Help needed creating a custom unit file (service) for swatch

Latest response

I've installed swatch and it works fine when run from the command line, next step was to create a custom unit file for it, I have done this (see below) and when I run systemctl start swatch.service it works great, however, if I reboot the server it fails to start, and then if I start it manually I get this error

[/etc/systemd/system/swatch.service:8] Executable path is not absolute, ignoring: kill -s KI...tch.pid)
Hint: Some lines were ellipsized, use -l to show in full.

Here is the custom unit file

[Unit]
Description=Swatch Log Monitoring Daemon
After=syslog.target network.target auditd.service sshd.service

[Service]
ExecStart=/usr/bin/swatch --config-file=/etc/swatch/yum.conf --tail-file=/var/log/yum.log --pid-file=/var/run/swatch.pid --daemon
ExecStop=kill -s KILL $(cat /var/run/swatch.pid)
Type=forking
PIDFile=/var/run/swatch.pid

[Install]
WantedBy=multi-user.target

swatch is in /bin/swatch and /usr/bin/swatch - I've tried both and I get the same result.

There is a /root/.swatch_script.xxxx file create when running it from the command line, is this causing an issue?

Responses

Stupid error, forgot to do

systemctl enable swatch.service

And add full path to the kill command.

Well it all works, and works after rebooting, but after it has been running for awhile I see this when running systemctl status swatch.service

[/etc/systemd/system/swatch.service:8] Executable path is not absolute, ignoring: kill -s KI...tch.pid)
Hint: Some lines were ellipsized, use -l to show in full.

Any reason you didn't give a fully-qualified path for the kill command?

Also, any reason you didn't enable automatic restarting (in case it dies)?

Later, I did post a comment that I did add the path, and that was the issue, I just couldn't see it at first, eyes getting tired! Thanks for mentioning auto restarting, I'll look into that.

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.