Starting scripts with systemd
It’s super simple to set up a service in system that starts when you say so, or automatically on boot.
create a .service file in
[Unit] Description=myservicename [Service] ExecStart=/bin/bash /home/scipts/myscriptname.sh StandardOutput=syslog StandardError=syslog SyslogIdentifier=myservicename # without any quote [Install] WantedBy=multi-user.target
once saved, reload the unit files
# systemctl daemon-reload
and start the service
# systemctl start myservicename
# systemctl stop myservicename
to check status
systemctl status myservicename
and last but not least, to enable a service on next boot
systemctl enable myservicename
to view logs:
journalctl is used to view logs on systemd based machines, Logs are identified by the SyslogIdentifier it can be changed to anything you’d like. SyslogIdentifier in this example is myservicename.
-f is used to follow, like tail.
journalctl -u myservicename -f