Why startup timeout for service in systemd has no effect on it.

mkatlinuxorg

New Member
Joined
Jan 23, 2023
Messages
3
Reaction score
0
Credits
39
I test service which fails after 90 sec. Seems using default value. Now. I tested with setup TimeoutStartSec = to longer or shorter time in seconds and stop/start service. But it doesn't take effect after daemon reload or even reboot.
What do I wrong?
 


What are you expecting this to do?
TimeoutStartSec

This doesn't force the service to wait for a specified time before it starts.
This is how long the service can take to startup before it times out.

Very few services will take 90 seconds to start up.

If you're wanting a delay, before a service starts, there are at least two ways to do this.

Code:
[Service]
ExecStartPre=/bin/sleep 10
ExecStart=/path/to/your/service

or the other way is a little more complicated.

systemd-time-wait-sync.service:

Follow these steps: This is for Debian/Ubuntu, but Redhat/Fedora is similar.
Just use dnf/rpm instead of apt/dpkg.

Remove chrony if installed: dpkg -l | grep -q "ii *chrony" && apt remove chrony
Enable systemd-timesyncd.service: systemctl enable --now systemd-timesyncd.service
Enable systemd-time-wait-sync.service: systemctl enable --now systemd-time-wait-sync.service
Edit your service unit file (e.g., watchdog.service or nfs-server.service) and add the following lines

Code:
:[Unit]
After=time-sync.target
Wants=time-sync.target

This will make sure that your services start only after the system time has been updated.
 
What are you expecting this to do?
TimeoutStartSec

This doesn't force the service to wait for a specified time before it starts.
This is how long the service can take to startup before it times out.

Very few services will take 90 seconds to start up.

If you're wanting a delay, before a service starts, there are at least two ways to do this.

Code:
[Service]
ExecStartPre=/bin/sleep 10
ExecStart=/path/to/your/service

or the other way is a little more complicated.

systemd-time-wait-sync.service:

Follow these steps: This is for Debian/Ubuntu, but Redhat/Fedora is similar.
Just use dnf/rpm instead of apt/dpkg.

Remove chrony if installed: dpkg -l | grep -q "ii *chrony" && apt remove chrony
Enable systemd-timesyncd.service: systemctl enable --now systemd-timesyncd.service
Enable systemd-time-wait-sync.service: systemctl enable --now systemd-time-wait-sync.service
Edit your service unit file (e.g., watchdog.service or nfs-server.service) and add the following lines

Code:
:[Unit]
After=time-sync.target
Wants=time-sync.target

This will make sure that your services start only after the system time has been updated.
Hi.
Thanks for quite a valuable answer to clarify and help in the future the startup topic more.

However here my question is more simple but maybe not precisely asked:
What i need is to preserve the service to get out with timeout failure if time from start passes 90 secs.(Actually it will not if other service that needs a bit more time will run and send to initial service data that will the initial one finish to start).
So indeed as i understand above parametr which should extend the timeout. When I set start timeout for particular service in its own config it should overwrite default 90s.
But when i set it lat say 180. Then stop and start service, the service reports failure after 90 anyway (timeouts)...but why? I want to push it to wait longer before it reaches the new longer timeout. But it doesn't work for me.
 
That's because the service failed before the 180 seconds were up.
It always reports a service failure, no matter what you set the time out to.
The only thing that changes, is how it will quit trying to restart.

Let's say a service takes 30 seconds to start up.
Let's say you have the startup time out set to 90 seconds.

It's possible that service might try to restart 3 or 4 times in that 90 seconds.
What if the last restart try is 85 seconds after start-up.
(That's still within your 90 second window) however the service takes 30 seconds to start,
so 85 seconds to start trying, 30 seconds to complete trying would be 115 seconds.
Now it reports to you as failed, because the timeout limit was reached.

But I don't understand why this is important.
If you want to be notified a service didn't start (this is the default behavior)
Then don't change anything.

If you don't want to be notified.
You can redirect StandardOutput and StandardError in your service file to /dev/null

Usually, you want to be notified if a service doesn't start.
If you don't care if it starts or not, then why bother?
But even if it notifies you a service didn't start, so what, unless there is a dependency.
on that service for another service to start up. It doesn't hurt anything.
 


Latest posts

Top