mirror of
https://github.com/troglobit/finit.git
synced 2026-11-02 13:20:32 +00:00
Add two new hook points: HOOK_SVC_RECONF and HOOK_RUNLEVEL_CHANGE.
These two new hooks run when SIGHUP is received and when changing system runlevel. The hooks are called when all services have been stopped, just before starting up new/modified services. Making it the perfect hook for reconfiguring the system/hardware before new services or modified services are started up again. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
e83f4ab4bf
commit
f5584ecc3c
3 files changed
+59
-8
No files matched your search
@@ -435,6 +435,8 @@ hook point in the boot process, useful to insert some pre-bootstrap
|
|||||||
mechanisms, like generating configuration files, restoring HW device
|
mechanisms, like generating configuration files, restoring HW device
|
||||||
state, etc. Available hook points are:
|
state, etc. Available hook points are:
|
||||||
|
|
||||||
|
**Bootstrap Hooks**
|
||||||
|
|
||||||
* `HOOK_ROOTFS_UP`: When `finit.conf` has been read and `/` has is
|
* `HOOK_ROOTFS_UP`: When `finit.conf` has been read and `/` has is
|
||||||
mounted -- very early
|
mounted -- very early
|
||||||
|
|
||||||
@@ -449,6 +451,20 @@ state, etc. Available hook points are:
|
|||||||
* `HOOK_SYSTEM_UP`: All services *and* everything in `/etc/finit.d`
|
* `HOOK_SYSTEM_UP`: All services *and* everything in `/etc/finit.d`
|
||||||
has been launched
|
has been launched
|
||||||
|
|
||||||
|
**Runtime Hooks**
|
||||||
|
|
||||||
|
* `HOOK_SVC_RECONF`: Called when the user has changed something in the
|
||||||
|
`/etc/finit.d` directory and issued `SIGHUP`. The hook is called when
|
||||||
|
all modified/removed services have been stopped. When the hook has
|
||||||
|
completed, Finit continues to start all modified and new services.
|
||||||
|
|
||||||
|
* `HOOK_RUNLEVEL_CHANGE`: Called when the user has issued a runlevel
|
||||||
|
change. The hook is called when services not matching the new
|
||||||
|
runlevel have been been stopped. When the hook has completed, Finit
|
||||||
|
continues to start all services in the new runlevel.
|
||||||
|
|
||||||
|
**Shutdown Hooks**
|
||||||
|
|
||||||
* `HOOK_SHUTDOWN`: Called at shutdown/reboot, right before all
|
* `HOOK_SHUTDOWN`: Called at shutdown/reboot, right before all
|
||||||
services are sent `SIGTERM`
|
services are sent `SIGTERM`
|
||||||
|
|
||||||
|
|||||||
@@ -41,11 +41,18 @@
|
|||||||
* Predefined hook points for easier plugin debugging
|
* Predefined hook points for easier plugin debugging
|
||||||
*/
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
/* Bootstrap hooks */
|
||||||
HOOK_ROOTFS_UP = 0,
|
HOOK_ROOTFS_UP = 0,
|
||||||
HOOK_BASEFS_UP,
|
HOOK_BASEFS_UP,
|
||||||
HOOK_NETWORK_UP,
|
HOOK_NETWORK_UP,
|
||||||
HOOK_SYSTEM_UP,
|
|
||||||
HOOK_SVC_UP,
|
HOOK_SVC_UP,
|
||||||
|
HOOK_SYSTEM_UP,
|
||||||
|
|
||||||
|
/* Runtime hooks */
|
||||||
|
HOOK_SVC_RECONF,
|
||||||
|
HOOK_RUNLEVEL_CHANGE,
|
||||||
|
|
||||||
|
/* Shutdown hooks */
|
||||||
HOOK_SHUTDOWN,
|
HOOK_SHUTDOWN,
|
||||||
HOOK_MAX_NUM
|
HOOK_MAX_NUM
|
||||||
} hook_point_t;
|
} hook_point_t;
|
||||||
|
|||||||
@@ -286,17 +286,32 @@ void svc_runlevel(int newlevel)
|
|||||||
|
|
||||||
prevlevel = runlevel;
|
prevlevel = runlevel;
|
||||||
runlevel = newlevel;
|
runlevel = newlevel;
|
||||||
utmp_save(prevlevel, newlevel);
|
|
||||||
|
|
||||||
_d("Setting new runlevel --> %d <-- previous %d", runlevel, prevlevel);
|
_d("Setting new runlevel --> %d <-- previous %d", runlevel, prevlevel);
|
||||||
|
utmp_save(prevlevel, newlevel);
|
||||||
|
|
||||||
|
_d("Stopping services services not allowed in new runlevel ...");
|
||||||
for (svc = svc_iterator(1); svc; svc = svc_iterator(0)) {
|
for (svc = svc_iterator(1); svc; svc = svc_iterator(0)) {
|
||||||
/* Inetd services have slightly different semantics */
|
if (!ISSET(svc->runlevels, runlevel)) {
|
||||||
#ifndef INETD_DISABLED
|
#ifndef INETD_DISABLED
|
||||||
if (svc->type == SVC_TYPE_INETD) {
|
if (svc->type == SVC_TYPE_INETD)
|
||||||
if (!ISSET(svc->runlevels, runlevel))
|
|
||||||
inetd_stop(&svc->inetd);
|
inetd_stop(&svc->inetd);
|
||||||
else
|
else
|
||||||
|
#endif
|
||||||
|
svc_stop(svc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Prev runlevel services stopped, call hooks before starting new runlevel ... */
|
||||||
|
_d("All services have been stoppped, calling runlevel change hooks ...");
|
||||||
|
plugin_run_hooks(HOOK_RUNLEVEL_CHANGE); /* Reconfigure HW/VLANs/etc here */
|
||||||
|
|
||||||
|
_d("Starting services services new to this runlevel ...");
|
||||||
|
for (svc = svc_iterator(1); svc; svc = svc_iterator(0)) {
|
||||||
|
#ifndef INETD_DISABLED
|
||||||
|
/* Inetd services have slightly different semantics */
|
||||||
|
if (svc->type == SVC_TYPE_INETD) {
|
||||||
|
if (ISSET(svc->runlevels, runlevel))
|
||||||
inetd_start(&svc->inetd);
|
inetd_start(&svc->inetd);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
@@ -901,13 +916,26 @@ int svc_reload(svc_t *svc)
|
|||||||
*/
|
*/
|
||||||
void svc_reload_dynamic(void)
|
void svc_reload_dynamic(void)
|
||||||
{
|
{
|
||||||
|
int num = 0;
|
||||||
svc_t *svc;
|
svc_t *svc;
|
||||||
|
|
||||||
_d("Checking if any dynamically loaded services need to be reloaded ...");
|
_d("Stopping disabled/removed services ...");
|
||||||
|
for (svc = svc_iterator(1); svc; svc = svc_iterator(0)) {
|
||||||
|
if (svc->mtime && svc->dirty != 0) {
|
||||||
|
svc_stop(svc);
|
||||||
|
num++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!num)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_d("All disabled/removed services have been stoppped, calling reconf hooks ...");
|
||||||
|
plugin_run_hooks(HOOK_SVC_RECONF); /* Reconfigure HW/VLANs/etc here */
|
||||||
|
|
||||||
|
_d("Starting enabled/added services ...");
|
||||||
for (svc = svc_iterator(1); svc; svc = svc_iterator(0)) {
|
for (svc = svc_iterator(1); svc; svc = svc_iterator(0)) {
|
||||||
if (svc->mtime && svc->dirty > 0) {
|
if (svc->mtime && svc->dirty > 0) {
|
||||||
_d("Service %s id %d modified, must stop-start for changes to take effect!", svc->cmd, svc->id);
|
|
||||||
svc_stop(svc); /* This will reset the restart_counter as well! */
|
|
||||||
svc_dance(svc);
|
svc_dance(svc);
|
||||||
svc->dirty = 0;
|
svc->dirty = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user