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

Ubuntu Startup Script - Not Working #289

Closed
ishanrakitha opened this Issue Feb 4, 2014 · 26 comments

Comments

10 participants
@ishanrakitha

ishanrakitha commented Feb 4, 2014

I'm using ubuntu server 12.10. i have genarated the start up script and executed the given command, but i have to manually execute "pm2 restart all" to get my process online. I can see my process in pm2 after system start up. it show as online. but it's not.

@Unitech

This comment has been minimized.

Show comment
Hide comment
@Unitech

Unitech Feb 4, 2014

Owner

Which nodejs version do you use ? pm2 version ?
Have you already generated an init script with older pm2 version ?

Owner

Unitech commented Feb 4, 2014

Which nodejs version do you use ? pm2 version ?
Have you already generated an init script with older pm2 version ?

@ishanrakitha

This comment has been minimized.

Show comment
Hide comment
@ishanrakitha

ishanrakitha Feb 4, 2014

My node version is - v0.10.24

just now i removed my startup script using "sudo update-rc.d -f pm2-init.sh remove" and reinstalled pm2 latest version. still the same.

ishanrakitha commented Feb 4, 2014

My node version is - v0.10.24

just now i removed my startup script using "sudo update-rc.d -f pm2-init.sh remove" and reinstalled pm2 latest version. still the same.

@Unitech

This comment has been minimized.

Show comment
Hide comment
@Unitech

Unitech Feb 5, 2014

Owner

Can you do something like pm2 dump; pm2 kill; pm2 resurrect and tell me if processes are up ?

Owner

Unitech commented Feb 5, 2014

Can you do something like pm2 dump; pm2 kill; pm2 resurrect and tell me if processes are up ?

@ishanrakitha

This comment has been minimized.

Show comment
Hide comment
@ishanrakitha

ishanrakitha Feb 5, 2014

yes all the processes are up.

ishanrakitha commented Feb 5, 2014

yes all the processes are up.

@Unitech

This comment has been minimized.

Show comment
Hide comment
@Unitech

Unitech Feb 12, 2014

Owner

Have you managed to fix this issue ?

Owner

Unitech commented Feb 12, 2014

Have you managed to fix this issue ?

@ishanrakitha

This comment has been minimized.

Show comment
Hide comment
@ishanrakitha

ishanrakitha Feb 12, 2014

no, still I'm manually restarting pm2 after a system reboot. I think the issue is in my ubuntu installation. To be sure I ll test pm2 and my services in a fresh ubuntu server and see.

ishanrakitha commented Feb 12, 2014

no, still I'm manually restarting pm2 after a system reboot. I think the issue is in my ubuntu installation. To be sure I ll test pm2 and my services in a fresh ubuntu server and see.

@pstadler

This comment has been minimized.

Show comment
Hide comment
@pstadler

pstadler Feb 17, 2014

I have the exact same problem on Ubuntu 12.04 with Node v0.10.25. It seems that the processes are not getting dumped, so there's nothing to resurrect.

pstadler commented Feb 17, 2014

I have the exact same problem on Ubuntu 12.04 with Node v0.10.25. It seems that the processes are not getting dumped, so there's nothing to resurrect.

@soyuka

This comment has been minimized.

Show comment
Hide comment
@soyuka

soyuka Feb 17, 2014

Collaborator

Had this issue too (debian 7),

Workaround :
I've edited the /etc/init.d/pm2.sh and edited to pm2 start path/to/script

It seems that the dumped result is lost after rebooting. Dump/kill/resurrect are working fine when executed.

Collaborator

soyuka commented Feb 17, 2014

Had this issue too (debian 7),

Workaround :
I've edited the /etc/init.d/pm2.sh and edited to pm2 start path/to/script

It seems that the dumped result is lost after rebooting. Dump/kill/resurrect are working fine when executed.

@pstadler

This comment has been minimized.

Show comment
Hide comment
@pstadler

pstadler Feb 17, 2014

That's the obvious solution but this fancy dump / resurrect method should still be fixed.

pstadler commented Feb 17, 2014

That's the obvious solution but this fancy dump / resurrect method should still be fixed.

@soyuka

