Linux: SystemD

From RHS Wiki
Revision as of 10:51, 4 April 2018 by Rafahsolis (talk | contribs)
Jump to navigation Jump to search
  1. List all running services
sytemctl
  1. Start/stop or enable/disable services
systemctl start foo.service
systemctl stop foo.service
systemctl restart foo.service
systemctl status foo.service
systemctl enable foo.service
systemctl disable foo.service
  1. Check if service is enabled
systemctl is-enabled foo.service; echo $?

Source: Useful SystemD Commands

Log to syslog

Use the following properties in your systemd service unit file:

StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=<your program identifier> # without any quote

Then, assuming your distribution is using rsyslog to manage syslogs, create a file in /etc/rsyslog.d/<new_file>.conf with the following content:

if $programname == '<your program identifier>' then /path/to/log/file.log
if $programname == '<your program identifier>' then ~