Systemd Cheat Sheet
Systemd Cheat Sheet
Section titled “Systemd Cheat Sheet”Service files
Section titled “Service files”service files are located at /etc/systemd/system services are often time applications ran at statrtup.
Create a service file
Section titled “Create a service file”Instructions for creating a service file. Typically I create a start.sh script for each application so that all services will have a similar ExecStart line. If using start.sh be sure to use chmod +x start.sh to make the startup script executable.
-
sudo touch /etc/systemd/system/<service>.serviceto create your service file -
sudo nano /etc/systemd/system/<service>.serviceto edit
[Unit]Description=Pixoo Discord Bot # Name of your serviceWants=network.target # Indicates service needs to be stopped before network shutdownAfter=syslog.target network-online.target # Start service after network is online
[Service]Type=simple # The default value. The process started with ExecStart is the main process of the service.ExecStart=/bin/bash /home/<user>/pixoobot/start.sh # Replace with the actual path to your JAR fileuser=root # User to execute application underRestart=on-failure # Restart application if it diesRestartSec=10 # Duration to wait for restart on failure
[Install]WantedBy=multi-user.target # means that the custom service will start when systemd loadssystemctl daemon-reloadloads service file changessystemctl restart <service>journalctl -fu <service>to watch logs and verify started
usefull systemctl commands
Section titled “usefull systemctl commands”List running services
systemctl
Start a service
systemctl start <service>
Stop a service
systemctl stop <service>
Restart a service
systemctl restart <service>
Show status of a service
systemctl status <service>
Enable service to start on boot
systemctl enable <service>
Disable service start on boot
systemctl disable <service>
Check if service is enabled
systemctl is-enabled <service>