Skripty které pollují frontu a spouštějí joby nespouštíme cronem ale máme nahozený pevně daný počet workerů. O udržování workerů při životě se stará Upstart http://upstart.ubuntu.com/getting-started.html
Pod rootem vytvořit soubor /etc/init/nazev-jobu.conf
s obsahem:
instance $N
respawn
exec su -s /bin/sh -c 'exec "$0" "$@"' deploy -- php /cesta/k/memu-skriptu
Jakmile je tenhle soubor je možné job spustit pomocí start nazev-jobu N=1
a stop nazev-jobu N=1
vypne. Parametr N
umožnuje mít stejný job spuštěný několikrát.
Někdy se hodí mít job parametrizovaný zvenčí. V SAPI se např předává fronta která se má pollovat. Konfigurace potom vypadá takhle:
instance ${QUEUE}-${N}
respawn
exec su -s /bin/sh -c 'exec "$0" "$@"' deploy -- /www/connection/current/cli.sh storage:queue:receive $QUEUE
Takovýhle job se pak spustí start nazev-jobu N=1 QUEUE=main
a vypne stop nazev-jobu N=1 QUEUE=main
.
## Výpis procesů
initctl list
Výstup:
[root@kbc-api-worker ec2-user]# initctl list
rc stop/waiting
update-motd stop/waiting
plymouth-shutdown stop/waiting
control-alt-delete stop/waiting
connection.queue-receive (main_fast-3) start/running, process 30179
connection.queue-receive (main_fast-4) start/running, process 30563
connection.queue-receive (main_fast-5) start/running, process 29346
connection.queue-receive (main_fast-6) start/running, process 30556
connection.queue-receive (main_fast-7) start/running, process 29214
connection.queue-receive (main_fast-8) start/running, process 29406
connection.queue-receive (eventsElastic-4) start/running, process 30446
connection.queue-receive (eventsElastic-1) start/running, process 29206
connection.queue-receive (eventsElastic-2) start/running, process 29525
connection.queue-receive (eventsElastic-3) start/running, process 30510
connection.queue-receive (main_fast-1) start/running, process 29595
connection.queue-receive (main_fast-2) start/running, process 29333
rcS-emergency stop/waiting
kexec-disable stop/waiting
quit-plymouth stop/waiting
rcS stop/waiting
prefdm stop/waiting
init-system-dbus stop/waiting
splash-manager stop/waiting
start-ttys stop/waiting
rcS-sulogin stop/waiting
serial (hvc0) start/running, process 1439
start jmeno-jobu N=CISLO_JOBU
stop jmeno-jobu N=CISLO_JOBU
Killne právě běžící job. Pokud je job definovaný jako exec su -s /bin/sh -c 'exec "$0" "$@"'
tak zabije pouze obalující skript a samotný vnitřní skript nechá doběhnout.