← Cheat Sheets

systemd and journalctl

Manage services and read logs.

# systemd and journalctl

Manage services and read logs.

```bash
sudo systemctl start|stop|restart|reload myapp
sudo systemctl enable myapp          # start at boot
sudo systemctl enable --now myapp
systemctl status myapp
sudo systemctl daemon-reload         # after editing unit files
journalctl -u myapp -f               # follow logs
journalctl -u myapp --since "1 hour ago"
journalctl -b -p err                 # errors since boot
```

**Unit file** (`/etc/systemd/system/myapp.service`)
```ini
[Unit]
Description=My app
After=network.target

[Service]
ExecStart=/usr/bin/node /srv/app/server.js
Restart=on-failure
User=app

[Install]
WantedBy=multi-user.target
```