Major change, rename <svc/...> conditions to <pid/...> conditions

The <svc/foo> condition was created to synchronize starting services,
hence the abbreviation.  Example: the Quagga ripd needs to start after
the zebra daemon to ensure its UNIX domain socket is active, otherwise
events may be lost.

However, considering that synchronization was implemented with UNIX PID
files, e.g. waiting for /var/run/quagga/zebra.pid to be created, the
condition abbreviation name <svc/foo> was hard to understand by most
newcomers to Finit.  To make matters worse, a new feature to track or
even create PID files for services that don't create one themselves,
using the syntax 'pid:/path/to/foo.pid' was added.

Connecting the dots between these wasn't obvious.

This patch renames service conditions pid conditions and also adds
a compatibility wrapper to the Finit .conf parser.  Any condition
given in old .conf files with 'svc/' prefix are internally renamed
'pid/', along with a LOG_INFO notice in syslog.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2021-02-09 22:07:03 +01:00
parent ff41868b59
commit a8b113185d
15 changed files with 43 additions and 36 deletions
+14 -11
View File
@@ -32,28 +32,31 @@
#include "service.h"
/*
* The service condition name is constructed from the 'svc/' prefix, the
* dirname of the svc->cmd, e.g., '/usr/bin/teamd' => 'usr/bin', and the
* service's pid:filename, including an optional subdirectory, without
* the .pid extension.
* The service condition name is constructed from the 'pid/' prefix,
* the dirname of the svc->cmd, e.g., '/usr/bin/teamd' => 'usr/bin', and
* the service's pid:filename, including an optional subdirectory,
* without the .pid extension.
*
* The following example uses the team (aggregate) service:
*
* service pid:!/run/teamd/a1.pid /usr/bin/teamd -f /etc/teamd/a1.conf
*
* => 'svc/' + 'usr/bin' + 'teamd/a1' => svc/usr/bin/teamd/a1
* => 'pid/' + 'usr/bin' + 'teamd/a1' => pid/usr/bin/teamd/a1
*
* The next example uses the dbus-daemon:
*
* service pid:!/run/dbus/pid /usr/bin/dbus-daemon
*
* => 'svc/' + 'usr/bin' + 'dbus' => svc/usr/bin/dbus
* => 'pid/' + 'usr/bin' + 'dbus' => pid/usr/bin/dbus
*
* The last example uses lxc-start to start container foo:
*
* service pid:!/run/lxc/foo.pid lxc-start -n foo -F -p /run/lxc/foo.pid -- Container foo
*
* => 'svc/' + '' + 'lxc/foo' => svc/lxc/foo
* => 'pid/' + '' + 'lxc/foo' => pid/lxc/foo
*
* Note: previously the condition ws called 'svc/..', the conf.c parser
* automatically translates to the 'pid/..' prefix and warns.
*/
char *mkcond(svc_t *svc, char *buf, size_t len)
{
@@ -81,12 +84,12 @@ char *mkcond(svc_t *svc, char *buf, size_t len)
else
ptr = rindex(pidfile, '/');
/* Custom name:foo declaration found => svc/foo instead of /svc/bin/path/pidfile-.pid */
/* Custom name:foo declaration found => pid/foo instead of /pid/bin/path/pidfile-.pid */
if (strcmp(nm, svc->name)) {
snprintf(buf, len, "svc/%s", svc->name);
snprintf(buf, len, "pid/%s", svc->name);
_d("Composed condition from svc->name %s => %s", svc->name, buf);
} else {
snprintf(buf, len, "svc%s%s%s", path[0] != 0 && path[0] != '/' ? "/" : "", path, ptr);
snprintf(buf, len, "pid%s%s%s", path[0] != 0 && path[0] != '/' ? "/" : "", path, ptr);
_d("Composed condition from cmd %s (path %s) and pidfile %s => %s", svc->cmd, path, ptr, buf);
}
@@ -306,7 +309,7 @@ static int reassert(const char *fpath, const struct stat *sb, int tflg, struct F
/*
* Used only by netlink plugin atm.
* type: is a one of svc/, net/, etc.
* type: is a one of pid/, net/, etc.
*/
void cond_reassert(const char *type)
{
+5 -1
View File
@@ -236,7 +236,11 @@ void conf_parse_cond(svc_t *svc, char *cond)
return;
}
strlcpy(svc->cond, ptr, sizeof(svc->cond));
if (!strncmp(ptr, "svc/", 4)) {
snprintf(svc->cond, sizeof(svc->cond), "pid/%s", &ptr[4]);
logit(LOG_INFO, "Migrating cond syntax of %s: %s -> %s", svc->cmd, ptr, svc->cond);
} else
strlcpy(svc->cond, ptr, sizeof(svc->cond));
}
struct rlimit_name {
+1 -1
View File
@@ -825,7 +825,7 @@ static void parse_cmdline_args(svc_t *svc, char *cmd)
* special case when a service is declared with <!> means it does not
* support SIGHUP but must be STOP/START'ed at system reconfiguration.
*
* Service conditions can be: svc/<PATH> for PID files, net/<IFNAME>/up
* Service conditions can be: pid/<PATH> for PID files, net/<IFNAME>/up
* and net/<IFNAME>/exists. The condition handling is further described
* in doc/conditions.md, but worth mentioning here is that the condition
* name itself can be modified using the :ID and name:foo syntax.