Gunnar is following up on the init script blog posts by Erich and me. First a note to Gunnar: The idea of the init scrip snippets isn’t exactly my own idea, but rather taken from a comment to one of Erich’s posts (IIRC), I don’t know the original author anymore.
Anyway, I really think that some init script generator should work. It should even be possible to fetch variables from /etc/default/<daemon-name> if needed. I’m just doing a braindump of what I have in mind for the start and stop of a daemon. I would expect a configuration file (currently I think one for each operation might be best, but INI-lookalike files might also be OK). So for the start operation, I would expect these options:
- simple daemon, uses a default config with a hardcoded path and needs no options or only static options passed:
[SIMPLE] /path/to/daemon option 1 option 2 option 3
Where I chose to name one option per line so whitespace and controll characters can be part of the options without the need to quote anything.
- a bit more complicated, needs a few variables from /etc/default/daemon:
[TEMPLATED] /path/to/daemon option 1 %PARAMETER_FROM_ETC_DEFAULT% --parameter=%ANOTHER_ONE_FROM_ETC_DEFAULT%
Where the script generator would have to make sure that the parameters from /etc/default are filled in at runtime. I would expect POSIX-Shell-Scripts in /etc/default for this.
- Really complex: A custom script snippet is needed which has to do some specificc tasks, like cleaning possible stable locks which had been left behind.
[SCRIPT] rm /var/lock/daemon.lck /path/to/daemon --background --and --other --options
Where the script generator would simply take this script and use it where it would otherwise generate its own code.
As for stopping, I generally see only three options for the sysv-like background processes: Either a script is needed (see above for how that would look like) or a process needs to be killed according to a PID-file or the process name (with the later being rather bad). So this would result in:
- [SCRIPT] like for starting the daemon
- killing by PID-file:
- killing by process name/executable:
where the generator would either only look at the name of the process (first version, no full pathname) or for a process with the given executable (from /proc/
/exec, I would expect).
Alright, this would leave the cases of running (instead of backgrounding) the server and stopping such a running server (the later should be fairly simple unless the stopping of the server requires additional actions other than simply killing it) as well as the reload/restart/status stuff. But these should also be relatively simple actually.
What would be interesting for me:
Does any init system require information that is not part of the following list? I would plan with supplying information how to:
- start server in background
- start server in foreground (without the need for a terminal)
- determine wether a server runs (status)
- determine wether a server is ready to serve requests (also part of status)
- determine wether the server is installed (and able to be started)
- stop a background server
- stop a foreground server (unless specified, a simple SIGKILL to the process is assumed)
- restart foreground server (unless specified, a simple stop-start cycle is assumed)
- restart background server (unless specified, a simple stop-start cycle is assumed)
- reload config (unless specified, it is assumed that reloading doesn’t work and a restart is needed)
- reopen logs (unless specified, the “reload config” operation is assumed to do this)
- some meta information: short description, needs writeable filesystem(s) mounted, needs a certain daemon to be running already (or even: able to serve requests), enhances other daemon X and should be started before it (don’t care if X isn’t installed/configured), is enhanced by daemon Y and should be started after it (don’t care if Y isn’t installed/configured), replaces daemon Z, should only run once at startup, …
Finally, even with all that information available inside a Debian package, this would still leave one question unanswered: Who triggers init script generation? If a daemon package does so in postinst: How do I switch to a different init system? If the init system does it in postinst: What happens to additional daemons installed later on? If they get regenerated during system start: How much penalty does that cause? Currently I think the route to go is to provide a command to daemon packages’ postinst that (re)generates only the needed scripts for that package and have a command used in an init system’s postinst which regenerates all of them. That should do. Regenerating during boot would most likely take too much time and has other problems, too, like the availability of a writeable filesystem to store the generated scripts.
Alright, if someone would like to see this post (or rather parts of it) on the Wiki page about an Init HackFest, please transfer it there yourself. I’m currently not able to log in, for whatever reason.