Create a simple service unit
Minimal systemd service unit template
cat > /etc/systemd/system/myapp.service <<EOF
[Unit]
Description=My App
After=network.target
[Service]
ExecStart=/usr/bin/myapp
Restart=always
RestartSec=5
User=appuser
[Install]
WantedBy=multi-user.target
EOF
More systemd commands
-
systemd-run --uid=1000 --gid=1000 --wait /usr/bin/myapp --taskRun a transient one-shot unit under a specific user
-
cat > /etc/systemd/system/backup.timer <<EOF [Unit] Description=Daily backup [Timer] OnCalendar=daily Persistent=true [Install] WantedBy=timers.target EOFReplacement for cron with Persistent=true for missed runs
-
systemctl set-property myapp.service MemoryMax=512M CPUQuota=50%Apply cgroup limits without editing unit file
-
systemctl status myapp.service | grep -E 'Memory:|CPU:|Tasks:'Current memory, CPU, and task counts from cgroup
-
systemctl list-units --type=socket --allAll socket-activated units and their state