I'm trying to make my nodejs app a linux service. I found the link below on the stackexchange and created a script under the /etc/init.d folder.
How can I make a script in /etc/init.d start at boot?
#!/bin/bash
# chkconfig: 2345 20 80
# description: Description comes here....
# Source function library.
. /etc/init.d/functions
start() {
# code to start app comes here
# example: daemon program_name &
/usr/bin/node /home/myapp/index.js
}
stop() {
# code to stop app comes here
# example: killproc program_name
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
# code to check status of app comes here
# example: status program_name
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
esac
I'm getting this error when I try to run the script.
$ service myapp start
/etc/init.d/myapp: line 17: syntax error near unexpected token `}'
/etc/init.d/myapp: line 17: `}'
I can successfully run the nodejs app manually. Something is wrong with my service. I cannot use systemctl so please do not recommend it.
I want to make this nodejs app a linux service that can be controlled like httpd,ftpd.