Skip to content

Instantly share code, notes, and snippets.

@fourjr
Created October 23, 2024 05:47
Show Gist options
  • Save fourjr/55b22041ad436a35de102e4e3aa3a6d3 to your computer and use it in GitHub Desktop.
Save fourjr/55b22041ad436a35de102e4e3aa3a6d3 to your computer and use it in GitHub Desktop.
using systemctl

Using Systemctl

Adapted/shortened from digitalocean

Creating a unit file

nano /etc/systemd/system/app.service

[Unit]
Description=App
After=multi-user.target
Wants=network-online.target  # all these lines are optional
After=network-online.target

[Service]
WorkingDirectory=/home/user/...
User=user
Group=user
ExecStart=/usr/bin/... #full command with full paths
Type=idle
Restart=always
RestartSec=15

[Install]
WantedBy=multi-user.target
  • systemctl daemon-reload reloads all unit files
  • systemctl cat app.service views the unit file

Auto Start

  • systemctl enable app.service
  • systemctl disable app.service

Start / Stop / Status

  • systemctl start app.service
  • systemctl stop app.service
  • systemctl status app.service

Logs

journalctl -u app.service -f - -f is the tail argument

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment