Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pm2-init.sh does not work on centos 7 #903

Closed
vitxd opened this issue Dec 24, 2014 · 20 comments
Closed

pm2-init.sh does not work on centos 7 #903

vitxd opened this issue Dec 24, 2014 · 20 comments

Comments

@vitxd
Copy link

vitxd commented Dec 24, 2014

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?

@vitxd
Copy link
Author

vitxd commented Jan 8, 2015

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?

@soyuka
Copy link
Collaborator

soyuka commented Jan 8, 2015

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

@vitxd
Copy link
Author

vitxd commented Jan 8, 2015

thing is, centos 7 uses systemd instead. It used to work correctly on centos 6 which used chconfig to enable/disable services

@Azerothian
Copy link

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.

@gregwym
Copy link

gregwym commented Mar 31, 2015

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.

@pablomaurer
Copy link

@Azerothian worked on fedora =) yay!

@qinyang912
Copy link

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.

@adrianocola
Copy link

Use this with CentOS 7:

sudo pm2 startup systemd

@meteormatt
Copy link

@Azerothian
sudo pm2 startup systemd still not work

@4everinbeta
Copy link

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.

@KostyaTretyak
Copy link

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

@KostyaTretyak
Copy link

If on CentOS 7 run pm2 list not under root, showing an empty table (only headers). So should it be?

@KostyaTretyak
Copy link

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

@meteormatt
Copy link

@KostyaTretyak Still not working here.

@KostyaTretyak
Copy link

@meteormatt, but if in your project to do this:

sudo chown $USER: -R .
sudo chmod 755 index.js

@MarkOStewart
Copy link

MarkOStewart commented Apr 6, 2016

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

@Danthemanwenttojapan
Copy link

Danthemanwenttojapan commented May 6, 2016

Thanks @Azerothian, works like a boss. Just comment out '$PM2 delete all' in /etc/init.d/pm2-init.sh

@PedroWilliam
Copy link

PedroWilliam commented Jul 16, 2016

Thanks @Azerothian and I runned this command:

  • my user is 'centos'

sudo su -c "env PATH=$PATH:/usr/bin pm2 startup centos -u centos --hp /home/centos"

@Unitech
Copy link
Owner

Unitech commented Dec 6, 2016

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

@Unitech Unitech closed this as completed Dec 6, 2016
@jpujari-cartera
Copy link

jpujari-cartera commented Dec 7, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests