Auto-Start Your Programs Using systemd

Greetings, fellow program enthusiasts! Today, let’s explore systemd, the trusty conductor orchestrating your server’s startup symphony. This guide shows the process of automating program launches during boot on Ubuntu, ensuring a seamless performance every time your server takes the spotlight. Follow me as we learn how to auto-start your programs using systemd.

Let’s jump straight into action, beginning with the creation of a system service file—a vital script that dictates how your programs take the stage during boot.

In your terminal, run the following to create your .service file and open the editor:

sudo nano /etc/systemd/system/ProgramNameHere.service

Within this file, you’ll craft the code to run your program:

Description=Program Name Description

ExecStart=/bin/bash -c 'cd /path/to/program_folder &&'


Using the above information as a template, input your program parameters and save your file.

Let’s break down the sections in this service file:

[Unit] Section:

  • Description: A brief, human-readable description of the service.
  • After: Specifies the service’s startup order, ensuring it kicks in after the network is up.

[Service] Section:

  • ExecStart: Specifies the full path to your program.
  • WorkingDirectory: Sets the working directory to your program’s location.
  • User and Group: Define the user and group under which the program should run.

[Install] Section:

  • WantedBy: Specifies the target (e.g., crucial for enabling the service during startup.

Here’s a real-world example using a Python-based mining program, Duino Coin.

If you want to try the example as well, if you are following along step by step, get the program files for Duino Coin here:

Simply install the program to ensure it is configured and runs, then follow the example below:

sudo nano /etc/systemd/system/duino-coin.service

Here is the code we will use for the program auto-start file:

Description=Duino Coin Program

ExecStart=/bin/bash -c 'cd /home/ubuntu/duino-coin && python3'


Once the file is saved, reload the daemon and enable the new service (using Duino Coin as an example):

sudo systemctl daemon-reload
sudo systemctl enable duino-coin
sudo systemctl restart duino-coin

To check the status:

sudo systemctl status duino-coin

Remember to adjust paths and configurations as needed for your specific setup.

For quick reference on working directory, username, and primary group ID:
# Working directory and program directory

# Username

# Primary group
id -gn

Troubleshooting tip: If the service doesn’t start as expected, checking the output of sudo journalctl -xe can provide additional information.

Python Virtual Environments:

For those working with Python programs in virtual environments, adapting the [Service] section is straightforward. Here’s an example:

ExecStart=/bin/bash -c 'cd /home/ubuntu/duino-coin && source myvenv/bin/activate && python3'

Now, armed with this guide, let your programs gracefully take the stage with each server boot! systemd can do so much more than auto-start;  more information can be found here on systemd’s website:

There you go! This is systemd! These are simple skills to auto-start your programs using systemd. Whether you’re a seasoned server maestro or a curious newcomer, this practical guide equips you to automate your system’s programs, ensuring a flawless performance each time the curtain rises. So go ahead, empower your server, and let the automation begin! May your servers hum with efficiency and your programs dance in perfect rhythm with every boot. Happy coding!


4 thoughts on “Auto-Start Your Programs Using systemd

  1. Ezzy says:

    How do you break things down so easily?! This was an awesome read.

    1. Sean says:

      Thank you! I really try and imagine I am being shown this for this first time, and write to that.

      Some days are better than others 😉


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.