systemd (systemctl, journalctl)
Managing services, reading logs with journalctl, writing your own unit and timers.
Services
Service status
systemctl status <service>
Start, stop, restart
sudo systemctl restart <service>
Same form for start and stop.
Reload config without restart
sudo systemctl reload <service>
Enable on boot and start now
sudo systemctl enable --now <service>
Disable autostart
sudo systemctl disable <service>
Failed services
systemctl --failedAll running services
systemctl list-units --type=service --state=runningLogs (journalctl)
Follow a service's logs
journalctl -u <service> -f
Logs since the last hour
journalctl -u <service> --since "1 hour ago"
Logs of the current boot, errors only
journalctl -b -p errKernel messages
journalctl -kHow much space the journal usesadvanced
journalctl --disk-usageShrink the journal to 500 MBadvanced
sudo journalctl --vacuum-size=500MUnit files
Show a unit's file
systemctl cat <service>
Override settings without editing the original
sudo systemctl edit <service>
Reload unit files after changes
sudo systemctl daemon-reloadMinimal service unitadvanced
# /etc/systemd/system/<service>.service [Unit] Description=My app After=network.target [Service] ExecStart=/usr/bin/node /opt/app/server.js Restart=on-failure User=app Environment=NODE_ENV=production [Install] WantedBy=multi-user.target
List timers (systemd's cron)advanced
systemctl list-timersBoot time breakdownadvanced
systemd-analyze blame