Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
Any option as long as it solves your problems. I use forever to daemonize on FreeBSD ( here's the article ). On Linux I use PM2 .
The most correct is a daemon (service), that is, it satisfies the 7 rules (close descriptors, go to the root directory, create a PID file, unhook from the parent's SID, go into the background, and so on)
Write an init script with LSB tags.
Wrote this script:
#!/bin/bash
### BEGIN INIT INFO
# Provides: myscript
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 1 0 6
# Short-Description: simple description.
### END INIT INFO
SMS_NAME=sms_app
CUR_NAME=currency_app
NODE_ENVIROMENT=production
SMS_FORSTOP=/home/scorpio/web_server/sms/bin/www
CUR_FORSTOP=/home/scorpio/web_server/EXPRESS/bin/www
smslogfile=/var/log/$SMS_NAME.log
curlogfile=/var/log/$CUR_NAME.log
forever=forever
start() {
export NODE_ENV=$NODE_ENVIROMENT
# echo "Starting $SMS_NAME app : "
touch $smslogfile
$forever start -a -l $smslogfile $SMS_FORSTOP
echo "Starting $CUR_NAME app : "
touch $curlogfile
$forever start -a -l $curlogfile $CUR_FORSTOP
RETVAL=$?
}
restart() {
echo -n "Restarting all : "
$forever restart $SMS_FORSTOP
$forever restart $CUR_FORSTOP
RETVAL=$?
}
status() {
echo "Status for all:"
$forever list
RETVAL=$?
}
stop() {
echo -n "Shutting down all : "
$forever stop $SMS_FORSTOP
$forever stop $CUR_FORSTOP
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
restart
;;
*)
echo "Usage: {start|stop|status|restart}"
exit 1
;;
esac
exit $RETVAL
update-rc.d myscript defaults
insserv myscript
service my script status
service myscript stop
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question