This comment has been minimized.

Show comment
Hide comment
@soyuka

soyuka Feb 17, 2014

Collaborator

+1
Just tried again with dump/resurect in the init.d/pm2-init.sh and it's working (Debian 7).

The pm2 script has to be running when the shutdown takes place (or it won't be dumped). Only one restart script for pm2 should be provided.

Collaborator

soyuka commented Feb 17, 2014

+1
Just tried again with dump/resurect in the init.d/pm2-init.sh and it's working (Debian 7).

The pm2 script has to be running when the shutdown takes place (or it won't be dumped). Only one restart script for pm2 should be provided.

@ishanrakitha

This comment has been minimized.

Show comment
Hide comment
@ishanrakitha

ishanrakitha Feb 18, 2014

if i have multiple processes i have set my path to "processes.json" right ? or is it possible to add mutiple services to "pm2-init.sh" ? as you mentioned earlier.

ishanrakitha commented Feb 18, 2014

if i have multiple processes i have set my path to "processes.json" right ? or is it possible to add mutiple services to "pm2-init.sh" ? as you mentioned earlier.

@soyuka

This comment has been minimized.

Show comment
Hide comment
@soyuka

soyuka Feb 18, 2014

Collaborator

It looked like this :
https://gist.github.com/soyuka/9080276

And take a look at the update-rc.d command if you're on ubutun/debian to make your own.

But the dump/resurrect method is working.

Collaborator

soyuka commented Feb 18, 2014

It looked like this :
https://gist.github.com/soyuka/9080276

And take a look at the update-rc.d command if you're on ubutun/debian to make your own.

But the dump/resurrect method is working.

@pstadler

This comment has been minimized.

Show comment
Hide comment
@pstadler

pstadler Feb 23, 2014

I was able to fix the problem. It seems that I was in the wrong directory while running the command to setup the init script. Everything works fine after setting the correct path to the user's home directory in /etc/init.d/pm2-init.sh:

export HOME="/home/www"

I hope this helps.

pstadler commented Feb 23, 2014

I was able to fix the problem. It seems that I was in the wrong directory while running the command to setup the init script. Everything works fine after setting the correct path to the user's home directory in /etc/init.d/pm2-init.sh:

export HOME="/home/www"

I hope this helps.

@ishanrakitha

This comment has been minimized.

Show comment
Hide comment
@ishanrakitha

ishanrakitha Feb 23, 2014

In my server "export HOME="/root" was already set. temporarily I'm using "su - root -c "pm2 resurrect" in my "/etc/rc.local".

ishanrakitha commented Feb 23, 2014

In my server "export HOME="/root" was already set. temporarily I'm using "su - root -c "pm2 resurrect" in my "/etc/rc.local".

@soyuka

This comment has been minimized.

Show comment
Hide comment
@soyuka

soyuka Feb 24, 2014

Collaborator

So, did you figure a way to make it work?

Collaborator

soyuka commented Feb 24, 2014

So, did you figure a way to make it work?

@ishanrakitha

This comment has been minimized.

Show comment
Hide comment
@ishanrakitha

ishanrakitha Feb 24, 2014

No I'm not. Using rc.local to resurrect my process on startup.

ishanrakitha commented Feb 24, 2014

No I'm not. Using rc.local to resurrect my process on startup.

@fschwiet

This comment has been minimized.

Show comment
Hide comment
@fschwiet

fschwiet May 12, 2014

If it helps, I think I have a repro of this issue that can be created easily in vagrant: https://github.com/fschwiet/helloVagrant/tree/pm2-issue42900019

  1. install vagrant and virtualbox
  2. clone the repository
  3. run "vagrant up nodejs"
  4. Observe that http://192.168.33.11:8080/ returns a hello world message
  5. run "vagrant reload nodejs"
  6. Observe that http://192.168.33.11:8080/ fails (expected result: a hello world message)

Here is a snippet from the Vagrantfile:

config.vm.define "nodejs" do |nodejs|

    nodejs.vm.network "private_network", ip: "192.168.33.11"

    nodejs.vm.provision :chef_solo do |chef|
        chef.cookbooks_path = "cookbooks"
        chef.add_recipe "nodejs::install_from_binary"
        chef.add_recipe "nodejs::npm"

        chef.json = {
            :nodejs => {
                version: "0.10.6",
                checksum_linux_x64: "cc7ccfce24ae0ebb0c50661ef8d98b5db07fc1cd4a222c5d1ae232260d5834ca"
            }   
        }
    end

    nodejs.vm.provision "shell", inline: "sudo npm install pm2 -g"
    nodejs.vm.provision "shell", inline: "cd /vagrant/src/server; pm2 start hello-server.js"
    nodejs.vm.provision "shell", inline: "cd ~;  pm2 startup ubuntu;"
  end

fschwiet commented May 12, 2014

If it helps, I think I have a repro of this issue that can be created easily in vagrant: https://github.com/fschwiet/helloVagrant/tree/pm2-issue42900019

  1. install vagrant and virtualbox
  2. clone the repository
  3. run "vagrant up nodejs"
  4. Observe that http://192.168.33.11:8080/ returns a hello world message
  5. run "vagrant reload nodejs"
  6. Observe that http://192.168.33.11:8080/ fails (expected result: a hello world message)

Here is a snippet from the Vagrantfile:

config.vm.define "nodejs" do |nodejs|

    nodejs.vm.network "private_network", ip: "192.168.33.11"

    nodejs.vm.provision :chef_solo do |chef|
        chef.cookbooks_path = "cookbooks"
        chef.add_recipe "nodejs::install_from_binary"
        chef.add_recipe "nodejs::npm"

        chef.json = {
            :nodejs => {
                version: "0.10.6",
                checksum_linux_x64: "cc7ccfce24ae0ebb0c50661ef8d98b5db07fc1cd4a222c5d1ae232260d5834ca"
            }   
        }
    end

    nodejs.vm.provision "shell", inline: "sudo npm install pm2 -g"
    nodejs.vm.provision "shell", inline: "cd /vagrant/src/server; pm2 start hello-server.js"
    nodejs.vm.provision "shell", inline: "cd ~;  pm2 startup ubuntu;"
  end
@ishanrakitha

This comment has been minimized.

Show comment
Hide comment
@ishanrakitha

ishanrakitha May 25, 2014

Thank you :)

ishanrakitha commented May 25, 2014

Thank you :)

