制作系统自启动脚本

#!/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
阅读更多
文章标签: linux shell
个人分类: LINUX shell
上一篇Docker 常用命令
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