Skip to main content

Start your service

After your wrote your first custom service, most likely you want to be sure that it will automatically start at every boot and restart in case of a failure or unexpected exit. One way to achive that is to exploit the potential of systemd, a suite of basic building blocks for a Linux system.

Let's create a systemd service for our diagnostic service developed in the previous section. Create a file called connhex-edge-diagnostic.service and place it in the /etc/systemd/system folder inside your edge device.

# Our service will start after the 'connhex-edge-export' service,
# a core connhex-edge service that is automatically installed on your device.

# The path where the source files of our service are located.
# Command used to start our service.
ExecStart=/usr/bin/node /opt/connhex/diagnostic-service/src/index.js
ExecStop=/bin/kill -s SIGINT $MAINPID


We can now start our service:

$ systemctl start connhex-edge-diagnostic

And automatically get it to start on boot:

$ systemctl enable connhex-edge-diagnostic
Systemd service configuration

If you want a more in-depth description of all available systemd services configurations take a look here.