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.

1 Answer 1

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
> }
$ 
1
  • The "official dummy command" is : Aug 11, 2017 at 1:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .