System MD
# List all loaded service units
systemctl list-units --type=service
# List all installed service files (including inactive)
systemctl list-unit-files --type=service
# Check status of a specific service (shows if running, logs, etc.)
systemctl status <service>.service
# Start a service
systemctl start <service>.service
# Stop a service
systemctl stop <service>.service
# Restart a service
systemctl restart <service>.service
# Enable a service to start at boot, `--now` will start it now
systemctl enable <service>.service
# Disable a service at boot
systemctl disable <service>.service
# Reloads the unit files
sudo systemctl daemon-reload
# Shows the PID of a service
systemctl show -p MainPID --value <service>.service
View logs
Make sure to use sudo since logs can only be viewed based on perms, using sudo allows you to see all of them.
sudo journalctl -fu <service>.service
# or
sudo journalctl -u accesscore.file.generation.integration.service -n 200Make a new service
- Make a new file at:
/etc/systemd/system/yourapp.service
[Unit]
Description=My Custom Service
After=network.target
[Service]
ExecStart=/usr/local/bin/mybinary --option foo # command to start your program
WorkingDirectory=/usr/local/bin # directory the program will use
Restart=always
User=youruser
Group=youruser
[Install]
WantedBy=multi-user.targetsudo systemctl daemon-reload
sudo systemctl enable yourapp.service
sudo systemctl start yourapp.service