Creating a new service
To create a brand new service from scratch, use the --force
and --full
options together, like this:
donnie@ubuntu20-04:~$ sudo systemctl edit --force --full timestamp.service
This will create a new service file in the /etc/systemd/system/
directory, just as we saw previously.
For this demo, we'll create a service that will place a periodic timestamp into our system log file. Our timestamp.service
file will look like this:
[Unit] Description=Service Creation Demo Wants=network.target After=syslog.target network-online.target [Service] ExecStart=/usr/local/bin/timestamp.sh Restart=on-failure RestartSec=20 KillMode=process [Install] WantedBy=multi-user.target
Here, we see the RestartSec=
parameter, which we haven't seen before. This works with the Restart=
line and just says to wait for the designated number of seconds before restarting a crashed service. Here, we're saying to wait for 20 seconds. We don't see a Type=
line here...