Trying to create a systemd startup service

I just did all the below and prior to reboot all looked good, but once I rebooted Deluge still started immediately., any thoughts on what’s going on?

I would like to create a service to run a script at system startup and would like to know if I have it right before I actually create it.

What I would like is to delay Deluge for 4 minutes at system boot to give my external drives time to actually mount before Deluge starts.

From what I’ve gathered so far is putting the below in a txt file, naming it delugedlay.sh, make it executable, place it in my desired location. Once I do that I need to know if I understand correctly what is needed for a systemd service.

#!/bin/bash
sleep 240 && deluge

Open a terminal in the folder it’s located and run chmod +x delugedelay.sh

```
[Unit]
Description=delugedelay

[Service]
Type=simple
ExecStart=/home/cccp/.config/delugedelay.sh
Restart=always

[Install]
WantedBy=multi-user.targe

Save that as delugedelay.service in /etc/systemd/system/ . Then the below.

sudo systemctl daemon-reload

sudo systemctl enable delaydeluge.service

sudo systemctl start delugedelay.service

sudo systemctl status -l delugedelay.service

Thanks

Is that a typo for WantedBy? It should be multi-user.target. You can run a script that creates a dummy file to test whether the service itself is working fine. Also, you can refer to this: refresh-mirrors/refresh-mirrors.service at main · RebornOS-Team/refresh-mirrors · GitHub

OK just checked it and it’s correct. That has to be from when I high-lited it to copy it.

[Unit]
Description=delugedelay

[Service]
Type=simple
ExecStart=/home/cccp/.config/delugedelay.sh
Restart=always

[Install]
WantedBy=multi-user.target

What is the output of systemctl start and systemctl status for your service? Does it say that the service ran? If yes, you may want to let your script log to a text file so that you know about any errors or abnormal termination of an executable.

 ~  systemctl start delugedelay                                                            ✔  02:35:46 
 ~  systemctl status delugedelay                                                      ✔  10s  02:36:10 
● delugedelay.service - delugedelay
     Loaded: loaded (/etc/systemd/system/delugedel
ay.service; enabled; preset: disabled)
     Active: active (running) since Mon 2025-01-06 02:35:53 PST; 35s ago
 Invocation: 7cdb423631404e3ca1610ee3e7608f48
   Main PID: 8196 (delugedelay.sh)
      Tasks: 2 (limit: 75538)
     Memory: 728K (peak: 2M)
        CPU: 4ms
     CGroup: /system.slice/delugedelay.service
             ├─8196 /bin/bash /home/cccp/.config/delugedelay.sh
             └─8200 sleep 240

Jan 06 02:35:53 CCCP systemd[1]: delugedelay.service: Scheduled restart job, restart counter is at 3.
Jan 06 02:35:53 CCCP systemd[1]: Started delugedelay.
 ~ 

Make your script output the exit code and stderr of the executable you are trying to run. Or run the executable in a debug/verbose mode.

Make your script output the exit code and stderr of the executable you are trying to run. Or run the executable in a debug/verbose mode.

You are speaking Greek to me.

What is in delugedelay.sh? Can you edit that script to add some echo statements to give more information about whatever it is running?

echo statements? As in maybe deluge.desktop instead of deluge? the .sh file is simply:

#!/bin/bash
sleep 240 && deluge

Edit the file to:

echo "The deluge script has started."
sleep 240 && deluge --loglevel=debug
echo "The deluge script has ended."

Then run

systemctl start delugedelay

systemctl status delugedelay
 ~  sudo systemctl stop delugedelay                                                        ✔  07:12:43 
[sudo] password for cccp: 
 ~  sudo systemctl start delugedelay                                                   ✔  9s  07:13:19 
 ~  sudo systemctl status delugedelay                                                      ✔  07:14:04 
● delugedelay.service - delugedelay
     Loaded: loaded (/etc/systemd/system/delugedelay.service; enabled; preset: disabled)
     Active: active (running) since Mon 2025-01-06 07:14:04 PST; 15s ago
 Invocation: bb2f321703454496be9155c7512b7787
   Main PID: 93067 (delugedelay.sh)
      Tasks: 2 (limit: 75538)
     Memory: 720K (peak: 1.6M)
        CPU: 3ms
     CGroup: /system.slice/delugedelay.service
             ├─93067 /bin/bash /home/cccp/.config/delugedelay.sh
             └─93068 sleep 240

Jan 06 07:14:04 CCCP systemd[1]: Started delugedelay.
Jan 06 07:14:04 CCCP delugedelay.sh[93067]: The deluge script has started.

Any update after 2 minutes?

See my last post there. I appreciate you trying to help, Thanks.

https://www.linux.org/threads/how-to-create-a-custom-systemd-service-file.47399/

Is deluge on autostart? Also, you may want to note the time at which the deluge delay script starts (systemctl status …) and compare it with the current time to see whether the service ran earlier than expected.

You may be on to something, cause I remember yesterday to remove Deluge from Plasma’s Autostart but did not think to go into preferences in deluge itself and untick autostart.

EDIT:

Actually there is no autostart in Deluge just show tray icon and minimize to tray, hence why it had to be added to Plasma’s Autostart.

Hello,

have you found a solution after all this time or is it obsolete?

Are you asking about systemd services or deluge?

A solution to start Deluge with a delay. Therefore my interest, has the problem been solved or is it now obsolete

It is technically possible to launch an executable after some delay like the above service. However I am not aware if deluge independently auto starts before the service can run with a delay.

I was still working on reproducing it last night. But I don’t know all the requirements of the OP, I don’t know about the dependencies, it may be that another service is a startup requirement for Deluge itself. (Sorry for any mistakes or misunderstandings, my English is not made for flawless communication, so I’m looking for support on Google Translate - my German ist better, we can try that :sweat_smile: )

After=deluge.service – Service X starts AFTER Deluge
Wants=deluge.service – Service X wants Deluge to be active

It would not work under certain circumstances:

  • Unfulfilled fundamental dependencies for Deluge

  • Incorrect systemd unit configuration for Deluge:

Missing or incorrect ExecStart: The command to start Deluge (ExecStart=) is incorrect, points to a non-existent executable file or contains incorrect arguments.

Missing [Install] section: If the [Install] section (especially WantedBy=multi-user.target) is missing or incorrect, the service will not be started automatically at boot time after systemctl enable deluge.service.

Incorrect Type=: If the Type= of the service (e.g. simple, forking, notify) does not correctly match the behavior of the Deluge daemon, systemd can misinterpret the status of the service, which leads to start errors or timeouts.