1

生成pm2开机启动脚本

使用pm2 save和pm2 startup生成启动脚本/etc/init.d/pm2-init.sh

pm2 start /opt/yliyun/work/node/pm2.json
pm2 save
pm2 startup
pm2 stop all
pm2 kill

新建服务启动脚本

node_service内容如下

#!/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

ymyang
66 声望1 粉丝