Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Ubuntu Startup Script - Not Working #289

ishanrakitha opened this Issue · 23 comments

7 participants

Ishan Rakitha Alexandre Strzelewicz Patrick Stadler Antoine Bluchet fschwiet Anton Fedchenko Javier Alvarez
Ishan Rakitha

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.

Alexandre Strzelewicz

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

Ishan Rakitha

My node version is - v0.10.24

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

Alexandre Strzelewicz

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

Ishan Rakitha

yes all the processes are up.

Alexandre Strzelewicz

Have you managed to fix this issue ?

Ishan Rakitha

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.

Patrick Stadler

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.

Antoine Bluchet
Patrick Stadler

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

Antoine Bluchet

Just tried again with dump/resurect in the init.d/ 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.

Ishan Rakitha

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

Antoine Bluchet

It looked like this :

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.

Patrick Stadler

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/

export HOME="/home/www"

I hope this helps.

Ishan Rakitha

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

Antoine Bluchet

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

Ishan Rakitha

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


If it helps, I think I have a repro of this issue that can be created easily in vagrant:

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

Here is a snippet from the Vagrantfile:

config.vm.define "nodejs" do |nodejs| "private_network", ip: ""

    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"

    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;"
Ishan Rakitha

Thank you :)


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/') | crontab

Where is something like:

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

noted and thanks :)

Anton Fedchenko

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.

Antoine Bluchet soyuka referenced this issue from a commit
Antoine Bluchet soyuka Added #289 link to readme c662d5b
Javier Alvarez

@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

 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
Ishan Rakitha

Thank you. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.