@fschwiet

This comment has been minimized.

Show comment
Hide comment
@fschwiet

fschwiet May 25, 2014

For reference to those running into this kind of issue, to keep pm2 running after reboot, I am using crontab:

(crontab -l ; echo '@reboot /sites/provision.sites.sh') | crontab

Where provision.sites.sh is something like:

if [ $(ps -e -o cmd | grep pm2 | grep hello-server | grep -v grep | wc -l | tr -s "\n") -eq 0 ]
then
    cd /sites/www; 
    /usr/local/bin/pm2 start hello-server.js --user vagrant
fi

fschwiet commented May 25, 2014

For reference to those running into this kind of issue, to keep pm2 running after reboot, I am using crontab:

(crontab -l ; echo '@reboot /sites/provision.sites.sh') | crontab

Where provision.sites.sh is something like:

if [ $(ps -e -o cmd | grep pm2 | grep hello-server | grep -v grep | wc -l | tr -s "\n") -eq 0 ]
then
    cd /sites/www; 
    /usr/local/bin/pm2 start hello-server.js --user vagrant
fi
@ishanrakitha

This comment has been minimized.

Show comment
Hide comment
@ishanrakitha

ishanrakitha May 25, 2014

noted and thanks :)

ishanrakitha commented May 25, 2014

noted and thanks :)

@kompot

This comment has been minimized.

Show comment
Hide comment
@kompot

kompot Jun 15, 2014

Seems like I've found issue why it does fail with vagrant.
/var/log/boot.log contains Process /home/vagrant/app/index.js not launched - (script missing).
vagrant/app folder is mounted via vagrant and of course it's mounted after booting.

Have not found a solution yet. But anyway it has nothing to do with pm2.

kompot commented Jun 15, 2014

