Skip to content

Service

A service is a long-running process that can be started and stopped manually as well as set to automatically start when the system boots. It can be used to run background tasks, handle network requests, and interact with the system.

Create Unit File

We're going to create a systemd service for the Khatru29 example relay which will allow us to automatically start the relay on boot.

To do this we're going to create and open the following systemd unit file:

nano /etc/systemd/system/khatru29.service

Edit Unit File

We're now going to add the following lines to the khatru29.service unit file:

[Unit]
Description=Khatru29 Service
After=network.target

[Service]
Type=simple
User=nostr
Group=nostr
WorkingDirectory=/home/nostr
EnvironmentFile=/etc/systemd/system/khatru29.env
ExecStart=/usr/local/bin/khatru29
Restart=on-failure

[Install]
WantedBy=multi-user.target

This service tells systemd to start the Khatru29 example relay as the nostr user after the network has been properly configured using our specified environment file and to attempt to restart the service if it fails.

Reload systemd

To apply the newly created Khatru29 example relay service we're going to reload systemd:

systemctl daemon-reload

Enable Service

We can enable the Khatru29 example relay service to automatically start on boot:

systemctl enable khatru29.service

Start Service

To start the Khatru29 example relay service:

systemctl start khatru29.service

Check Status

The relay service should now be running and set to automatically start on boot.

You can check the status of the service using:

systemctl status khatru29.service

If the service is running, you should see the following in the output:

Active: active (running)

If the service is enabled to automatically start on boot, you should see the following in the output:

Loaded: loaded (/etc/systemd/system/khatru29.service; enabled; preset: enabled)