53 lines
1.9 KiB
Text
53 lines
1.9 KiB
Text
|
cinit - Respawning and sleeping
|
||
|
===============================
|
||
|
Nico Schottelius <nico-cinit__@__schottelius.org>
|
||
|
0.1, for cinit 0.3, Initial Version from 2007-04-13
|
||
|
:Author Initials: NS
|
||
|
|
||
|
|
||
|
How cinit sleeps, before a service is respawned.
|
||
|
|
||
|
Introduction
|
||
|
------------
|
||
|
When a service, that is configured to be respawning, exits cinit restarts it.
|
||
|
Because services may be broken and thus cinit would try to restart it many
|
||
|
times in a second, it is necessary to sleep between restarts.
|
||
|
|
||
|
The big question: How to sleep?
|
||
|
------------------------------------
|
||
|
The first possibility is to sleep a fixed amount of time between restarts:
|
||
|
For instance one second. This is not a good solution, because this waits
|
||
|
one unecessary second if the process just crashed. It may be too less, if
|
||
|
the service is really broken.
|
||
|
|
||
|
The second possibility is to sleep a dynamic amount of time.
|
||
|
|
||
|
|
||
|
The next big question: How long to sleep?
|
||
|
-----------------------------------------
|
||
|
I think that as long as a service is broken we should not investigate to much
|
||
|
time into restarting it. So we can define a maximum amount of time to sleep
|
||
|
(for instance 30 seconds). The minimum amount of time to sleep is zero seconds.
|
||
|
|
||
|
When the service is first started, the sleep time defaults to the minimum
|
||
|
amount of time. Each time the service is restarted, the sleep time is adjusted:
|
||
|
|
||
|
sleep time (st) = Maximum sleep time (mst) / Time the process was running (tr)
|
||
|
|
||
|
- If tr is < 1 it is adjusted to 1 and thus st is set to mst.
|
||
|
- If tr is > mst, st is set to 0.
|
||
|
|
||
|
|
||
|
How to force restart of a service?
|
||
|
----------------------------------
|
||
|
Use cvsc (to be implemented).
|
||
|
|
||
|
|
||
|
Hom is it implemented?
|
||
|
----------------------
|
||
|
Everytime cinit has to respawn a service it has to fork() itself.
|
||
|
The sleep call is implemented in the fork, so cinit itself does not have
|
||
|
to care about it. After the sleep time is over or the fork() recieves
|
||
|
SIGALARM it executes the real service. cinit itself records as start time
|
||
|
the current time plus sleep time.
|