linux-系统自启动脚本

#!/bin/bash
# processname: processname
# description: tomcat is a j2se server
# chkconfig: 2345 86 16
# description: Start up the Tomcat servlet engine.

###################
#Set Env variables#
###################
USER=deploy
PIDFILE=/tmp/demo.pid
APPDIR=/var/www/demo-warehouse.weboapps.com/server/
NODEENV=staging
DEAMON=/usr/bin/node
DEAMON_OPT=/var/www/demo-warehouse.weboapps.com/server/server.js

function start {
    start-stop-daemon --start --oknodo --background --user $USER --chuid $USER -m -p $PIDFILE --chdir $APPDIR --exec /usr/bin/env NODE_ENV="`echo $NODEENV`" $DEAMON -- $DEAMON_OPT
           }

function stop {
               start-stop-daemon --stop --oknodo --user $USER --chuid $USER -p $PIDFILE --chdir $APPDIR --exec $DEAMON -- $DEAMON_OPT
           }

case $1 in
start)
    if [ -f $DEAMON_OPT ]; then
        echo "starting Node service"
        start
        echo -e  "Started [OK] \nNode service started with pid : `cat $PIDFILE`"
    else
        echo "Node service start failed"
        echo "status returned $?"
    fi
  ;;
stop)
        if [ -f $PIDFILE ]; then
                echo "shutting down Node service"
        stop
                echo "Node service stopped [OK]"
        else
                echo "Node service shutdown failed"
                echo "status returned $?"
        fi

  ;;
restart)
    stop
    start
  ;;
*)
        echo "Use (start|stop|restart)";
  ;;
esac

你可能感兴趣的:(linux-系统自启动脚本)