关闭

制作系统自启动脚本

标签: linuxshell
103人阅读 评论(0) 收藏 举报
分类:
#!/bin/bash

###################
#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
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:3304次
    • 积分:143
    • 等级:
    • 排名:千里之外
    • 原创:11篇
    • 转载:2篇
    • 译文:0篇
    • 评论:0条