使用pm2 save和pm2 startup生成啓動腳本/etc/init.d/pm2-init.shnode
pm2 start /opt/yliyun/work/node/pm2.json pm2 save pm2 startup pm2 stop all pm2 kill
node_service內容以下json
#!/bin/sh # chkconfig: 2345 64 36 # description: yliyun node start scripts. YLIYUN_HOME=/opt/yliyun #EXEC=$YLIYUN_HOME/node/bin/pm2 EXEC=/etc/init.d/pm2-init.sh export PATH=$YLIYUN_HOME/common/bin:$PATH case "$1" in start) echo "Starting node..." $EXEC start $YLIYUN_HOME/work/node/pm2.json ;; stop) echo "Stoping node..." $EXEC stop all $EXEC kill ;; *) echo "Please use start or stop as first agrument" ;; esac
cp -f node_service/etc/init.d/node chmod +x /etc/init.d/node chkconfig --add node chkconfig nodeon