Well there are two options
1) easy way Cron
create an entry in your crobtab ( usually crontab -e will open the editor for you)
<crontab -e> ------------------ editor
@reboot $DEBUG=myapp npm start
better practice would be create a script say under /usr/src/scripts ( chmod it to 755 or similar ) and call the script @reboot. such as
<crontab -e> ------------------ editor
@reboot /usr/src/script/myscript.sh >> /var/log/myscript.log
Like that you actually have your console outputs saved in a log file as well.
2) The more complex one is create a daemon script ( varies slightly across distributions.
#!/bin/sh
#
# /etc/init.d/mysystem
# Subsystem file for "MySystem" server
#
# chkconfig: 2345 95 05
# description: MySystem server daemon
#
# processname: MySystem
# config: /etc/MySystem/mySystem.conf
# config: /etc/sysconfig/mySystem
# pidfile: /var/run/MySystem.pid
# source function library
. /etc/rc.d/init.d/functions
# pull in sysconfig settings
[ -f /etc/sysconfig/mySystem ] && . /etc/sysconfig/mySystem
RETVAL=0
prog="MySystem"
.
.
.
start() {
echo -n $"Starting $prog:"
.
.
.
RETVAL=$?
[ "$RETVAL" = 0 ] && touch /var/lock/subsys/$prog
echo
}
stop() {
echo -n $"Stopping $prog:"
.
.
.
killproc $prog -TERM
RETVAL=$?
[ "$RETVAL" = 0 ] && rm -f /var/lock/subsys/$prog
echo
}
reload() {
echo -n $"Reloading $prog:"
killproc $prog -HUP
RETVAL=$?
echo
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
reload)
reload
;;
condrestart)
if [ -f /var/lock/subsys/$prog ] ; then
stop
# avoid race
sleep 3
start
fi
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|condrestart|status}"
RETVAL=1
esac
exit $RETVAL |
I use both methods depending on the mode of operation and the level of control I want to give users on the box.
1st is adequate second is proper.
david.