Caution! Article for developers

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

Creating a custom systemd service

Jan 31, 2023 · 2 minutes to read

Treon Gateway

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 Customer Support

If you have further questions or are at any point unsure how to continue, please contact Treon Customer Support.


Was this article helpful? Let us know.