mirror of
https://github.com/troglobit/finit.git
synced 2026-11-03 13:28:27 +00:00
Add service/task name config option
Allows the service/task name derived from the binary to be
overridden with a custom name.
Example:
service name:dhcpd [2] /usr/sbin/udhcpd -f -- DHCP Server
Signed-off-by: Robert Andersson <robert.m.andersson@se.atlascopco.com>
This commit is contained in:
1 parent
33fd6f0049
commit
f2cab53e55
6 files changed
+34
-24
No files matched your search
@@ -185,6 +185,12 @@ Syntax
|
|||||||
For a detailed description of conditions, and how to debug them, see
|
For a detailed description of conditions, and how to debug them, see
|
||||||
the [Finit Conditions](conditions.md) document.
|
the [Finit Conditions](conditions.md) document.
|
||||||
|
|
||||||
|
The name of a service, shown by the `initctl` tool, defaults to the
|
||||||
|
basename of the service executable. It can be changed with the
|
||||||
|
optional `name` argument:
|
||||||
|
|
||||||
|
name:<service-name>
|
||||||
|
|
||||||
* `inetd service/proto[@iflist] <wait|nowait> [LVLS] /path/to/daemon args`
|
* `inetd service/proto[@iflist] <wait|nowait> [LVLS] /path/to/daemon args`
|
||||||
Launch a daemon when a client initiates a connection on an Internet
|
Launch a daemon when a client initiates a connection on an Internet
|
||||||
port. Available services are listed in the UNIX `/etc/services` file.
|
port. Available services are listed in the UNIX `/etc/services` file.
|
||||||
|
|||||||
@@ -226,6 +226,7 @@ static void socket_cb(uev_t *w, void *arg, int events)
|
|||||||
strlcpy(task->desc, svc->desc, sizeof(task->desc) - strlen(conn));
|
strlcpy(task->desc, svc->desc, sizeof(task->desc) - strlen(conn));
|
||||||
strlcat(task->desc, conn, sizeof(task->desc));
|
strlcat(task->desc, conn, sizeof(task->desc));
|
||||||
strlcpy(task->iifname, iifname, sizeof(task->iifname));
|
strlcpy(task->iifname, iifname, sizeof(task->iifname));
|
||||||
|
strlcpy(task->name, svc->name, sizeof(task->name));
|
||||||
|
|
||||||
task->stdin_fd = stdin;
|
task->stdin_fd = stdin;
|
||||||
service_step(task);
|
service_step(task);
|
||||||
|
|||||||
+1
-8
@@ -459,14 +459,7 @@ static int show_status(char *arg)
|
|||||||
|
|
||||||
if (!verbose) {
|
if (!verbose) {
|
||||||
int adj = screen_cols - 60;
|
int adj = screen_cols - 60;
|
||||||
char *name = strrchr(svc->cmd, '/');
|
printf("%-16.16s %-*.*s\n", svc->name, adj, adj, svc->desc);
|
||||||
|
|
||||||
if (!name)
|
|
||||||
name = svc->cmd;
|
|
||||||
else
|
|
||||||
name++;
|
|
||||||
|
|
||||||
printf("%-16.16s %-*.*s\n", name, adj, adj, svc->desc);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -569,6 +569,23 @@ static void parse_log(svc_t *svc, char *arg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* name:<name>
|
||||||
|
*/
|
||||||
|
static void parse_name(svc_t *svc, char *arg)
|
||||||
|
{
|
||||||
|
char *name = NULL;
|
||||||
|
|
||||||
|
if (arg && !strncasecmp(arg, "name:", 5)) {
|
||||||
|
name = arg + 5;
|
||||||
|
} else {
|
||||||
|
name = strrchr(svc->cmd, '/');
|
||||||
|
name = name ? name + 1 : svc->cmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
strlcpy(svc->name, name, sizeof(svc->name));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* parse_cmdline_args - Update the command line args in the svc struct
|
* parse_cmdline_args - Update the command line args in the svc struct
|
||||||
*
|
*
|
||||||
@@ -659,6 +676,7 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
|||||||
char *username = NULL, *log = NULL, *pid = NULL;
|
char *username = NULL, *log = NULL, *pid = NULL;
|
||||||
char *service = NULL, *proto = NULL, *ifaces = NULL;
|
char *service = NULL, *proto = NULL, *ifaces = NULL;
|
||||||
char *cmd, *desc, *runlevels = NULL, *cond = NULL;
|
char *cmd, *desc, *runlevels = NULL, *cond = NULL;
|
||||||
|
char *name = NULL;
|
||||||
svc_t *svc;
|
svc_t *svc;
|
||||||
plugin_t *plugin = NULL;
|
plugin_t *plugin = NULL;
|
||||||
|
|
||||||
@@ -716,6 +734,8 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
|||||||
log = cmd;
|
log = cmd;
|
||||||
else if (!strncasecmp(cmd, "pid", 3))
|
else if (!strncasecmp(cmd, "pid", 3))
|
||||||
pid = cmd;
|
pid = cmd;
|
||||||
|
else if (!strncasecmp(cmd, "name:", 5))
|
||||||
|
name = cmd;
|
||||||
else if (cmd[0] != '/' && strchr(cmd, '/'))
|
else if (cmd[0] != '/' && strchr(cmd, '/'))
|
||||||
service = cmd; /* inetd service/proto */
|
service = cmd; /* inetd service/proto */
|
||||||
else
|
else
|
||||||
@@ -831,6 +851,8 @@ recreate:
|
|||||||
|
|
||||||
conf_parse_cond(svc, cond);
|
conf_parse_cond(svc, cond);
|
||||||
|
|
||||||
|
parse_name(svc, name);
|
||||||
|
|
||||||
if (log)
|
if (log)
|
||||||
parse_log(svc, log);
|
parse_log(svc, log);
|
||||||
if (desc)
|
if (desc)
|
||||||
|
|||||||
@@ -80,7 +80,6 @@ static void svc_gc(void *arg)
|
|||||||
svc_t *svc_new(char *cmd, int id, int type)
|
svc_t *svc_new(char *cmd, int id, int type)
|
||||||
{
|
{
|
||||||
int job = -1;
|
int job = -1;
|
||||||
char *desc;
|
|
||||||
svc_t *svc, *iter = NULL;
|
svc_t *svc, *iter = NULL;
|
||||||
|
|
||||||
/* Find first job n:o if registering multiple instances */
|
/* Find first job n:o if registering multiple instances */
|
||||||
@@ -103,12 +102,7 @@ svc_t *svc_new(char *cmd, int id, int type)
|
|||||||
strlcpy(svc->cmd, cmd, sizeof(svc->cmd));
|
strlcpy(svc->cmd, cmd, sizeof(svc->cmd));
|
||||||
|
|
||||||
/* Default description, if missing */
|
/* Default description, if missing */
|
||||||
desc = strrchr(cmd, '/');
|
strlcpy(svc->desc, svc->name, sizeof(svc->desc));
|
||||||
if (desc)
|
|
||||||
desc++;
|
|
||||||
else
|
|
||||||
desc = cmd;
|
|
||||||
strlcpy(svc->desc, desc, sizeof(svc->desc));
|
|
||||||
|
|
||||||
TAILQ_INSERT_TAIL(&svc_list, svc, link);
|
TAILQ_INSERT_TAIL(&svc_list, svc, link);
|
||||||
|
|
||||||
@@ -204,7 +198,7 @@ svc_t *svc_named_iterator(svc_t **iter, int first, char *cmd)
|
|||||||
svc_t *svc;
|
svc_t *svc;
|
||||||
|
|
||||||
for (svc = svc_iterator(iter, first); svc; svc = svc_iterator(iter, 0)) {
|
for (svc = svc_iterator(iter, first); svc; svc = svc_iterator(iter, 0)) {
|
||||||
char *name = basename(svc->cmd);
|
char *name = svc->name;
|
||||||
|
|
||||||
if (!strncmp(name, cmd, strlen(name)))
|
if (!strncmp(name, cmd, strlen(name)))
|
||||||
return svc;
|
return svc;
|
||||||
@@ -362,17 +356,10 @@ svc_t *svc_find_by_jobid(int job, int id)
|
|||||||
*/
|
*/
|
||||||
svc_t *svc_find_by_nameid(char *name, int id)
|
svc_t *svc_find_by_nameid(char *name, int id)
|
||||||
{
|
{
|
||||||
char *ptr;
|
|
||||||
svc_t *svc, *iter = NULL;
|
svc_t *svc, *iter = NULL;
|
||||||
|
|
||||||
for (svc = svc_iterator(&iter, 1); svc; svc = svc_iterator(&iter, 0)) {
|
for (svc = svc_iterator(&iter, 1); svc; svc = svc_iterator(&iter, 0)) {
|
||||||
ptr = strrchr(svc->cmd, '/');
|
if (svc->id == id && !strcmp(name, svc->name))
|
||||||
if (ptr)
|
|
||||||
ptr++;
|
|
||||||
else
|
|
||||||
ptr = svc->cmd;
|
|
||||||
|
|
||||||
if (svc->id == id && !strcmp(name, ptr))
|
|
||||||
return svc;
|
return svc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ typedef struct svc {
|
|||||||
int sighup; /* This service supports SIGHUP :) */
|
int sighup; /* This service supports SIGHUP :) */
|
||||||
svc_block_t block; /* Reason that this service is currently stopped */
|
svc_block_t block; /* Reason that this service is currently stopped */
|
||||||
char cond[MAX_COND_LEN];
|
char cond[MAX_COND_LEN];
|
||||||
|
char name[MAX_ARG_LEN];
|
||||||
|
|
||||||
/* Counters */
|
/* Counters */
|
||||||
char once; /* run/task, (at least) once per runlevel */
|
char once; /* run/task, (at least) once per runlevel */
|
||||||
|
|||||||
Reference in new issue
Block a user