Seems like I've found issue why it does fail with vagrant.
/var/log/boot.log contains Process /home/vagrant/app/index.js not launched - (script missing).
vagrant/app folder is mounted via vagrant and of course it's mounted after booting.

Have not found a solution yet. But anyway it has nothing to do with pm2.

soyuka added a commit that referenced this issue Jun 16, 2014

@jalvarezsamayoa

This comment has been minimized.

Show comment
Hide comment
@jalvarezsamayoa

jalvarezsamayoa Aug 4, 2014

@kompot a solution for the vagrant + pm2 start on reload is to add an upstart script that takes care of restarting you app after vagrant has mounted the source.

This is what I use:

# /etc/init/vagrant-mounted.conf
description "Start pm2 on vagrant mounted"
author      "Me"

start on vagrant-mounted

expect fork

setgid vagrant
setuid vagrant

script
 export HOME=/home/vagrant
 export PATH=/usr/local/node/node-default/bin:/usr/local/bin:/bin
 cd /home/vagrant
 pm2 start app.js
end script

jalvarezsamayoa commented Aug 4, 2014

@kompot a solution for the vagrant + pm2 start on reload is to add an upstart script that takes care of restarting you app after vagrant has mounted the source.

This is what I use:

# /etc/init/vagrant-mounted.conf
description "Start pm2 on vagrant mounted"
author      "Me"

start on vagrant-mounted

expect fork

setgid vagrant
setuid vagrant

script
 export HOME=/home/vagrant
 export PATH=/usr/local/node/node-default/bin:/usr/local/bin:/bin
 cd /home/vagrant
 pm2 start app.js
end script
@ishanrakitha

This comment has been minimized.

Show comment
Hide comment
@ishanrakitha

ishanrakitha Aug 5, 2014

Thank you. :)

ishanrakitha commented Aug 5, 2014

Thank you. :)

@ipsips

This comment has been minimized.

Show comment
Hide comment
@ipsips

ipsips Mar 2, 2015

how would start an app with pm2 after vagrant-mount on centos 7 (uses systemd)?

ipsips commented Mar 2, 2015

how would start an app with pm2 after vagrant-mount on centos 7 (uses systemd)?

@eexit

This comment has been minimized.

Show comment
Hide comment
@eexit

eexit Mar 3, 2015

Hello,

I'm having the same issue:

  • NodeJS v0.10.33
  • NPM 1.3.6
  • Centos 7
chkconfig --list | grep $(runlevel | awk '{ print $2}'):on

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

iprdump         0:off   1:off   2:on    3:on    4:on    5:on    6:off
iprinit         0:off   1:off   2:on    3:on    4:on    5:on    6:off
iprupdate       0:off   1:off   2:on    3:on    4:on    5:on    6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off
pm2-init.sh     0:off   1:off   2:on    3:on    4:on    5:on    6:off

The pm2 dump; pm2 kill; pm2 resurrect commands work wells... I don't get it.
Any idea?

Thanks!

eexit commented Mar 3, 2015

Hello,

I'm having the same issue:

  • NodeJS v0.10.33
  • NPM 1.3.6
  • Centos 7
chkconfig --list | grep $(runlevel | awk '{ print $2}'):on

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

iprdump         0:off   1:off   2:on    3:on    4:on    5:on    6:off
iprinit         0:off   1:off   2:on    3:on    4:on    5:on    6:off
iprupdate       0:off   1:off   2:on    3:on    4:on    5:on    6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off
pm2-init.sh     0:off   1:off   2:on    3:on    4:on    5:on    6:off

The pm2 dump; pm2 kill; pm2 resurrect commands work wells... I don't get it.
Any idea?

Thanks!

@agusputra

This comment has been minimized.

Show comment
Hide comment
@agusputra

agusputra Aug 6, 2015

On Ubuntu, I followed @soyuka advice. Edit /etc/init.d/pm2-init.sh , and change PM2_HOME="/root/.pm2" to PM2_HOME="/path/to/.pm2"

agusputra commented Aug 6, 2015

On Ubuntu, I followed @soyuka advice. Edit /etc/init.d/pm2-init.sh , and change PM2_HOME="/root/.pm2" to PM2_HOME="/path/to/.pm2"

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