Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 277
Matthias Avatar asked Feb 01 '26 07:02

Matthias


1 Answers

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!

like image 144
Omar Aflak Avatar answered Feb 03 '26 01:02

Omar Aflak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!