Last active
April 29, 2020 19:24
-
-
Save celesteking/1aa739c081399b5061eda088735eee75 to your computer and use it in GitHub Desktop.
PM2 systemd unit file - under SCL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# put this into /etc/systemd/system/pm2-myuser.service , then `systemctl daemon-reload` | |
# `myuser` should be replaced with your username and `ExecXXX` params adjusted to relevant paths. | |
# This systemd unit file will spawn nodejs PM2 process manager. | |
# It's an adapted version of `pm2 startup` and contains proper things to use with latest systemd. | |
# This one uses nodejs from SCL (centos/redhat software collections) and allows you to get rid of error: | |
# systemd[1]: New main PID XXX does not belong to service, and PID file is not owned by root. Refusing. | |
# If you don't use SCL, just adjust `ExecXXX` params accordingly. | |
[Unit] | |
Description=PM2 process manager (%N) | |
Documentation=https://pm2.keymetrics.io/ | |
After=network.target | |
[Service] | |
Type=forking | |
User=myuser | |
SyslogIdentifier=%N | |
LimitNOFILE=infinity | |
LimitNPROC=infinity | |
LimitCORE=infinity | |
Environment=PM2_HOME=/home/myuser/.pm2 | |
PIDFile=/home/myuser/.pm2/pm2.pid | |
Restart=on-failure | |
RestartSec=1m | |
ExecStart=/usr/bin/scl enable rh-nodejs12 -- /home/myuser/pm2/bin/pm2 resurrect | |
ExecReload=/usr/bin/scl enable rh-nodejs12 -- /home/myuser/pm2/bin/pm2 reload all | |
ExecStop=/usr/bin/scl enable rh-nodejs12 -- /home/myuser/pm2/bin/pm2 kill | |
[Install] | |
WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment