Skip to content

Commit

Permalink
ease demo with supervisor
Browse files Browse the repository at this point in the history
  • Loading branch information
kalmyk committed Oct 2, 2021
1 parent ed8ed13 commit 753acab
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
node_modules
npm-debug.log
*.log
coverage/*
.nyc_output
.idea/
**/*.iml
dbfiles/*
supervisor/*.db
5 changes: 4 additions & 1 deletion allot/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
const conf_wamp_port = process.env.WAMP_PORT
|| console.log('WAMP_PORT must be defined') || process.exit(1)

const conf_mqtt_port = process.env.MQTT_PORT
|| console.log('MQTT_PORT must be defined') || process.exit(1)

const Router = require('../lib/router')
const { BaseRealm } = require('../lib/realm')
const WampGate = require('../lib/wamp/gate')
Expand All @@ -16,6 +19,6 @@ const binder = new NetBinder(router)
router.createRealm = () => new BaseRealm(router, new NetEngine(binder))

new WampServer(new WampGate(router), { port: conf_wamp_port })
new MqttServer(new MqttGate(router), { port: 1883 })
new MqttServer(new MqttGate(router), { port: conf_mqtt_port })

console.log('Listening WAMP port:', conf_wamp_port)
12 changes: 6 additions & 6 deletions allot/ndb.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ async function main () {
const history = new History(db)
await history.createTables()

mkSync('ws:https://127.0.0.1:9011/wamp', 1)
mkSync('ws:https://127.0.0.1:9012/wamp', 2)
mkSync('ws:https://127.0.0.1:9013/wamp', 3)
mkSync('ws:https://127.0.0.1:9021/wamp', 1)
mkSync('ws:https://127.0.0.1:9022/wamp', 2)
mkSync('ws:https://127.0.0.1:9023/wamp', 3)

mkGate('ws:https://127.0.0.1:9021/wamp', 1, history)
// mkGate('ws:https://127.0.0.1:9022/wamp', 2, history)
// mkGate('ws:https://127.0.0.1:9023/wamp', 3, history)
mkGate('ws:https://127.0.0.1:9031/wamp', 1, history)
mkGate('ws:https://127.0.0.1:9032/wamp', 2, history)
mkGate('ws:https://127.0.0.1:9033/wamp', 3, history)
}

main().then(() => {
Expand Down
19 changes: 19 additions & 0 deletions supervisor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# demo easy start

## resource-lock.supervisord.ini
three clients that lock resource for the 5 second each, so the next able to lock the resource after the previous release it

- to start:
```shell
$ supervisord -c ./resource-lock.supervisord.ini
```

## allot.supervisord.ini
leaderless queue work

- to start:
```shell
$ supervisord -c ./allot.supervisord.ini


```
86 changes: 86 additions & 0 deletions supervisor/allot.supervisord.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
[supervisord]
logfile=./supervisord.log ; (main log file;default $CWD/supervisord.log)
loglevel=info ; (log level;default info; others: debug,warn,trace)
pidfile=./supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=true ; (start in foreground if true;default false)

[program:sync-1]
command=./prefix-log.sh node ../allot/sync.js
environment=WAMP_PORT=9021
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
priority=1

[program:sync-2]
command=./prefix-log.sh node ../allot/sync.js
environment=WAMP_PORT=9022
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
priority=1

[program:sync-3]
command=./prefix-log.sh node ../allot/sync.js
environment=WAMP_PORT=9023
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
priority=1

[program:entry-1]
command=./prefix-log.sh node ../allot/entry.js
environment=WAMP_PORT=9031,MQTT_PORT=1881
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
priority=2

[program:entry-2]
command=./prefix-log.sh node ../allot/entry.js
environment=WAMP_PORT=9032,MQTT_PORT=1882
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
priority=2

[program:entry-3]
command=./prefix-log.sh node ../allot/entry.js
environment=WAMP_PORT=9033,MQTT_PORT=1883
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
priority=2

[program:ndb-1]
command=./prefix-log.sh node ../allot/ndb.js
environment=DB_FILE=./x1.db
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
priority=3

[program:ndb-2]
command=./prefix-log.sh node ../allot/ndb.js
environment=DB_FILE=./x2.db
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
priority=3

[program:ndb-3]
command=./prefix-log.sh node ../allot/ndb.js
environment=DB_FILE=./x3.db
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
priority=3
16 changes: 16 additions & 0 deletions supervisor/prefix-log.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
# setup fd-3 to point to the original stdout
exec 3>&1
# setup fd-4 to point to the original stderr
exec 4>&2

# get the prefix from SUPERVISOR_PROCESS_NAME environement variable
printf -v PREFIX "%-10.10s" ${SUPERVISOR_PROCESS_NAME}

# reassign stdout and stderr to a preprocessed and redirected to the original stdout/stderr (3 and 4) we have create eralier
exec 1> >( perl -ne '$| = 1; print "'"${PREFIX}"' | $_"' >&3)
exec 2> >( perl -ne '$| = 1; print "'"${PREFIX}"' | $_"' >&4)

# from here on everthing that outputs to stdout/stderr will be go through the perl script

exec "$@"
37 changes: 37 additions & 0 deletions supervisor/resource-lock.supervisord.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[supervisord]
logfile=./supervisord.log ; (main log file;default $CWD/supervisord.log)
loglevel=info ; (log level;default info; others: debug,warn,trace)
pidfile=./supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=true ; (start in foreground if true;default false)

[program:router]
command=./prefix-log.sh node ../bin/basic.js
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
priority=1

[program:resource1]
command=./prefix-log.sh node ../democli/resource-lock.js
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
priority=2

[program:resource2]
command=./prefix-log.sh node ../democli/resource-lock.js
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
priority=2

[program:resource3]
command=./prefix-log.sh node ../democli/resource-lock.js
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
priority=2

0 comments on commit 753acab

Please sign in to comment.