I’m setting up a new server and trying now to get pm2 installed and working following this instructions https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-18-04
When trying sudo systemctl start pm2-userName
I get this error message: "Job for pm2-userName.service failed because the service did not take the steps required by its unit configuration."
Any help would be very much appreciated since I am stuck on this. Thanks!"
I have followed this steps until now:
- sudo npm install pm2@latest -g
//(installed fine!)
- pm2 start hello.js
//(working fine!)
- pm2 startup systemd
//(i get a sudo env PATH... to copyPaste)
- copyPasted sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u carles --hp /home/carles
//(and everything looks still fine and working (See STARTUP SCRIPT BELOW)
- sudo pm2 save
(worked)
- sudo systemctl start pm2-carles
(FAILED! as Job for pm2-carles.service failed because the service did not take the steps required by its unit configuration.)
- systemctl status pm2-carles.service
//(loaded but Active: failed (Result: protocol)
STARTUP SCRIPT/// ##########################
[PM2] Init System found: systemd
Platform systemd
Template
[Unit]
Description=PM2 process manager
Documentation=https://pm2.keymetrics.io/
After=network.target
[Service]
Type=forking
User=carles
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
Environment=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/bin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
Environment=PM2_HOME=/home/carles/.pm2
PIDFile=/home/carles/.pm2/pm2.pid
Restart=on-failure
ExecStart=/usr/lib/node_modules/pm2/bin/pm2 resurrect
ExecReload=/usr/lib/node_modules/pm2/bin/pm2 reload all
ExecStop=/usr/lib/node_modules/pm2/bin/pm2 kill
[Install]
WantedBy=multi-user.target
Target path
/etc/systemd/system/pm2-carles.service
Command list
[ 'systemctl enable pm2-carles' ]
[PM2] Writing init configuration in /etc/systemd/system/pm2-carles.service
[PM2] Making script booting at startup...
[PM2] [-] Executing: systemctl enable pm2-carles...
[PM2] [v] Command successfully executed.
+---------------------------------------+
[PM2] Freeze a process list on reboot via:
$ pm2 save
[PM2] Remove init script via:
$ pm2 unstartup systemd
#
JOURNALCTL -XE ###############################################
Hint: You are currently not seeing messages from other users and the system.
Users in groups 'adm', 'systemd-journal' can see all messages.
Pass -q to turn off this notice.
Jul 09 09:36:19 future-card pm2[4752]: [PM2] Resurrecting
Jul 09 09:36:19 future-card pm2[4752]: [PM2] Restoring processes located in /home/carles/.pm2/dump.pm2
Jul 09 09:36:19 future-card pm2[4752]: ┌──────────┬────┬─────────┬──────┬──────┬────────┬─────────┬────────┬──
Jul 09 09:36:19 future-card pm2[4752]: │ App name │ id │ version │ mode │ pid │ status │ restart │ uptime │ c
Jul 09 09:36:19 future-card pm2[4752]: ├──────────┼────┼─────────┼──────┼──────┼────────┼─────────┼────────┼──
Jul 09 09:36:19 future-card pm2[4752]: │ hello │ 0 │ N/A │ fork │ 3268 │ online │ 0 │ 33m │ 0
Jul 09 09:36:19 future-card pm2[4752]: └──────────┴────┴─────────┴──────┴──────┴────────┴─────────┴────────┴──
Jul 09 09:36:19 future-card pm2[4752]: Use `pm2 show <id|name>` to get more details about an app
Jul 09 09:36:20 future-card pm2[4783]: [PM2] Resurrecting
Jul 09 09:36:20 future-card pm2[4783]: [PM2] Restoring processes located in /home/carles/.pm2/dump.pm2
Jul 09 09:36:20 future-card pm2[4783]: ┌──────────┬────┬─────────┬──────┬──────┬────────┬─────────┬────────┬──
Jul 09 09:36:20 future-card pm2[4783]: │ App name │ id │ version │ mode │ pid │ status │ restart │ uptime │ c
Jul 09 09:36:20 future-card pm2[4783]: ├──────────┼────┼─────────┼──────┼──────┼────────┼─────────┼────────┼──
Jul 09 09:36:20 future-card pm2[4783]: │ hello │ 0 │ N/A │ fork │ 3268 │ online │ 0 │ 33m │ 0
Jul 09 09:36:20 future-card pm2[4783]: └──────────┴────┴─────────┴──────┴──────┴────────┴─────────┴────────┴──
Jul 09 09:36:20 future-card pm2[4783]: Use `pm2 show <id|name>` to get more details about an app
Jul 09 09:36:20 future-card pm2[4815]: [PM2] Resurrecting
Jul 09 09:36:20 future-card pm2[4815]: [PM2] Restoring processes located in /home/carles/.pm2/dump.pm2
Jul 09 09:36:20 future-card pm2[4815]: ┌──────────┬────┬─────────┬──────┬──────┬────────┬─────────┬────────┬──
Jul 09 09:36:20 future-card pm2[4815]: │ App name │ id │ version │ mode │ pid │ status │ restart │ uptime │ c
Jul 09 09:36:20 future-card pm2[4815]: ├──────────┼────┼─────────┼──────┼──────┼────────┼─────────┼────────┼──
Jul 09 09:36:20 future-card pm2[4815]: │ hello │ 0 │ N/A │ fork │ 3268 │ online │ 0 │ 33m │ 0
Jul 09 09:36:20 future-card pm2[4815]: └──────────┴────┴─────────┴──────┴──────┴────────┴─────────┴────────┴──
Jul 09 09:36:20 future-card pm2[4815]: Use `pm2 show <id|name>` to get more details about an app
Jul 09 09:36:21 future-card pm2[4846]: [PM2] Resurrecting
Jul 09 09:36:21 future-card pm2[4846]: [PM2] Restoring processes located in /home/carles/.pm2/dump.pm2
Jul 09 09:36:21 future-card pm2[4846]: ┌──────────┬────┬─────────┬──────┬──────┬────────┬─────────┬────────┬──
Jul 09 09:36:21 future-card pm2[4846]: │ App name │ id │ version │ mode │ pid │ status │ restart │ uptime │ c
Jul 09 09:36:21 future-card pm2[4846]: ├──────────┼────┼─────────┼──────┼──────┼────────┼─────────┼────────┼──
Jul 09 09:36:21 future-card pm2[4846]: │ hello │ 0 │ N/A │ fork │ 3268 │ online │ 0 │ 33m │ 0
Jul 09 09:36:21 future-card pm2[4846]: └──────────┴────┴─────────┴──────┴──────┴────────┴─────────┴────────┴──
Jul 09 09:36:21 future-card pm2[4846]: Use `pm2 show <id|name>` to get more details about an app
Jul 09 09:50:20 future-card pm2[5168]: [PM2] Resurrecting
Jul 09 09:50:20 future-card pm2[5168]: [PM2] Restoring processes located in /home/carles/.pm2/dump.pm2
Jul 09 09:50:20 future-card pm2[5168]: ┌──────────┬────┬─────────┬──────┬──────┬────────┬─────────┬────────┬──
Jul 09 09:50:20 future-card pm2[5168]: │ App name │ id │ version │ mode │ pid │ status │ restart │ uptime │ c
Jul 09 09:50:20 future-card pm2[5168]: ├──────────┼────┼─────────┼──────┼──────┼────────┼─────────┼────────┼──
Jul 09 09:50:20 future-card pm2[5168]: │ hello │ 0 │ N/A │ fork │ 3268 │ online │ 0 │ 47m │ 0
Jul 09 09:50:20 future-card pm2[5168]: └──────────┴────┴─────────┴──────┴──────┴────────┴─────────┴────────┴──
Jul 09 09:50:20 future-card pm2[5168]: Use `pm2 show <id|name>` to get more details about an app
Jul 09 09:50:20 future-card pm2[5200]: [PM2] Resurrecting
Jul 09 09:50:20 future-card pm2[5200]: [PM2] Restoring processes located in /home/carles/.pm2/dump.pm2
Jul 09 09:50:20 future-card pm2[5200]: ┌──────────┬────┬─────────┬──────┬──────┬────────┬─────────┬────────┬──
Jul 09 09:50:20 future-card pm2[5200]: │ App name │ id │ version │ mode │ pid │ status │ restart │ uptime │ c
Jul 09 09:50:20 future-card pm2[5200]: ├──────────┼────┼─────────┼──────┼──────┼────────┼─────────┼────────┼──
Jul 09 09:50:20 future-card pm2[5200]: │ hello │ 0 │ N/A │ fork │ 3268 │ online │ 0 │ 47m │ 0
Jul 09 09:50:20 future-card pm2[5200]: └──────────┴────┴─────────┴──────┴──────┴────────┴─────────┴────────┴──
Jul 09 09:50:20 future-card pm2[5200]: Use `pm2 show <id|name>` to get more details about an app
Jul 09 09:50:21 future-card pm2[5233]: [PM2] Resurrecting
Jul 09 09:50:21 future-card pm2[5233]: [PM2] Restoring processes located in /home/carles/.pm2/dump.pm2
Jul 09 09:50:21 future-card pm2[5233]: ┌──────────┬────┬─────────┬──────┬──────┬────────┬─────────┬────────┬──
Jul 09 09:50:21 future-card pm2[5233]: │ App name │ id │ version │ mode │ pid │ status │ restart │ uptime │ c
Jul 09 09:50:21 future-card pm2[5233]: ├──────────┼────┼─────────┼──────┼──────┼────────┼─────────┼────────┼──
Jul 09 09:50:21 future-card pm2[5233]: │ hello │ 0 │ N/A │ fork │ 3268 │ online │ 0 │ 47m │ 0
Jul 09 09:50:21 future-card pm2[5233]: └──────────┴────┴─────────┴──────┴──────┴────────┴─────────┴────────┴──
Jul 09 09:50:21 future-card pm2[5233]: Use `pm2 show <id|name>` to get more details about an app
Jul 09 09:50:22 future-card pm2[5265]: [PM2] Resurrecting
Jul 09 09:50:22 future-card pm2[5265]: [PM2] Restoring processes located in /home/carles/.pm2/dump.pm2
Jul 09 09:50:22 future-card pm2[5265]: ┌──────────┬────┬─────────┬──────┬──────┬────────┬─────────┬────────┬──
Jul 09 09:50:22 future-card pm2[5265]: │ App name │ id │ version │ mode │ pid │ status │ restart │ uptime │ c
Jul 09 09:50:22 future-card pm2[5265]: ├──────────┼────┼─────────┼──────┼──────┼────────┼─────────┼────────┼──
Jul 09 09:50:22 future-card pm2[5265]: │ hello │ 0 │ N/A │ fork │ 3268 │ online │ 0 │ 47m │ 0
Jul 09 09:50:22 future-card pm2[5265]: └──────────┴────┴─────────┴──────┴──────┴────────┴─────────┴────────┴──
Jul 09 09:50:22 future-card pm2[5265]: Use `pm2 show <id|name>` to get more details about an app
Jul 09 09:50:23 future-card pm2[5295]: [PM2] Resurrecting
Jul 09 09:50:23 future-card pm2[5295]: [PM2] Restoring processes located in /home/carles/.pm2/dump.pm2
Jul 09 09:50:23 future-card pm2[5295]: ┌──────────┬────┬─────────┬──────┬──────┬────────┬─────────┬────────┬──
Jul 09 09:50:23 future-card pm2[5295]: │ App name │ id │ version │ mode │ pid │ status │ restart │ uptime │ c
Jul 09 09:50:23 future-card pm2[5295]: ├──────────┼────┼─────────┼──────┼──────┼────────┼─────────┼────────┼──
Jul 09 09:50:23 future-card pm2[5295]: │ hello │ 0 │ N/A │ fork │ 3268 │ online │ 0 │ 47m │ 0
Jul 09 09:50:23 future-card pm2[5295]: └──────────┴────┴─────────┴──────┴──────┴────────┴─────────┴────────┴──
Jul 09 09:50:23 future-card pm2[5295]: Use `pm2 show <id|name>` to get more details about an app```
I expect sudo systemctl start pm2-carles to run and work, instead I am getting "pm2-carles.service - PM2 process manager
Loaded: loaded (/etc/systemd/system/pm2-carles.service; enabled; vendor preset: enabled)
Active: failed (Result: protocol) since Tue 2019-07-09 09:50:23 UTC; 1min 2s ago
Docs: https://pm2.keymetrics.io/
Process: 5295 ExecStart=/usr/lib/node_modules/pm2/bin/pm2 resurrect (code=exited, status=0/SUCCESS)"
Restart on file change To totally disable the watch feature, do: pm2 stop app --watch or toggle the watch option on application restart via pm2 restart app --watch .
In this article, we will show you how to deploy PM2 as a service to reliably manage your Node. js apps. For this guide, the test system uses a systemd service and system manager.
Rebooting the virtual server worked for me with:
sudo reboot
If that doesn't work, try:
ps aux | grep pm2 | grep -v grep | awk '{print $2}' | xargs kill -9
The above kills the pm2 service daemon after which you can restart it with root privileges. (This is if you are running from the directory /usr/bin/pm2).
Got the above from github pm2 thread
We need to kill the existing master process first and restart the pm2 master process with systemd. The following steps will fix your issue.
pm2 kill
to kill the master process if it launched already.pm2 startup systemd
.sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u USERNAME --hp /home/USERNAME
run sudo systemctl start pm2-USERNAME
, now you have a pm2 master process managed by systemd.
You can verify it with systemctl status pm2-USERNAME
.
run pm2 save
to save your app configuration to /home/USERNAME/.pm2
,
so systemd launched pm2 master process can resume it from after a server restart.
You can find more about this issue here at the github
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With