Skip to content

Instantly share code, notes, and snippets.

@andriika
Last active December 31, 2023 20:17
Show Gist options
  • Save andriika/e7eac941f291b154e9d789465e374cbd to your computer and use it in GitHub Desktop.
Save andriika/e7eac941f291b154e9d789465e374cbd to your computer and use it in GitHub Desktop.
systemd cheat sheet

systemd Cheat Sheet

Add/Edit a Unit (.service)

# add new .service file
cp app.service /etc/systemd/system/

# or edit existing
systemctl edit --full app.service

# reload the systemd process (to pick up a changes)
systemctl daemon-reload

# enable service (to let it started automatically at boot)
systemctl enable app.service

Querying State and Logs

# information about the process, and the latest logs
systemctl status app.service

# tail service logs
journalctl -u app.service -f

Unit Management

# start service
systemctl start nginx.service

# stop service
systemctl stop nginx.service

# restart service
systemctl restart nginx.service

# reload service (without interrupting normal functionality)
systemctl reload nginx.service

# disable enabled service
systemctl disable app.service

Resources

[Unit]
After=network.target, syslog.target
Conflicts=shutdown.target
[Service]
Type=simple
Restart=on-failure
RestartSec=30
TimeoutSec=5min
WorkingDirectory=/opt/listx
ExecStart=/usr/bin/java -jar /opt/listx/listx.jar /opt/listx/listx.properties
ExecStop=/bin/fuser 8080/tcp -k
# or ExecStop=/bin/kill $(ps aux | grep 'listx.jar' | awk '{print $2}')
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment