keymetrics / pm2-plus-tech-questions

http://docs.keymetrics.io/docs/pages/faq-troubleshooting/
27 stars 3 forks source link

boot run #210

Closed bgbruno closed 5 years ago

bgbruno commented 5 years ago

Hello,

I run #pm2 with os running from "/etc" script

if i run it like "pm2 {{whole_path_to_app}}/{{file}}.js" all machine is offline

so I have to use first jump to that directory with "cd" - then processes and server are runned ok, but no data in $console or "$pm2 list"

Q any help how can I run process with os boot?

vmarchaud commented 5 years ago

I'm not sure to understand, you want to run your process at startup ? If so you can use the startup hooks : https://pm2.io/doc/en/runtime/guide/startup-hook/#startup-hook

justocer commented 5 years ago

You can add systemd service

[Unit] Description=PM2 process manager Documentation=https://pm2.keymetrics.io/ After=network.target

[Service] Type=forking User=ubuntu LimitNOFILE=infinity LimitNPROC=infinity LimitCORE=infinity Environment=PATH=/usr/bin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin Environment=PM2_HOME=/home/ubuntu/.pm2 PIDFile=/home/ubuntu/.pm2/pm2.pid

WorkingDirectory=/var/www/yourdir/ ExecStart=/usr/local/bin/pm2 start ecosystem.config.js ExecReload=/usr/local/bin/pm2 kill && /usr/local/bin/pm2 start ecosystem.config.js ExecStop=/usr/local/bin/pm2 kill

[Install] WantedBy=multi-user.target