Matthias
Matthias

Reputation: 158

NodeJS forever does not work on startup

I'm working on a Rest Service working with NodeJS(iojs) on an old Raspberry Pi 1 running on Arch Linux. Everything works fine but its not starting on Reboot.

What I tried: Crontab without user:

crontab -e
@reboot /usr/local/iojs/bin/forever start /x/y/server.js

and with user:

crontab -u x -e
@reboot /usr/bin/sudo -u x -H /usr/local/iojs/bin/forever start /x/y/server.js

Both versions work manually executed. I also tried to do it with systemctrl:

/etc/systemd/system/rest_api.service
[Unit]
Description=Rest Api

[Service]
ExecStart=/x/y/rest_api/start_service.sh
Restart=always

[Install]
WantedBy=multi-user.target

This should execute start_service.sh:

#!/bin/sh
forever start /usr/local/rest_api/server.js
exit

Starting it throws an error

systemctl start rest_api
Error getting authority: Error initializing authority: Error calling StartServiceByName for org.freedesktop.PolicyKit1: Timeout was reached (g-io-error-quark, 24)
Failed to start rest_api.service: Connection timed out

I'm a beginner in some of those topics, therefore I'm struggling to find the mistake. Actually I think this should be simple.

Thank you, Matthias

Upvotes: 3

Views: 3448

Answers (2)

Omar Aflak
Omar Aflak

Reputation: 2962

If some people are still interested, this works perfectly:

1) npm install forever -g && npm install forever-service -g

2) rename your js script to app.js, go to its location with cd and type:

forever-service install myService

3) add the following line in /etc/rc.local :

sudo service myService start

I hope it will help!

Upvotes: 2

colinwurtz
colinwurtz

Reputation: 723

I was having this same problem. Got it working with the way you have it in scenario #1 above.

sudo crontab -e
#added this to the bottom
@reboot /usr/bin/sudo -u pi -H /usr/local/bin/forever start /home/pi/server.js

I thought it didn't work at first, but after rebooting the pi I gave it a solid 5 minutes before running:

forever list

And it showed up:

info:    Forever processes running
data:        uid  command             script                                       forever pid  id logfile                    uptime
data:    [0] L8AA /usr/local/bin/node /home/pi/server.js 3086    3108    /home/pi/.forever/L8AA.log 0:0:12:21.877

Upvotes: 0

Related Questions