I want to execute a script on startup. The script is recursive and calls itself.
When I added systemd unit for the same, it is executing but getting stopped in 1 min due to DefaultTimeoutStartSec. It assumes that my script has not yet started.

Following is the service file I have created

    Description = My Desc
    After = network.target

    Type = forking
    ExecStart = /root/my_recursive_script.sh

    WantedBy = multi-user.target

I know I can make this service as working by adding TimeoutSec to infinity but that would be workaround. When I execute my service with

    systemctl start myservice.service 

it does not leave the cursor until timeout encounter.

  1. What is the proper way to make systemd units work with recursive script?
  2. Do I need to make changes in my script to make it executable like daemon?

The issue is you have set the service type to forking. Systemd is waiting for you ExecStart to fork to background before proceeding. You need to change the type to simple. See the manual

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.