Преглед изворни кода

ncd: add process_manager module

ambrop7 пре 15 година
родитељ
комит
0e6286d54d

+ 1 - 0
blog_channels.txt

@@ -19,6 +19,7 @@ ncd_blocker 4
 ncd_ip_in_network 4
 ncd_run 4
 ncd_synchronous_process 4
+ncd_process_manager 4
 ncd_net_backend_waitdevice 4
 ncd_net_backend_waitlink 4
 ncd_net_backend_badvpn 4

+ 4 - 0
generated/blog_channel_ncd_process_manager.h

@@ -0,0 +1,4 @@
+#ifdef BLOG_CURRENT_CHANNEL
+#undef BLOG_CURRENT_CHANNEL
+#endif
+#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_ncd_process_manager

+ 41 - 40
generated/blog_channels_defines.h

@@ -19,43 +19,44 @@
 #define BLOG_CHANNEL_ncd_ip_in_network 18
 #define BLOG_CHANNEL_ncd_run 19
 #define BLOG_CHANNEL_ncd_synchronous_process 20
-#define BLOG_CHANNEL_ncd_net_backend_waitdevice 21
-#define BLOG_CHANNEL_ncd_net_backend_waitlink 22
-#define BLOG_CHANNEL_ncd_net_backend_badvpn 23
-#define BLOG_CHANNEL_ncd_net_backend_wpa_supplicant 24
-#define BLOG_CHANNEL_ncd_net_backend_rfkill 25
-#define BLOG_CHANNEL_ncd_net_up 26
-#define BLOG_CHANNEL_ncd_net_dns 27
-#define BLOG_CHANNEL_ncd_net_iptables 28
-#define BLOG_CHANNEL_ncd_net_ipv4_addr 29
-#define BLOG_CHANNEL_ncd_net_ipv4_dhcp 30
-#define BLOG_CHANNEL_ncd_net_ipv4_route 31
-#define BLOG_CHANNEL_ncd_sys_evdev 32
-#define BLOG_CHANNEL_StreamPeerIO 33
-#define BLOG_CHANNEL_DatagramPeerIO 34
-#define BLOG_CHANNEL_BReactor 35
-#define BLOG_CHANNEL_BSignal 36
-#define BLOG_CHANNEL_FragmentProtoAssembler 37
-#define BLOG_CHANNEL_BPredicate 38
-#define BLOG_CHANNEL_ServerConnection 39
-#define BLOG_CHANNEL_Listener 40
-#define BLOG_CHANNEL_DataProto 41
-#define BLOG_CHANNEL_FrameDecider 42
-#define BLOG_CHANNEL_BSocksClient 43
-#define BLOG_CHANNEL_BDHCPClientCore 44
-#define BLOG_CHANNEL_BDHCPClient 45
-#define BLOG_CHANNEL_NCDIfConfig 46
-#define BLOG_CHANNEL_BUnixSignal 47
-#define BLOG_CHANNEL_BProcess 48
-#define BLOG_CHANNEL_StreamSocketSink 49
-#define BLOG_CHANNEL_StreamSocketSource 50
-#define BLOG_CHANNEL_DatagramSocketSink 51
-#define BLOG_CHANNEL_DatagramSocketSource 52
-#define BLOG_CHANNEL_PRStreamSink 53
-#define BLOG_CHANNEL_PRStreamSource 54
-#define BLOG_CHANNEL_BSocketPRFileDesc 55
-#define BLOG_CHANNEL_PacketProtoDecoder 56
-#define BLOG_CHANNEL_DPRelay 57
-#define BLOG_CHANNEL_BThreadWork 58
-#define BLOG_CHANNEL_DPReceive 59
-#define BLOG_NUM_CHANNELS 60
+#define BLOG_CHANNEL_ncd_process_manager 21
+#define BLOG_CHANNEL_ncd_net_backend_waitdevice 22
+#define BLOG_CHANNEL_ncd_net_backend_waitlink 23
+#define BLOG_CHANNEL_ncd_net_backend_badvpn 24
+#define BLOG_CHANNEL_ncd_net_backend_wpa_supplicant 25
+#define BLOG_CHANNEL_ncd_net_backend_rfkill 26
+#define BLOG_CHANNEL_ncd_net_up 27
+#define BLOG_CHANNEL_ncd_net_dns 28
+#define BLOG_CHANNEL_ncd_net_iptables 29
+#define BLOG_CHANNEL_ncd_net_ipv4_addr 30
+#define BLOG_CHANNEL_ncd_net_ipv4_dhcp 31
+#define BLOG_CHANNEL_ncd_net_ipv4_route 32
+#define BLOG_CHANNEL_ncd_sys_evdev 33
+#define BLOG_CHANNEL_StreamPeerIO 34
+#define BLOG_CHANNEL_DatagramPeerIO 35
+#define BLOG_CHANNEL_BReactor 36
+#define BLOG_CHANNEL_BSignal 37
+#define BLOG_CHANNEL_FragmentProtoAssembler 38
+#define BLOG_CHANNEL_BPredicate 39
+#define BLOG_CHANNEL_ServerConnection 40
+#define BLOG_CHANNEL_Listener 41
+#define BLOG_CHANNEL_DataProto 42
+#define BLOG_CHANNEL_FrameDecider 43
+#define BLOG_CHANNEL_BSocksClient 44
+#define BLOG_CHANNEL_BDHCPClientCore 45
+#define BLOG_CHANNEL_BDHCPClient 46
+#define BLOG_CHANNEL_NCDIfConfig 47
+#define BLOG_CHANNEL_BUnixSignal 48
+#define BLOG_CHANNEL_BProcess 49
+#define BLOG_CHANNEL_StreamSocketSink 50
+#define BLOG_CHANNEL_StreamSocketSource 51
+#define BLOG_CHANNEL_DatagramSocketSink 52
+#define BLOG_CHANNEL_DatagramSocketSource 53
+#define BLOG_CHANNEL_PRStreamSink 54
+#define BLOG_CHANNEL_PRStreamSource 55
+#define BLOG_CHANNEL_BSocketPRFileDesc 56
+#define BLOG_CHANNEL_PacketProtoDecoder 57
+#define BLOG_CHANNEL_DPRelay 58
+#define BLOG_CHANNEL_BThreadWork 59
+#define BLOG_CHANNEL_DPReceive 60
+#define BLOG_NUM_CHANNELS 61

+ 1 - 0
generated/blog_channels_list.h

@@ -19,6 +19,7 @@
 {.name = "ncd_ip_in_network", .loglevel = 4},
 {.name = "ncd_run", .loglevel = 4},
 {.name = "ncd_synchronous_process", .loglevel = 4},
+{.name = "ncd_process_manager", .loglevel = 4},
 {.name = "ncd_net_backend_waitdevice", .loglevel = 4},
 {.name = "ncd_net_backend_waitlink", .loglevel = 4},
 {.name = "ncd_net_backend_badvpn", .loglevel = 4},

+ 1 - 0
ncd/CMakeLists.txt

@@ -38,6 +38,7 @@ add_executable(badvpn-ncd
     modules/ip_in_network.c
     modules/run.c
     modules/synchronous_process.c
+    modules/process_manager.c
     modules/net_backend_waitdevice.c
     modules/net_backend_waitlink.c
     modules/net_backend_badvpn.c

+ 2 - 0
ncd/modules/modules.h

@@ -43,6 +43,7 @@ extern const struct NCDModuleGroup ncdmodule_blocker;
 extern const struct NCDModuleGroup ncdmodule_ip_in_network;
 extern const struct NCDModuleGroup ncdmodule_run;
 extern const struct NCDModuleGroup ncdmodule_synchronous_process;
+extern const struct NCDModuleGroup ncdmodule_process_manager;
 extern const struct NCDModuleGroup ncdmodule_net_backend_waitdevice;
 extern const struct NCDModuleGroup ncdmodule_net_backend_waitlink;
 extern const struct NCDModuleGroup ncdmodule_net_backend_badvpn;
@@ -77,6 +78,7 @@ static const struct NCDModuleGroup *ncd_modules[] = {
     &ncdmodule_ip_in_network,
     &ncdmodule_run,
     &ncdmodule_synchronous_process,
+    &ncdmodule_process_manager,
     &ncdmodule_net_backend_waitdevice,
     &ncdmodule_net_backend_waitlink,
     &ncdmodule_net_backend_badvpn,

+ 572 - 0
ncd/modules/process_manager.c

@@ -0,0 +1,572 @@
+/**
+ * @file process_manager.c
+ * @author Ambroz Bizjak <ambrop7@gmail.com>
+ * 
+ * @section LICENSE
+ * 
+ * This file is part of BadVPN.
+ * 
+ * BadVPN is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ * 
+ * BadVPN is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * 
+ * @section DESCRIPTION
+ * 
+ * Module which allows starting and stopping processes from templates dynamically.
+ * 
+ * Synopsis: process_manager()
+ * Description: manages processes. On deinitialization, initiates termination of all
+ *   contained processes and waits for them to terminate.
+ * 
+ * Synopsis: process_manager::start(string name, string template_name, list(string) args)
+ * Description: creates a new process from the template named template_name, with arguments args,
+ *   identified by name within the process manager. If a process with this name already exists
+ *   and is not being terminated, does nothing. If it is being terminated, it will be restarted
+ *   using the given parameters after it terminates.
+ * 
+ * Synopsis: process_manager::stop(string name)
+ * Description: initiates termination of the process identified by name within the process manager.
+ *   If there is no such process, or the process is already being terminated, does nothing.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <misc/offset.h>
+#include <structure/LinkedList2.h>
+#include <ncd/NCDModule.h>
+
+#include <generated/blog_channel_ncd_process_manager.h>
+
+#define ModuleLog(i, ...) NCDModuleInst_Backend_Log((i), BLOG_CURRENT_CHANNEL, __VA_ARGS__)
+
+#define RETRY_TIME 10000
+
+#define PROCESS_STATE_RUNNING 1
+#define PROCESS_STATE_STOPPING 2
+#define PROCESS_STATE_RESTARTING 3
+#define PROCESS_STATE_RETRYING 4
+
+struct instance {
+    NCDModuleInst *i;
+    LinkedList2 processes_list;
+    int dying;
+};
+
+struct process {
+    struct instance *manager;
+    char *name;
+    BTimer retry_timer;
+    LinkedList2Node processes_list_node;
+    int state;
+    int have_params;
+    char *params_template_name;
+    NCDValue params_args;
+    int have_module_process;
+    NCDModuleProcess module_process;
+};
+
+struct startstop_instance {
+    NCDModuleInst *i;
+};
+
+static struct process * find_process (struct instance *o, const char *name);
+static int process_new (struct instance *o, const char *name, const char *template_name, NCDValue *args);
+static void process_free (struct process *p);
+static void process_retry_timer_handler (struct process *p);
+static void process_module_process_handler_dead (struct process *p);
+static void process_stop (struct process *p);
+static int process_restart (struct process *p, const char *template_name, NCDValue *args);
+static void process_try (struct process *p);
+static int process_set_params (struct process *p, const char *template_name, NCDValue args);
+static void instance_free (struct instance *o);
+
+struct process * find_process (struct instance *o, const char *name)
+{
+    LinkedList2Node *n = LinkedList2_GetFirst(&o->processes_list);
+    while (n) {
+        struct process *p = UPPER_OBJECT(n, struct process, processes_list_node);
+        if (!strcmp(p->name, name)) {
+            return p;
+        }
+        n = LinkedList2Node_Next(n);
+    }
+    
+    return NULL;
+}
+
+int process_new (struct instance *o, const char *name, const char *template_name, NCDValue *args)
+{
+    ASSERT(!o->dying)
+    ASSERT(!find_process(o, name))
+    ASSERT(NCDValue_Type(args) == NCDVALUE_LIST)
+    
+    // allocate structure
+    struct process *p = malloc(sizeof(*p));
+    if (!p) {
+        ModuleLog(o->i, BLOG_ERROR, "malloc failed");
+        goto fail0;
+    }
+    
+    // set manager
+    p->manager = o;
+    
+    // copy name
+    if (!(p->name = strdup(name))) {
+        ModuleLog(o->i, BLOG_ERROR, "strdup failed");
+        goto fail1;
+    }
+    
+    // init retry timer
+    BTimer_Init(&p->retry_timer, RETRY_TIME, (BTimer_handler)process_retry_timer_handler, p);
+    
+    // insert to processes list
+    LinkedList2_Append(&o->processes_list, &p->processes_list_node);
+    
+    // have no params
+    p->have_params = 0;
+    
+    // have no module process
+    p->have_module_process = 0;
+    
+    // copy arguments
+    NCDValue args2;
+    if (!NCDValue_InitCopy(&args2, args)) {
+        ModuleLog(o->i, BLOG_ERROR, "NCDValue_InitCopy failed");
+        goto fail2;
+    }
+    
+    // set params
+    if (!process_set_params(p, template_name, args2)) {
+        NCDValue_Free(&args2);
+        goto fail2;
+    }
+    
+    // try starting it
+    process_try(p);
+    
+    return 1;
+    
+fail2:
+    LinkedList2_Remove(&o->processes_list, &p->processes_list_node);
+    free(p->name);
+fail1:
+    free(p);
+fail0:
+    return 0;
+}
+
+void process_free (struct process *p)
+{
+    ASSERT(!p->have_module_process)
+    struct instance *o = p->manager;
+    
+    // free params
+    if (p->have_params) {
+        NCDValue_Free(&p->params_args);
+        free(p->params_template_name);
+    }
+    
+    // remove from processes list
+    LinkedList2_Remove(&o->processes_list, &p->processes_list_node);
+    
+    // free timer
+    BReactor_RemoveTimer(o->i->reactor, &p->retry_timer);
+    
+    // free name
+    free(p->name);
+    
+    // free structure
+    free(p);
+}
+
+void process_retry_timer_handler (struct process *p)
+{
+    struct instance *o = p->manager;
+    ASSERT(p->state == PROCESS_STATE_RETRYING)
+    ASSERT(!o->dying)
+    ASSERT(p->have_params)
+    ASSERT(!p->have_module_process)
+    
+    // retry
+    process_try(p);
+}
+
+void process_module_process_handler_dead (struct process *p)
+{
+    struct instance *o = p->manager;
+    ASSERT(p->have_module_process)
+    
+    // free module process
+    NCDModuleProcess_Free(&p->module_process);
+    
+    // set no module process
+    p->have_module_process = 0;
+    
+    switch (p->state) {
+        case PROCESS_STATE_STOPPING: {
+            // free process
+            process_free(p);
+        
+            // if manager is dying and there are no more processes, let it die
+            if (o->dying && LinkedList2_IsEmpty(&o->processes_list)) {
+                instance_free(o);
+            }
+            
+            return;
+        } break;
+        
+        case PROCESS_STATE_RESTARTING: {
+            ASSERT(!o->dying)
+            ASSERT(p->have_params)
+            
+            // restart
+            process_try(p);
+        } break;
+        
+        default: ASSERT(0);
+    }
+}
+
+void process_stop (struct process *p)
+{
+    switch (p->state) {
+        case PROCESS_STATE_RETRYING: {
+            // free process
+            process_free(p);
+            return;
+        } break;
+        
+        case PROCESS_STATE_RUNNING: {
+            // request process to die
+            NCDModuleProcess_Die(&p->module_process);
+            
+            // set state
+            p->state = PROCESS_STATE_STOPPING;
+        } break;
+        
+        case PROCESS_STATE_RESTARTING: {
+            // free params
+            NCDValue_Free(&p->params_args);
+            free(p->params_template_name);
+            p->have_params = 0;
+            
+            // set state
+            p->state = PROCESS_STATE_STOPPING;
+        } break;
+        
+        case PROCESS_STATE_STOPPING: {
+            // nothing to do
+        } break;
+        
+        default: ASSERT(0);
+    }
+}
+
+int process_restart (struct process *p, const char *template_name, NCDValue *args)
+{
+    struct instance *o = p->manager;
+    ASSERT(!o->dying)
+    ASSERT(p->state == PROCESS_STATE_STOPPING)
+    ASSERT(!p->have_params)
+    
+    // copy arguments
+    NCDValue args2;
+    if (!NCDValue_InitCopy(&args2, args)) {
+        ModuleLog(o->i, BLOG_ERROR, "NCDValue_InitCopy failed");
+        return 0;
+    }
+    
+    // set params
+    if (!process_set_params(p, template_name, args2)) {
+        NCDValue_Free(&args2);
+        return 0;
+    }
+    
+    // set state
+    p->state = PROCESS_STATE_RESTARTING;
+    
+    return 1;
+}
+
+void process_try (struct process *p)
+{
+    struct instance *o = p->manager;
+    ASSERT(!o->dying)
+    ASSERT(p->have_params)
+    ASSERT(!p->have_module_process)
+    
+    ModuleLog(o->i, BLOG_INFO, "trying process %s", p->name);
+    
+    // init module process
+    if (!NCDModuleProcess_Init(&p->module_process, o->i, p->params_template_name, p->params_args, p, (NCDModuleProcess_handler_dead)process_module_process_handler_dead)) {
+        ModuleLog(o->i, BLOG_ERROR, "NCDModuleProcess_Init failed");
+        
+        // set timer
+        BReactor_SetTimer(o->i->reactor, &p->retry_timer);
+        
+        // set state
+        p->state = PROCESS_STATE_RETRYING;
+        
+        return;
+    }
+    
+    // free params
+    free(p->params_template_name);
+    p->have_params = 0;
+    
+    // set have module process
+    p->have_module_process = 1;
+    
+    // set state
+    p->state = PROCESS_STATE_RUNNING;
+}
+
+int process_set_params (struct process *p, const char *template_name, NCDValue args)
+{
+    ASSERT(!p->have_params)
+    
+    // copy template name
+    if (!(p->params_template_name = strdup(template_name))) {
+        ModuleLog(p->manager->i, BLOG_ERROR, "strdup failed");
+        return 0;
+    }
+    
+    // eat arguments
+    p->params_args = args;
+    
+    // set have params
+    p->have_params = 1;
+    
+    return 1;
+}
+
+static void func_new (NCDModuleInst *i)
+{
+    // allocate instance
+    struct instance *o = malloc(sizeof(*o));
+    if (!o) {
+        ModuleLog(i, BLOG_ERROR, "failed to allocate instance");
+        goto fail0;
+    }
+    NCDModuleInst_Backend_SetUser(i, o);
+    
+    // init arguments
+    o->i = i;
+    
+    // check arguments
+    if (!NCDValue_ListRead(o->i->args, 0)) {
+        ModuleLog(o->i, BLOG_ERROR, "wrong arity");
+        goto fail1;
+    }
+    
+    // init processes list
+    LinkedList2_Init(&o->processes_list);
+    
+    // set not dying
+    o->dying = 0;
+    
+    // signal up
+    NCDModuleInst_Backend_Event(o->i, NCDMODULE_EVENT_UP);
+    
+    return;
+    
+fail1:
+    free(o);
+fail0:
+    NCDModuleInst_Backend_SetError(i);
+    NCDModuleInst_Backend_Event(i, NCDMODULE_EVENT_DEAD);
+}
+
+void instance_free (struct instance *o)
+{
+    ASSERT(LinkedList2_IsEmpty(&o->processes_list))
+    NCDModuleInst *i = o->i;
+    
+    // free instance
+    free(o);
+    
+    NCDModuleInst_Backend_Event(i, NCDMODULE_EVENT_DEAD);
+}
+
+static void func_die (void *vo)
+{
+    struct instance *o = vo;
+    ASSERT(!o->dying)
+    
+    // request all processes to die
+    LinkedList2Iterator it;
+    LinkedList2Iterator_InitForward(&it, &o->processes_list);
+    LinkedList2Node *n;
+    while (n = LinkedList2Iterator_Next(&it)) {
+        struct process *p = UPPER_OBJECT(n, struct process, processes_list_node);
+        process_stop(p);
+    }
+    
+    // if there are no processes, die immediately
+    if (LinkedList2_IsEmpty(&o->processes_list)) {
+        instance_free(o);
+        return;
+    }
+    
+    // set dying
+    o->dying = 1;
+}
+
+static void start_func_new (NCDModuleInst *i)
+{
+    // allocate instance
+    struct startstop_instance *o = malloc(sizeof(*o));
+    if (!o) {
+        ModuleLog(i, BLOG_ERROR, "failed to allocate instance");
+        goto fail0;
+    }
+    NCDModuleInst_Backend_SetUser(i, o);
+    
+    // init arguments
+    o->i = i;
+    
+    // check arguments
+    NCDValue *name_arg;
+    NCDValue *template_name_arg;
+    NCDValue *args_arg;
+    if (!NCDValue_ListRead(o->i->args, 3, &name_arg, &template_name_arg, &args_arg)) {
+        ModuleLog(o->i, BLOG_ERROR, "wrong arity");
+        goto fail1;
+    }
+    if (NCDValue_Type(name_arg) != NCDVALUE_STRING || NCDValue_Type(template_name_arg) != NCDVALUE_STRING ||
+        NCDValue_Type(args_arg) != NCDVALUE_LIST) {
+        ModuleLog(o->i, BLOG_ERROR, "wrong type");
+        goto fail1;
+    }
+    char *name = NCDValue_StringValue(name_arg);
+    char *template_name = NCDValue_StringValue(template_name_arg);
+    
+    // signal up.
+    // Do it before creating the process so that the process starts initializing before our own process continues.
+    NCDModuleInst_Backend_Event(o->i, NCDMODULE_EVENT_UP);
+    
+    // get method object
+    struct instance *mo = i->method_object->inst_user;
+    
+    if (mo->dying) {
+        ModuleLog(o->i, BLOG_INFO, "manager is dying, not creating process %s", name);
+    } else {
+        struct process *p = find_process(mo, name);
+        if (p && p->state != PROCESS_STATE_STOPPING) {
+            ModuleLog(o->i, BLOG_INFO, "process %s already started", name);
+        } else {
+            if (p) {
+                if (!process_restart(p, template_name, args_arg)) {
+                    goto fail1;
+                }
+            } else {
+                if (!process_new(mo, name, template_name, args_arg)) {
+                    goto fail1;
+                }
+            }
+        }
+    }
+    
+    return;
+    
+fail1:
+    free(o);
+fail0:
+    NCDModuleInst_Backend_SetError(i);
+    NCDModuleInst_Backend_Event(i, NCDMODULE_EVENT_DEAD);
+}
+
+static void stop_func_new (NCDModuleInst *i)
+{
+    // allocate instance
+    struct startstop_instance *o = malloc(sizeof(*o));
+    if (!o) {
+        ModuleLog(i, BLOG_ERROR, "failed to allocate instance");
+        goto fail0;
+    }
+    NCDModuleInst_Backend_SetUser(i, o);
+    
+    // init arguments
+    o->i = i;
+    
+    // check arguments
+    NCDValue *name_arg;
+    if (!NCDValue_ListRead(o->i->args, 1, &name_arg)) {
+        ModuleLog(o->i, BLOG_ERROR, "wrong arity");
+        goto fail1;
+    }
+    if (NCDValue_Type(name_arg) != NCDVALUE_STRING) {
+        ModuleLog(o->i, BLOG_ERROR, "wrong type");
+        goto fail1;
+    }
+    char *name = NCDValue_StringValue(name_arg);
+    
+    // signal up.
+    // Do it before stopping the process so that the process starts terminating before our own process continues.
+    NCDModuleInst_Backend_Event(o->i, NCDMODULE_EVENT_UP);
+    
+    // get method object
+    struct instance *mo = i->method_object->inst_user;
+    
+    if (mo->dying) {
+        ModuleLog(o->i, BLOG_INFO, "manager is dying, not stopping process %s", name);
+    } else {
+        struct process *p = find_process(mo, name);
+        if (!(p && p->state != PROCESS_STATE_STOPPING)) {
+            ModuleLog(o->i, BLOG_INFO, "process %s already stopped", name);
+        } else {
+            process_stop(p);
+        }
+    }
+    
+    return;
+    
+fail1:
+    free(o);
+fail0:
+    NCDModuleInst_Backend_SetError(i);
+    NCDModuleInst_Backend_Event(i, NCDMODULE_EVENT_DEAD);
+}
+
+static void startstop_func_die (void *vo)
+{
+    struct startstop_instance *o = vo;
+    NCDModuleInst *i = o->i;
+    
+    // free instance
+    free(o);
+    
+    NCDModuleInst_Backend_Event(i, NCDMODULE_EVENT_DEAD);
+}
+
+static const struct NCDModule modules[] = {
+    {
+        .type = "process_manager",
+        .func_new = func_new,
+        .func_die = func_die
+    }, {
+        .type = "process_manager::start",
+        .func_new = start_func_new,
+        .func_die = startstop_func_die
+    }, {
+        .type = "process_manager::stop",
+        .func_new = stop_func_new,
+        .func_die = startstop_func_die
+    }, {
+        .type = NULL
+    }
+};
+
+const struct NCDModuleGroup ncdmodule_process_manager = {
+    .modules = modules
+};