juggernaut (node.js アプリ) をデーモン化するために upstart スクリプトを作成しました。upstart スクリプトは次のとおりです。
description "juggernaut server"
author "panojsee"
start on startup
stop on shutdown
script
# We found $HOME is needed. Without it, we ran into problems
#export HOME="/home/ubuntu/src/juggernaut"
chdir /home/ubuntu/src/juggernaut
exec sudo /usr/bin/node server.js 2>&1 >> /var/log/node.log
end script
ご覧のとおり、ノードを sudo で実行したい (Flash ソケットを使用できるようにするため)。私のmonitスクリプトは次のとおりです。
ログファイル /var/log/monit.log を設定
check host juggernaut with address 127.0.0.1
start program = "/sbin/start juggernaut"
stop program = "/sbin/stop juggernaut"
if failed port 8080 protocol HTTP
request /
with timeout 10 seconds
then restart
Monit では、start program = " sudo /sbin/start juggernaut" を使用できません。juggernaut (ノード) を強制終了すると、monit はそれを再起動しようとしますが、次のメッセージが表示されて終了します。
[UTC Feb 3 22:48:25] error : 'nodejs' failed, cannot open a connection to INET[127.0.0.1:8080] via TCP
[UTC Feb 3 22:48:25] info : 'nodejs' trying to restart
[UTC Feb 3 22:48:25] info : 'nodejs' stop: sudo
[UTC Feb 3 22:48:25] error : Error: Could not execute sudo
[UTC Feb 3 22:48:25] info : 'nodejs' start: sudo
どうすればmonitにsudoコマンドを実行するように指示できますか?