Linux: Let your program run as background service

Process - checkIn this post you will learn how to convert your headless Linux program to a service running in the background.

Here with headless is meant a program without user interaction and without graphical user interface (GUI).

Assumed is that you are running a Linux distribution with Systemd enabled, like Ubuntu 15.10.

In the example below, the name of the service is ‘my-service‘ and the executable is named: ‘/opt/bin/MyProgram‘. Of course you can change these to your own needs.

First create a file:

/etc/systemd/system/my-service.service

.. with these contents:

After creating the file, let the systemd-daemon restart to read the new configuration file:

Now you are ready to start your new service:

To check the status of the service, run the command:

When everything is ok, make sure the service will be started at the next boot:

Read more