Getting ready for production
After creating your first Connhex Edge service, you'll most likely want to be sure that:
- it will automatically start at every boot
- it restart in case of a failure or unexpected exit.
One way to achieve this is to leverage systemd
, a suite of basic building blocks for a Linux system.
Let's create a systemd service
for our diagnostic service.
Creating a systemd service
Create a file called connhex-edge-diagnostic.service
and put it in the /etc/systemd/system
folder of your edge.
[Unit]
Description=connhex-edge-diagnostic
# Our service will start after the 'connhex-edge-agent' service,
# a core connhex-edge service that is automatically installed.
After=connhex-edge-agent.service
Requires=connhex-edge-agent.service
[Service]
Type=simple
Restart=always
RestartSec=15s
# The path where the source files for our service are located.
WorkingDirectory=/opt/connhex
# Command used to start our service.
# For example: `/usr/bin/node /opt/connhex/diagnostic-service/src/index.js`
ExecStart=...
ExecStop=/bin/kill -s SIGINT $MAINPID
[Install]
WantedBy=multi-user.target
Launching the service
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 systemd, take a look here.
That's it!
Congratulations 🎉 You have completed every step required to install Connhex Edge, launch it, create a custom service and preparing it for production.