Executando várias instâncias com upstart

3

Eu tenho um servidor que escrevi que precisa ser executado em várias portas.

Então eu escrevi dois scripts do Upstart como os documentos iniciais sugerem. link

Tarefa para gerar instâncias:

# gatling-broadcast.conf
description "Start multiple gatling-broadcast servers"
console output

start on runlevel [2345]

task

script
    for i in 'seq 21001 21004'; do
        start gatling-broadcast-worker PORT=$i
    done
end script

Script de instância:

# gatling-broadcast-worker.conf
description "Gatling-broadcast server."
instance $PORT  
env ROOT="/home/ctargett/Projects/msgqueue"
exec $ROOT/env/bin/pypy $ROOT/main.py --mode=broadcast --port=$PORT --log_file_prefix=/tmp/gatling-broadcast-$PORT.log

Posso executar várias versões do trabalho gatling-broadcast-worker :

$ initctl --session start gatling-broadcast-worker PORT=21001
gatling-broadcast-worker (21001) start/running, process 20956
$ initctl --session start gatling-broadcast-worker PORT=21002
gatling-broadcast-worker (21002) start/running, process 20963
$ initctl --session list
gatling-broadcast stop/waiting
gatling-monitor stop/waiting
gatling-broadcast-worker (21002) start/running, process 20963
gatling-broadcast-worker (21001) start/running, process 20956

No entanto, quando tento iniciar o trabalho gatling-broadcast , recebo um erro:

$ initctl --session start gatling-broadcast
initctl: Job failed to start

E nada de ajuda na saída de init diferente de init: gatling-broadcast main process (21007) terminated with status 1 :

Loading configuration from /home/ctargett/Projects/msgqueue/upstart
job_class_unregister: Unregistered job /com/ubuntu/Upstart/jobs/gatling_2dbroadcast
conf_file_destroy: Destroyed unused job gatling-broadcast
conf_reload_path: Loading gatling-broadcast from /home/ctargett/Projects/msgqueue/upstart/gatling-broadcast.conf
parse_job: Creating new JobClass gatling-broadcast
job_class_register: Registered job /com/ubuntu/Upstart/jobs/gatling_2dbroadcast
job_class_unregister: Unregistered job /com/ubuntu/Upstart/jobs/gatling_2dbroadcast_2dworker
conf_file_destroy: Destroyed unused job gatling-broadcast-worker
conf_reload_path: Loading gatling-broadcast-worker from /home/ctargett/Projects/msgqueue/upstart/gatling-broadcast-worker.conf
parse_job: Creating new JobClass gatling-broadcast-worker
job_class_register: Registered job /com/ubuntu/Upstart/jobs/gatling_2dbroadcast_2dworker
job_class_unregister: Unregistered job /com/ubuntu/Upstart/jobs/gatling_2dmonitor
conf_file_destroy: Destroyed unused job gatling-monitor
conf_reload_path: Loading gatling-monitor from /home/ctargett/Projects/msgqueue/upstart/gatling-monitor.conf
parse_job: Creating new JobClass gatling-monitor
job_class_register: Registered job /com/ubuntu/Upstart/jobs/gatling_2dmonitor

job_register: Registered instance /com/ubuntu/Upstart/jobs/gatling_2dbroadcast/_
gatling-broadcast goal changed from stop to start
gatling-broadcast state changed from waiting to starting
event_new: Pending starting event
Handling starting event
event_finished: Finished starting event
gatling-broadcast state changed from starting to pre-start
gatling-broadcast state changed from pre-start to spawned
gatling-broadcast main process (21007)
gatling-broadcast state changed from spawned to post-start
gatling-broadcast state changed from post-start to running
event_new: Pending started event
Handling started event
event_finished: Finished started event
init: gatling-broadcast main process (21007) terminated with status 1
gatling-broadcast goal changed from start to stop
gatling-broadcast state changed from running to stopping
event_new: Pending stopping event
Handling stopping event
event_finished: Finished stopping event
gatling-broadcast state changed from stopping to killed
gatling-broadcast state changed from killed to post-stop
gatling-broadcast state changed from post-stop to waiting
event_new: Pending stopped event
job_change_state: Destroyed inactive instance gatling-broadcast
Handling stopped event
event_finished: Finished stopped event
    
por Chris Targett 14.05.2012 / 16:37

1 resposta

1

Eu acho que o problema é que gatling-broadcast está falhando ao iniciar uma ou mais instâncias, provavelmente porque já estão comando simples falhar, o script sairá imediatamente. Veja:

link

Se você estiver executando o Ubuntu Precise, dê uma olhada em /var/log/upstart/gatling-broadcast.log . Você pode adicionar " set -x " ao topo da sub-rotina do script para ver exatamente onde ele está falhando.

A correção é fácil:

script
    for i in 'seq 21001 21004'; do
        start gatling-broadcast-worker PORT=$i || true
    done
end script

No entanto, uma solução melhor seria verificar o status da instância específica da tarefa gatling-broadcast-worker e, se ela não estiver em execução, tentar iniciá-la. E se isso falhar, tome alguma ação apropriada.

    
por 16.05.2012 / 18:16