Skip to main content

Ubuntu Service Creation (Systemd)

Below are instructions on how to setup a binary as a linux service.

For additional systemd commands, see this: SystemCtl Usage

Service Creation

Here are steps to run a binary as a linux service.

Create a systemd unit file for the service by generating a file in: /lib/systemd/system
The file should contain these things:

[Unit]
Description=OGA.HostControl.Service
After=network.target

[Service]
ExecStart=/usr/bin/bliss/oga.hostcontrol.service/OGA.HostControl.Service --urls "http://192.168.1.201:4180;http://172.17.0.1:4180"
Environment=DOTNET_CLI_HOME=/temp
WorkingDirectory=/usr/bin/bliss/oga.hostcontrol.service
Restart=on-failure

[Install]
WantedBy=multi-user.target

NOTE: The above systemd unit file was generated for a dotnet service, called: OGA.HostControl.Service.

NOTE: This service runs as root, as no user was specified in the [Service] section.

NOTE: We have specified a working directory that points back to the bin folder of the service. This is necessary for a dotnet service.

Once the unit file has been created for the service, you must tell systemd to load it.
Tell systemd to reload unit files with this:

sudo systemctl daemon-reload

With the unit file available, you should be able to start the service.

Start the service with this:

sudo systemctl start servicename

Verify the service is running with this:

sudo systemctl status servicename

Once happy that the service is configured correctly and will run as required, you should enable it to start on boot.

To enable a service to start on boot, do this:

sudo systemctl enable servicename

At this point, your service will startup each time the machine reboots.