How to make a Systemd service run forever (“Bootup is not yet finished. Please try again later.”)

servicessystemd

I have created a systemd service that has to run forever (because it does the main job on my embedded computer):

# /etc/systemd/system/samplerbox.service
########################################
[Unit]
Description=Starts SamplerBox

[Service]
Type=oneshot
ExecStart=/root/SamplerBox/samplerbox.sh
WorkingDirectory=/root/SamplerBox/

[Install]
WantedBy=multi-user.target

Here is what it actually does:

# /root/SamplerBox/samplerbox.sh
################################
#!/bin/sh
python /root/SamplerBox/samplerbox.py

I enabled this service with

systemctl enable /etc/systemd/system/samplerbox.service

It works, and it is started on boot.


However, since I enabled this service, when I do systemd-analyze, I see:

Bootup is not yet finished. Please try again later.

Moreover, I get this information showing that the service is still seen as "activating" / starting :

# systemctl status samplerbox
â samplerbox.service - Starts SamplerBox
   Loaded: loaded (/etc/systemd/system/samplerbox.service; enabled)
   Active: activating (start) since Thu 1970-01-01 00:14:01 UTC; 11min ago
 Main PID: 258 (samplerbox.sh)
   CGroup: /system.slice/samplerbox.service
           ââ258 /bin/sh /root/SamplerBox/samplerbox.sh
           ââ260 python /root/SamplerBox/samplerbox.py

How to properly make a service run forever?

Best Answer

The solution was quite simple: one has to replace

[Service]
Type=oneshot

by

[Service]
Type=simple

This doc states:

Type=simple (default): systemd considers the service to be started up immediately. The process must not fork. Do not use this type if other services need to be ordered on this service, unless it is socket activated.

...

Type=oneshot: this is useful for scripts that do a single job and then exit. You may want to set RemainAfterExit=yes as well so that systemd still considers the service as active after the process has exited.