* New process-control RPC feature in clixon-lib.yang to manage processes

* This is an alternative to manage a clixon daemon via sudtemd, containerd or other
  * One important special case is starting the clixon-restconf daemon internally
  * This is how it works:
    * Register a process via `clixon_process_register(h, name, namespace, argv, argc)`
    * Use process-control RPC defined in clixon-lib.yang to start/stop/restart or query status on that process
  * Example code in the main example
This commit is contained in:
Olof hagsand 2020-12-15 14:43:01 +01:00
parent 8540820698
commit 22adc58187
19 changed files with 971 additions and 47 deletions

View file

@ -66,7 +66,7 @@
#include <clixon/clixon_backend.h>
/* Command line options to be passed to getopt(3) */
#define BACKEND_EXAMPLE_OPTS "rsS:iuUt:v:"
#define BACKEND_EXAMPLE_OPTS "rsS:iuUt:v:n:"
/*! Variable to control if reset code is run.
* The reset code inserts "extra XML" which assumes ietf-interfaces is
@ -119,6 +119,11 @@ static int _transaction_log = 0;
static char *_validate_fail_xpath = NULL;
static int _validate_fail_toggle = 0; /* fail at validate and commit */
/* -n <ns>
* Network namespace for starting restconf process in another namespace
*/
static char *_proc_netns = NULL;
/* forward */
static int example_stream_timer_setup(clicon_handle h);
@ -1079,6 +1084,9 @@ clixon_plugin_init(clicon_handle h)
case 'v': /* validate fail */
_validate_fail_xpath = optarg;
break;
case 'n': /* process restconf namespace*/
_proc_netns = optarg;
break;
}
/* Example stream initialization:
@ -1142,7 +1150,36 @@ clixon_plugin_init(clicon_handle h)
else
if (upgrade_callback_register(h, xml_changelog_upgrade, NULL, NULL) < 0)
goto done;
{
char **argv = NULL;
int i;
int nr;
char dbgstr[8];
char wwwstr[64];
nr = 4;
if (clicon_debug_get() != 0)
nr += 2;
if ((argv = calloc(nr, sizeof(char *))) == NULL){
clicon_err(OE_UNIX, errno, "calloc");
goto done;
}
i = 0;
snprintf(wwwstr, sizeof(wwwstr)-1, "%s/clixon_restconf", clicon_option_str(h, "CLICON_WWWDIR"));
argv[i++] = wwwstr;
argv[i++] = "-f";
argv[i++] = clicon_option_str(h, "CLICON_CONFIGFILE");
if (clicon_debug_get() != 0){
argv[i++] = "-D";
snprintf(dbgstr, sizeof(dbgstr)-1, "%d", clicon_debug_get());
argv[i++] = dbgstr;
}
argv[i++] = NULL;
if (clixon_process_register(h, "restconf", _proc_netns, argv, nr) < 0)
goto done;
if (argv != NULL)
free(argv);
}
/* Return plugin API */
return &api;
done: