Safe Reboots
While BGR excellently manages your processes during runtime, you'll want them to restart automatically after system reboots. This can be done by creating a systemd
service.
Create systemd service:
Create a new service file at:
1sudo nano /etc/systemd/system/bgr-startup.service
Example bgr-startup.service
:
1# /etc/systemd/system/bgr-startup.service
2[Unit]
3Description=BGR Process Manager Startup
4After=network.target postgresql.service redis.service
5
6[Service]
7Type=oneshot
8RemainAfterExit=yes
9User=youruser
10Group=yourgroup
11WorkingDirectory=/home/youruser
12
13# Environment variables (optional)
14Environment="NODE_ENV=production"
15Environment="PATH=/usr/local/bin:/usr/bin:/bin"
16
17# Start all your services
18ExecStart=/bin/bash -c ' \
19 bgr postgres --restart && \
20 bgr api --restart
21'
22
23# Optional: Stop all BGR processes on shutdown
24ExecStop=/bin/bash -c 'bgr --nuke'
25
26# Restart policy
27Restart=on-failure
28RestartSec=10
29
30[Install]
31WantedBy=multi-user.target
Enable and start service:
1sudo systemctl enable bgr-startup.service
2sudo systemctl start bgr-startup.service