Working with services

Sometimes it is needed to enable or disable a service across a fleet of devices. This can be handled by distributing a simple script through "Configure -> File distribution" and templating this as follows:

A simple means of enabling/disabling services on group or device level

Sometimes it is important that services can be turned on or off for a large froup of devices. This can be achieved by running a simple script and templating the respective condition.

The scrip will look like this and is called node-red-enable.tmpl. The variable that is exposed here is "enable/disable". Obviously this can be set to enable, disable, start or stop

#!/usr/bin/env bash

systemctl {{enable/disable}} node-red
In the UI this will look as follows:


Explaining the "command to run"

The script is defined as a bash script and started by calling bash /usr/local/bin/ > /dev/null 2>&1 &. This runs the script in the background and the appendix > /dev/null 2>&1 & pipes bash output to /dev/null. This command will run any time the file is changed or a key-value pair changes.

It is possible to do this even more general by templating both service and action:

#!/usr/bin/env bash

systemctl {{enable/disable}} {{service_name}}

This allows to run any service and any action.

When does this run?

The "command to run" will only be invoked if the file after templating is different from what is there already. If the script is used with "start" but the file on the device is already written with systemctl start node-red nothing would happen.

Introducing a "run once" every time there is a new commit

This is a simple trick. The script file is extended with a comment that uses for example an epoch time stamp (or anything unique). Any time this is updated, the file distribution is saved and committed all devices in scope will run the script again because the script sha will be different than the one on the target device. Therefore the script will be replaced and run again through the after command.

#!/usr/bin/env bash

systemctl {{enable/disable}} {{service_name}}

# unique run-once trigger, here epoch time {{epoch}}


For more information please also consult the run-once page.