🤖 Systemd
Automatically start and heal processes with systemd
Pocketbase Service
ls /etc/systemd/system/
nano /etc/systemd/system/pocketbase.service
touch /var/log/pocketbase.log
chmod 644 /var/log/pocketbase.log
[Unit]
Description=PocketBase
[Service]
Type=simple
User=root
Group=root
LimitNOFILE=4096
Restart=always
RestartSec=5s
StandardOutput=append:/var/log/pocketbase.log
StandardError=append:/var/log/pocketbase.log
ExecStart=/root/apps/guestbook/pocketbase serve --http="127.0.0.1:8090"
Environment="NEXT_PUBLIC_POCKETBASE_URL=https://linux.fireship.app/pb"
[Install]
WantedBy=multi-user.target
Next.js Service
nano /etc/systemd/system/nextjs.service
[Unit]
Description=Next.js Application
After=network.target
[Service]
Type=simple
User=root
Group=root
Restart=always
RestartSec=5s
WorkingDirectory=/root/apps/guestbook
ExecStart=/bin/bash -c 'source /root/.nvm/nvm.sh && /root/.nvm/versions/node/v20.15.0/bin/npm start'
Environment="NODE_ENV=production"
Environment="NEXT_PUBLIC_POCKETBASE_URL=https://linux.fireship.app/pb"
[Install]
WantedBy=multi-user.target
Run the Services
systemctl daemon-reload
systemctl start pocketbase
systemctl enable pocketbase
systemctl start nextjs
systemctl enable nextjs
systemctl status pocketbase
systemctl status nextjs