Caution! Article for developers

Information on this page is intended particularly for users with advanced technical knowledge.

Creating a custom systemd service

Sep 6, 2023 · 2 minutes to read

Treon Gateway Treon Gateway 2 Treon Gateway in Protective Enclosure


The Treon Gateway uses systemd as it’s init/service manager. This article helps you add your own service or unit file to start your application automatically after boot process is finished and make it persistent between updates. This article will not teach you how to create your systemd unit file.

Because the gateways update process wipes the system partition mounted to / after each update, the unit file has to be persisted somehow.

Unfortunately, we cannot use the persist_move utility described in here to persist the unit file because persist_move is executed after systemd has read the unit files. However we can use the updatehooks to copy the unit file to system partition when the gateway is running it’s update process.


Tips for unit files and verifying your unit file works

First you will need to create your unit file. The unit file should be placed to e.g. the /lib/systemd/system-folder and after the content has been changed, then sudo systemctl daemon-reload should be run.

We have used:

ExecStartPre=/usr/bin/test -f /etc/first_boot_done


Make sure the service is not run while the Treon Gateway is updating! Also make sure it does not start too early.

After creating this unit file and running the sudo systemctl daemon-reload-command, the service should start automatically. It can be verified that it runs with systemctl status <service-name>.


Persisting the unit file

To make sure the unit file is persisted over any Treon Gateway firmware updates, it has to be installed each time the gateway has been updated to new firmware (as the firmware update wipes the system partition).

This can be done with updatehooks by creating an updatehook which copies the unit file to it’s system partition location during update process.

Example updatehook:


cp /mnt/data/my_application.service /lib/systemd/system/
systemctl daemon-reload
systemctl enable my_application

For this to work, the unit file has to be located in the folder /mnt/data/my_application.service.


Treon Support

You still have questions? Our dedicated team of experts is happy to help you! Please contact Treon Support directly by e-mail.

Did you know? Treon offers Premium Support and Maintenance Packages for our customers. Get even more out of Treon and boost your sales - inquire now about features and prices!


Was this article helpful? Let us know.