Julien Sellier

Last update: 2025-04-29

Run your App with Systemd

A very simple way to deploy an application to a server is by using the already built-in service system. Debian-based Linux distros use systemd for this purpose.

Systemd will start your application when the server boots and restart it if it goes down.

Setup a Unit File

The first step is creating the unit file to tell systemd to run your app as a daemon.

In /etc/systemd/system/myapp.service:

[Unit]
Description=My App
After=network.target

[Service]
Type=simple
Restart=always
User=root
Group=root
WorkingDirectory=/var/<SERVICE_NAME>/
ExecStart=/usr/local/bin/<SERVICE_NAME>

[Install]
WantedBy=multi-user.target

Note: You probably want to use another user than root.

Once this is done, enable the service by running:

systemctl enable <SERVICE_NAME>

NB: Once enabled, the service will be started by systemd on boot.

To start the service immediately, run:

systemctl start <SERVICE_NAME>

Useful Commands

To check that the daemon is running:

systemctl status <SERVICE_NAME>

To check systemd logs for your service:

journalctl -u <SERVICE_NAME>

NB: Use the -f flag to follow the live logs.