1

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.

2

Your stop() function has no content. Add some content, even if it's just running /bin/true (or maybe killproc /usr/bin/node ?) and it'll happily get past this error.

Example:

$ a() {
> echo foo
> }
$ b() {
> # comment
> }
-bash: syntax error near unexpected token `}'
$ b() {
> /bin/true
> }
$ 
  • The "official dummy command" is : – Hauke Laging Aug 11 '17 at 1:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.