Service as Root
/usr/local/bin/test1.sh
#/!/bin/bash while : do echo “Running …” logger $(date) sleep 10 done
chmod +x /usr/local/bin/test1.sh
/etc/systemd/system/test1.service
[Unit] Description= Simple test service
[Service] Type=simple ExecStart=/usr/local/bin/test1.sh
[Install] WantedBy=multi-user.target
sudo chmod 664 tracker.service sudo systemctl daemon-reload
sudo systemct enable tracker sudo systemct start tracker sudo systemct status tracker
sudo cat /var/log/syslog
Service as Non-root
- Run as a non-root user
- Restart automatically when not running
- Attempt restart after 1 second ( default is 100ms )
- Make sure it starts after network and nss-lookup are up
- Attempt to restart forever ( StartLimitIntervalSec=0 ) ( default stop after 5 fails in 10 secs )
[Unit] Description= Simple test service After=network.target nss-lookup.target StartLimitIntervalSec=0
[Service] Type=simple Restart=always RestartSec=1 User=prduser ExecStart=/usr/local/bin/test1.sh
[Install] WantedBy=multi-user.target
More Info
Type = simple # for a program that starts and just keeps running, sucess right after fork Type = exec # almost the same, sucess after both fork and binary up and running Type = forking # for a program that daemonizes itself ( launcher returns after forking ) Type = oneshot # for one shot serrvices that don’t keep running