service: kill stubborn services, wait before restart

Add support for registering callbacks to be called after a given
timeout.

Use this to implement forceful termination of services that refuse to
terminate upon receiving a SIGTERM. If the service PID is not collected
within 3 seconds, send a SIGKILL to it.

Also, rework restarting of crashing services. When a service crashes for
the first time, try to restart it immediately. If it crashes again, wait
a few seconds before trying again. Just as before, if it continues to
crash, block the service.
This commit is contained in:
Tobias Waldekranz committed 2016-09-13 20:26:28 +02:00
1 parent b4f385d2e0
commit 10b72f1d7f
5 files changed
+146 -12

No files matched your search

+6
View File
@@ -65,6 +65,7 @@ typedef enum {
SVC_BLOCK_CRASHING,
SVC_BLOCK_USER,
SVC_BLOCK_INETD_BUSY,
SVC_BLOCK_RESTARTING,
} svc_block_t;
#define FINIT_SHM_ID 0x494E4954 /* "INIT", see ascii(7) */
@@ -123,6 +124,11 @@ typedef struct svc {
int dynamic_stop;
int private;
svc_cmd_t (*cb)(struct svc *svc, int event, void *event_arg);
/* Used to forcefully kill services that won't shutdown on
* termination and to delay restarts of crashing services. */
uev_t timer;
void (*timer_cb)(struct svc *svc);
} svc_t;
typedef struct svc_map svc_map_t;