Table of Contents

Use as systemd service

With running the script as a service can be helpful if you administrate servers and habe developer teams with limited access. Instead of giving sudo permissions you can watch a touchfile to execute something specific as root, i.e. restart Apache httpd. In the real world this file would be touched during an automated deploy process.

Below is just an example service watching a dummy file in /tmp directory.

In /etc/systemd/system/ create a service config file onfilechange-demo.service

Description=Onfilechange demo

ExecStart=/usr/local/bin/ -f "/tmp/mytestfile" -c 'systemctl restart apache2'


Check if the service exists systemctl status onfilechange-demo. If so you can start and stop it with systemctl [start|stop] onfilechange-demo

To start the service on reboot you additionally need to enable it: systemctl enable onfilechange-demo.