Friday 28 December 2018

Simple systemd / systemctl

A basic systemd file:

[Unit]
Description=test

[Service]
User=andy
Type=simple
ExecStart=/home/andy/test

[Install]
WantedBy=multi-user.target

The file /home/andy/test must begin with: 
#!/bin/sh -
The core systemd commands: Not type systemctl not systemd
  • sudo systemctl status test       
  • sudo systemctl restart test
  • sudo systemctl stop test
For when you add something to: /etc/systemd/system
  • sudo systemctl daemon-reload     
Sending logs to syslog from services started by systemd:
Taken from here:
https://stackoverflow.com/questions/37585758/how-to-redirect-output-of-systemd-service-to-a-file
           
Use the following properties in your systemd service unit file:
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier= # without any quote
Then, assuming your distribution is using rsyslog to manage syslogs, create a file in /etc/rsyslog.d/.conf with the following content:
if $programname == '' then /path/to/log/file.log
& stop
restart rsyslog (sudo systemctl restart rsyslog)

No comments:

Post a Comment