node.js startup script file

  • 2020-05-09 18:08:57
  • OfStack


#!/bin/bash
### BEGIN INIT INFO
# Provides:       xiyoulib
# Required-Start:   $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:   0 1 6
# Short-Description: Start daemon at boot time
# Description:     Enable service provided by daemon.
### END INIT INFO
# chkconfig: 345 88 08
# description: Forever for Node.js
 
DEAMON=/home/wwwroot/default/im/chat.js   # You need to fill in your own Node The startup script file for the project
LOG=/home/wwwroot/default/im/log/log  # Optionally, log file directory
PID=/home/wwwroot/default/im/log/pid  # Required content for recording forever The process of no.
 
export PATH=$PATH:/usr/local/bin  # I'm gonna specify here 1 Under the Node The executable program installation directory for mine is /usr/local/bin
export NODE_PATH=$NODE_PATH:/usr/local/lib/node_modules  # Here is the Node The path to the class library
 
# You don't need to change the following
 
node=node
forever=forever
 
case "$1" in
    start)
        $forever start -l $LOG --pidFile $PID -a $DEAMON
        ;;
    stop)
        $forever stop --pidFile $PID $DEAMON
        ;;
    stopall)
        $forever stopall --pidFile $PID
        ;;
    restartall)
        $forever restartall --pidFile $PID
        ;;
    reload|restart)
        $forever restart -l $LOG --pidFile $PID -a $DEAMON
        ;;
    list)
        $forever list
        ;;
    *)
        echo "Usage: /etc.init.d/node {start|stop|restart|reload|stopall|restartall|list}"
        exit 1
        ;;
esac


chmod 755 /etc/init.d/node
chkconfig /etc/init.d/node on


Related articles: