1

I'm trying to start a nodeJS Server on Raspbian on startup.

Everything works fine with this script:

#!/bin/sh
#/etc/init.d/myService
### BEGIN INIT INFO
# Provides:          myService
# Required-Start:    $all
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:
# Short-Description: your description here
### END INIT INFO
export PATH=$PATH:/usr/local/bin
export NODE_PATH=$NODE_PATH:/usr/local/lib/node_modules

case "$1" in
start)
exec forever --sourceDir=/root/CamSlider -l forever.log -o out.log -e err.log -p /root/CamSlider server.js  #scriptarguments
;;
stop)
exec forever stop --sourceDir=/root/CamSliderr server.js
;;
*)
echo "Usage: /etc/init.d/myService {start|stop}"
exit 1
;;
esac
exit 0

This works fine. But somehow I get strange errors if my server gets started like this as oposed to a manual start within the shell as root with simply node server.js.

What could cause these problems? Do I need to start myService as root or do I need to run forever as root?

Thanks for any advice!

  • 1
    Raspbian is not Ubuntu. And Raspian uses systemd instead of sysvinit. – user535733 Aug 22 at 16:15
1

Since version 8 (Jessie) Debian has switched to the new init system systemd. All Debian flavors, including Ubuntu and Raspbian, followed this. So old style init system SysV is deprecated and no more available. Its init scripts in /etc/init.d/ are only emulated by systemd for downstream Compatibility with SysV. But the last sentence in the document notes:

Note that there are some areas where systemd currently provides a certain amount of compatibility where we expect this compatibility to be removed eventually.

It seems this becomes more and more true. I suggest that you don't take more effort into fixing an emulated deprecated init system SysV. You should use a systemd Unit file to make your service.

  • Exactly what I did and its now working better! Thanks for your advice! – FabZbi Aug 23 at 20:45

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.