I have written a systemd service.
When I run systemctl start foo.service
, the service starts and runs correctly, but systemctl
does not return immediately to the shell.
After a while it exits with
Job for foo.service failed because a timeout was exceeded.
and then the service is no longer running.
Here is foo.service, I RTFM and used Type=forking
with a command which forks:
[Unit]
Description=blah blah
[Service]
Type=forking
PIDFile=/var/run/myservice.pid
ExecStart=/my/path/fork my-script my-args
[Install]
WantedBy=multi-user.target
my-script
does not itself fork, so /my/path/fork
is as follows
#!/bin/bash
PATH="$PATH:/my/path" "$@" &
Why does this service not fork and run in the background as expected? I have done everything as root on CentOS.
Service Type=forking is for truly forking programs (apache for example). Your bash script only run another script on background. This is not exactly what systemd wants as forking program. Why you using
, when your script my-script is normal simple service?
Try to change service type and run your script directly with this:
And remove whole /my/path/fork file. I can't see any profit from it.
Also you can try to set TimeoutStartSec=1 option to service configuration file.
I'm using bash script containing infinite loop with this configuration: