In centos 7 when I reboot the server, pm2 does not load the processes saved on shutdown.
The service name (pm2-init.sh) also collides with systemctl format. Can I suggest to rename the file in just pm2?
It's weird because it works if I power off the machine (unplug the power cable) but not if I run a correct reboot. Can anybody help me?
Maybe we missed something.
I'm not familiar with centos chkconfig, maybe someone could check the init file : https://github.com/Unitech/PM2/blob/master/lib/scripts/pm2-init-centos.sh#L5
thing is, centos 7 uses systemd instead. It used to work correctly on centos 6 which used chconfig to enable/disable services
Hi, i came across the same issue while using centos 7,
I am running this under a normal user (not root)
once i commented out the 'delete all' & 'dump' under stop in the initd script my apps kept coming back on reboot.
Hi @Azerothian ,
Thanks a lot for sharing your solution! This indeed fix the problem. I also have change the export PM2_HOME="/root/.pm2" to my normal user home folder.
@Azerothian worked on fedora =) yay!
me too!
In centos 7,when reboot the sever,the pm2 startup do not work,but when power off the server,and then restart the server,the pm2 startup work fine.
Use this with CentOS 7:
sudo pm2 startup systemd
@Azerothian
sudo pm2 startup systemd still not work
Feels to me like this needs more than a manual workaround. If we detect centos 7+ in the cli we should be able to do this correctly. Correct? Or there could be an optional version flag on the startup command.
I also have problem with the startup pm2 on CentOS 7. It seems that these problems disappear if the application is run under root:
# in project folder
sudo pm2 start index.js
and then:
sudo pm2 startup centos
If on CentOS 7 run pm2 list not under root, showing an empty table (only headers). So should it be?
I played with pm2, and found two working way for CentOS 7 (in your project folder index.js - main file):
# 1
sudo pm2 start index.js
sudo pm2 save
sudo pm2 startup centos
# 2
pm2 start index.js
pm2 save
pm2 startup centos
# and run the script generated in the previous code under sudo
NOT working next
pm2 start index.js
pm2 save
sudo pm2 startup centos
and NOT working next
pm2 start index.js
sudo pm2 startup centos
@KostyaTretyak Still not working here.
@meteormatt, but if in your project to do this:
sudo chown $USER: -R .
sudo chmod 755 index.js
Here is what worked for me. (to launch Kibana4 under the node user on a RHEL/CentOS 7 server.
As root
pm2 startup systemd /home/node/kibana4.yml -u node
pm2 save
Note about above: change the -u (user) node to what user you want the app to run as and the path to the startup file of the app.
Now you should be able to reboot and it will run the app as the node user on startup.
Hope this helps.
Mark
Thanks @Azerothian, works like a boss. Just comment out '$PM2 delete all' in /etc/init.d/pm2-init.sh
Thanks @Azerothian and I runned this command:
sudo su -c "env PATH=$PATH:/usr/bin pm2 startup centos -u centos --hp /home/centos"
Closing in favor of #2559
To try the new startup system:
$ npm install Unitech/pm2#development -g
$ pm2 update
$ pm2 startup # Then copy / paste the command displayed
$ pm2 unstartup
I am using
Centos 7
pm2 2.1.6
node v6.9.1
The following command worked for me. I am running pm2 as node user not root.
sudo pm2 startup systemd run as sudo, any user
pm2 save run as node user, make sure the app is running
update the user to node user in the service file.
cat /etc/systemd/system/pm2.service
Under [Service], u should see the following
[Service]
Type=forking
User=node
the whole pm2.service file for reference
cat /etc/systemd/system/pm2.service
[Unit]
Description=PM2 next gen process manager for Node.js
After=network.target remote-fs.target
[Service]
Type=forking
User=node
ExecStartPre=/usr/local/lib/node_modules/pm2/bin/pm2 kill
ExecStart=/usr/local/lib/node_modules/pm2/bin/pm2 resurrect
ExecReload=/usr/local/lib/node_modules/pm2/bin/pm2 reload all
ExecStop=/usr/local/lib/node_modules/pm2/bin/pm2 dump
ExecStop=/usr/local/lib/node_modules/pm2/bin/pm2 delete all
ExecStop=/usr/local/lib/node_modules/pm2/bin/pm2 kill
[Install]
WantedBy=multi-user.target
Reboot the server for test.
Check /var/log/messages to verify pm2 started correctly. You would see something like this after reboot.
Dec X 13:29:17 X.X.X.X pm2: [PM2] Spawning PM2 daemon with pm2_home=/home/node/.pm2
Dec X 13:29:17 X.X.X.X systemd: Started Apply the settings specified in cloud-config.
Dec X 13:29:17 X.X.X.X systemd: Starting Execute cloud user/final scripts...
Dec X 13:29:17 X.X.X.X pm2: [PM2] PM2 Successfully daemonized
Dec X 13:29:17 X.X.X.X pm2: [PM2] Resurrecting
Dec X 13:29:17 X.X.X.X pm2: [PM2] Restoring processes located in /home/node/.pm2/dump.pm2
P.S. I think pm2 doesn't work well in centos 7 if you are using chkconfig, atleast I couldn't get it working
Most helpful comment
Hi, i came across the same issue while using centos 7,
I am running this under a normal user (not root)
once i commented out the 'delete all' & 'dump' under stop in the initd script my apps kept coming back on reboot.