1.安装nodejs和forever    npm install forever -g

2.制作自己nodejs的自启动文件,在此为express框架,放在/etc/init.d/***

确定网站所在文件夹(/root/ImageServer),以及执行文件(bin/www)

#!/bin/bash
#
# node Start up node server daemon
#
# chkconfig: 345 85 15
# description: Forever for Node.js
#
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
LOG=/work/server/hosts_log
PID=/work/server/forever.pid

function start_app {
cd /root/ImageServer;
forever start "bin/www" -l $LOG/forever.log -o $LOG/forever_out.log -e $LOG/forever_err.log --pidFile $PID
}
function stop_app {
cd /root/ImageServer;
forever stop "bin/www"
}

case $1 in
start)
start_app ;;
stop)
stop_app ;;
restart)
stop_app
start_app
;;
*)
echo "usage: clearstonecc {start|stop}" ;;
esac
exit 0

3.确认文件属性  sudo chmod 755 /etc/init.d/***

4.启动服务

sudo chkconfig -add ***

chkconfig *** on

5.控制服务

service *** start

service *** stop

service *** restart

相关文章:

  • 2021-12-05
  • 2022-03-06
  • 2021-06-25
  • 2021-04-01
  • 2021-11-19
  • 2021-07-21
  • 2021-08-29
  • 2022-12-23
猜你喜欢
  • 2021-11-26
  • 2021-04-26
  • 2021-09-09
  • 2022-12-23
  • 2021-12-13
  • 2021-12-02
  • 2022-12-23
相关资源
相似解决方案