Last active
December 31, 2015 12:09
-
-
Save you21979/7984236 to your computer and use it in GitHub Desktop.
nodejsのPM2使ったサービス登録草案
調査終わったのでQIITAに書いた
http://qiita.com/you21979@github/items/593db14d2468b4bada0e
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/etc/init.dに置く | |
DIRを適切に書き換える | |
chkconfig nodead on | |
service nodead start | |
として起動する | |
# どうやらpm2に自動構築コマンドがあるみたいだけどうまくいかない | |
pm2 startup | |
{ [Error: Command failed: /bin/sh: update-rc.d: コマンドが見つかりません | |
] killed: false, code: 127, signal: null } | |
どうやらdebian,ubuntu系だけのようだ | |
しかし↓みると対応してるってあるけどなぁ | |
It uses System V init script compatible with Ubuntu and CentOS | |
だいぶ前にissueに上がってたようだ | |
https://github.com/Unitech/pm2/issues/57 | |
↓centos6の場合以下のコマンドで/etc/init.d/pm2-init.sh にテンプレートが出力される | |
sudo env PATH=$PATH:/usr/bin pm2 startup centos | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# chkconfig: - 98 02 | |
# description: pm2 | |
. /etc/rc.d/init.d/functions | |
export HOME=/tmp | |
PM2=/usr/bin/pm2 | |
DIR=/tmp | |
SCRIPT=${DIR}/processor.json | |
start() { | |
$PM2 start $SCRIPT | |
return $RETVAL | |
} | |
stop() { | |
$PM2 delete all | |
return $RETVAL | |
} | |
reload() { | |
$PM2 reload all | |
return $RETVAL | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart) | |
stop | |
start | |
;; | |
force-reload|reload) | |
reload | |
;; | |
*) | |
echo $"Usage: $prog {start|stop|restart|reload|help}" | |
RETVAL=2 | |
esac | |
exit $RETVAL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# chkconfig: 2345 98 02 | |
# | |
# description: PM2 next gen process manager for Node.js | |
# processname: pm2 | |
# | |
### BEGIN INIT INFO | |
# Provides: pm2 | |
# Required-Start: | |
# Required-Stop: | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: PM2 init script | |
# Description: PM2 is the next gen process manager for Node.js | |
### END INIT INFO | |
NAME=pm2 | |
PM2=/usr/lib/node_modules/pm2/bin/pm2 | |
NODE=/usr/bin/node | |
USER=root | |
export HOME="/root" | |
super() { | |
sudo -u $USER $* | |
} | |
start() { | |
echo "Starting $NAME" | |
super $NODE $PM2 resurrect | |
} | |
stop() { | |
super $NODE $PM2 dump | |
super $NODE $PM2 delete all | |
super $NODE $PM2 kill | |
} | |
restart() { | |
echo "Restarting $NAME" | |
stop | |
start | |
} | |
status() { | |
echo "Status for $NAME:" | |
$NODE $PM2 list | |
RETVAL=$? | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
status) | |
status | |
;; | |
restart) | |
restart | |
;; | |
*) | |
echo "Usage: {start|stop|status|restart}" | |
exit 1 | |
;; | |
esac | |
exit $RETVAL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{ | |
"name" : "app", | |
"script" : "/tmp/app.js", | |
"exec_mode" : "cluster_mode", | |
"instance" : "max", | |
"port" : 8080 | |
}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment