* Added CLICON_BACKEND_RESTCONF_PROCESS to clixon-config.yang
This commit is contained in:
parent
4fe3486d4e
commit
b8f5d1dcae
8 changed files with 83 additions and 46 deletions
|
|
@ -35,7 +35,7 @@
|
|||
* 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
|
||||
* Enable in backend for restconf using `CLICON_BACKEND_RESTCONF_PROCESS`.
|
||||
* More YANG extension functionality,
|
||||
* See [Augment auto-cli for hiding/modifying cli syntax #156](https://github.com/clicon/clixon/issues/156) and [hiding auto-generated CLI entries #153](https://github.com/clicon/clixon/issues/153)
|
||||
* Extensions can be used in augmentations
|
||||
|
|
@ -57,7 +57,8 @@ Users may have to change how they access the system
|
|||
* Added: autocli-op extension (see new features)
|
||||
* Added: rpc process-control for process/daemon management
|
||||
* New clixon-config@2020-11-03.yang revision
|
||||
* Moved to clixon-restconf.yang and marked as obsolete:
|
||||
* Added CLICON_BACKEND_RESTCONF_PROCESS
|
||||
* Copied to clixon-restconf.yang and marked as obsolete:
|
||||
- CLICON_RESTCONF_IPV4_ADDR
|
||||
- CLICON_RESTCONF_IPV6_ADDR
|
||||
- CLICON_RESTCONF_HTTP_PORT
|
||||
|
|
|
|||
|
|
@ -178,6 +178,50 @@ backend_server_socket(clicon_handle h)
|
|||
return ss;
|
||||
}
|
||||
|
||||
/*! Enable process-control of restconf daemon, ie start/stop restconf
|
||||
* @param[in] h Clicon handle
|
||||
* @note Could also look in clixon-restconf and start process if enable is true, but that needs to
|
||||
* be in start callback using a pseudo plugin.
|
||||
*/
|
||||
static int
|
||||
backend_restconf_process_control(clicon_handle h)
|
||||
{
|
||||
int retval = -1;
|
||||
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",
|
||||
NULL /* XXX network namespace */,
|
||||
argv, nr) < 0)
|
||||
goto done;
|
||||
if (argv != NULL)
|
||||
free(argv);
|
||||
retval = 0;
|
||||
done:
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*! Load external NACM file
|
||||
*/
|
||||
static int
|
||||
|
|
@ -745,6 +789,12 @@ main(int argc,
|
|||
clicon_option_str(h, "CLICON_BACKEND_REGEXP")) < 0)
|
||||
goto done;
|
||||
|
||||
/* Enable process-control of restconf daemon, ie start/stop restconf */
|
||||
if (clicon_option_bool(h, "CLICON_BACKEND_RESTCONF_PROCESS")){
|
||||
if (backend_restconf_process_control(h) < 0)
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Load Yang modules
|
||||
* 1. Load a yang module as a specific absolute filename */
|
||||
if ((str = clicon_yang_main_file(h)) != NULL)
|
||||
|
|
|
|||
|
|
@ -1153,36 +1153,6 @@ 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:
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ int xmldb_clear(clicon_handle h, const char *db);
|
|||
int xmldb_delete(clicon_handle h, const char *db);
|
||||
int xmldb_create(clicon_handle h, const char *db);
|
||||
/* utility functions */
|
||||
int xmldb_db_reset(clicon_handle h, char *db);
|
||||
int xmldb_db_reset(clicon_handle h, const char *db);
|
||||
|
||||
cxobj *xmldb_cache_get(clicon_handle h, const char *db);
|
||||
|
||||
|
|
|
|||
|
|
@ -466,7 +466,7 @@ xmldb_create(clicon_handle h,
|
|||
*/
|
||||
int
|
||||
xmldb_db_reset(clicon_handle h,
|
||||
char *db)
|
||||
const char *db)
|
||||
{
|
||||
if (xmldb_exists(h, db) == 1){
|
||||
if (xmldb_delete(h, db) != 0 && errno != ENOENT)
|
||||
|
|
|
|||
|
|
@ -100,22 +100,24 @@ EOF
|
|||
fi
|
||||
new "start backend -s $db -f $cfg"
|
||||
start_backend -s $db -f $cfg
|
||||
|
||||
new "wait backend"
|
||||
wait_backend
|
||||
else
|
||||
new "Restart backend as eg follows: -Ff $cfg -s $db"
|
||||
sleep 2
|
||||
fi
|
||||
|
||||
new "waiting"
|
||||
wait_backend
|
||||
|
||||
new "kill old restconf daemon"
|
||||
stop_restconf_pre
|
||||
if [ $RC -ne 0 ]; then # Bring your own restconf
|
||||
new "kill old restconf daemon"
|
||||
stop_restconf_pre
|
||||
|
||||
new "start restconf daemon (-a is enable basic authentication)"
|
||||
start_restconf -f $cfg -- -a
|
||||
new "start restconf daemon (-a is enable basic authentication)"
|
||||
start_restconf -f $cfg -- -a
|
||||
|
||||
new "waiting"
|
||||
wait_restconf
|
||||
new "wait restconf"
|
||||
wait_restconf
|
||||
fi
|
||||
|
||||
# Use POST (instead of startup)
|
||||
# Note this only works because CLICON_NACM_DISABLED_ON_EMPTY is true
|
||||
|
|
@ -176,8 +178,10 @@ EOF
|
|||
new "get 99"
|
||||
expectpart "$(curl -u guest:bar $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/nacm-example:x)" 0 "$status" "$ret"
|
||||
|
||||
new "Kill restconf daemon"
|
||||
stop_restconf
|
||||
if [ $RC -ne 0 ]; then # Bring your own restconf
|
||||
new "Kill restconf daemon"
|
||||
stop_restconf
|
||||
fi
|
||||
|
||||
if [ $BE -ne 0 ]; then # Bring your own backend
|
||||
new "Kill backend"
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ cat <<EOF > $cfg
|
|||
<CLICON_BACKEND_PIDFILE>/usr/local/var/$APPNAME/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
|
||||
<CLICON_XMLDB_DIR>/usr/local/var/$APPNAME</CLICON_XMLDB_DIR>
|
||||
<CLICON_MODULE_LIBRARY_RFC7895>true</CLICON_MODULE_LIBRARY_RFC7895>
|
||||
<!-- start restconf from backend -->
|
||||
<CLICON_BACKEND_RESTCONF_PROCESS>true</CLICON_BACKEND_RESTCONF_PROCESS>
|
||||
$RESTCONFIG
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
|
|
|||
|
|
@ -45,7 +45,8 @@ module clixon-config {
|
|||
|
||||
revision 2020-11-03 {
|
||||
description
|
||||
"Moved to clixon-restconf.yang and marked as obsolete:
|
||||
"Added CLICON_BACKEND_RESTCONF_PROCESS
|
||||
Copied to clixon-restconf.yang and marked as obsolete:
|
||||
CLICON_RESTCONF_IPV4_ADDR
|
||||
CLICON_RESTCONF_IPV6_ADDR
|
||||
CLICON_RESTCONF_HTTP_PORT
|
||||
|
|
@ -712,6 +713,15 @@ module clixon-config {
|
|||
mandatory true;
|
||||
description "Process-id file of backend daemon";
|
||||
}
|
||||
leaf CLICON_BACKEND_RESTCONF_PROCESS {
|
||||
type boolean;
|
||||
default false;
|
||||
description
|
||||
"If set:
|
||||
- enable process-control of restconf daemon, ie start/stop restconf
|
||||
daemon internally using fork/exec.
|
||||
Set to false if you start the restconf daemon by other means.";
|
||||
}
|
||||
leaf CLICON_AUTOCOMMIT {
|
||||
type int32;
|
||||
default 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue