Ubuntu 14.04 - pm2 startup not starting after reboot

前端 未结 5 1952
南旧
南旧 2021-01-02 13:04

I am using pm2 to start a node.js process, and I would like this process to be started automatically when the system (Ubuntu 14.04 on Intel Atom processor) is booted. I have

5条回答
  •  梦毁少年i
    2021-01-02 13:43

    Well, I think this worked, anyway. I was originally trying to start as a system user (no login shell) called node-red running the node application of the same name, and when that didn't work I tried starting as ordinary user max. After some fiddling with things it suddenly started working, but on this slow Atom processor, the node application starts only a couple of minutes after the desktop appears.

    To get it running under the system user: first, logged in as max, I deleted all pm2 jobs and ran pm2 save to create a empty dump file. Then I did:

    sudo npm install pm2@latest -g
    pm2 update
    

    To get the latest version, in case that helped. I moved from 0.14.7 to 0.15.7

    Then I ran

    sudo su -c "env PATH=$PATH:/usr/bin pm2 startup ubuntu -u node-red"
    

    and edited /etc/init.d/pm2-init.sh correcting the line that sets the PM2_HOME directory to the home directory of node-red:

    export PM2_HOME="/home/node-red/.pm2"
    

    Then I became a login version of the node-red user, changed to that user's home directory, started my job, and saved the process list:

    sudo -H -u node-red bash -l
    cd
    pm2 start /usr/local/bin/node-red --node-args="--max-old-space-size=128" -- -v -u /home/node-red/.node-red
    pm2 save
    

    Then I exited from node-red's shell, rebooted, and (after a minute or so's delay) there was the application running nicely!

    Note that this was ubuntu 14.04, which uses the init/upstart system. Later versions I think use systemd approach and may need the ubuntu parameter changed to systemd when creating the startup script.

    I'm still not really sure why it didn't work properly the first time, though.

提交回复
热议问题