6️⃣ PM2 and SystemD Integration¶
Step 1 — Install PM2 globally¶
Step 2 — Start both bots under PM2¶
cd ~/gunbot-live
pm2 start ./gunthy-linux --name gunbot-live --time
cd ~/gunbot-sim
pm2 start ./gunthy-linux --name gunbot-sim --time
Check:
Step 3 — Enable PM2 persistence¶
pm2 save
pm2 startup systemd -u gunbot --hp /home/gunbot
sudo env PATH=$PATH:/usr/bin pm2 startup systemd -u gunbot --hp /home/gunbot
Note:
The second command registers PM2 for thegunbotuser so it restarts automatically after reboots.
Step 4 — Create a systemd override for clean restarts¶
Insert:
[Service]
Type=simple
ExecStart=
ExecStart=/usr/bin/pm2 resurrect
Restart=on-failure
User=gunbot
Environment=PM2_HOME=/home/gunbot/.pm2
Reload systemd and enable persistence:
Check status: