send ubus_notify events when servers and instances change state
authorJohn Crispin <blogic@openwrt.org>
Wed, 4 Jun 2014 19:50:00 +0000 (20:50 +0100)
committerJohn Crispin <blogic@openwrt.org>
Thu, 5 Jun 2014 10:45:15 +0000 (11:45 +0100)
Signed-off-by: John Crispin <blogic@openwrt.org>
service/instance.c
service/service.c
service/service.h

index fa3594b710e0d453f8c6443f0e0557e060c5cf20..e410bc43a493eb4904054f2b09a654a2f3391716 100644 (file)
@@ -188,6 +188,7 @@ instance_start(struct service_instance *in)
        in->proc.pid = pid;
        clock_gettime(CLOCK_MONOTONIC, &in->start);
        uloop_process_add(&in->proc);
+       service_event("instance.start", in->srv->name, in->name);
 }
 
 static void
@@ -236,6 +237,7 @@ instance_exit(struct uloop_process *p, int ret)
                        uloop_timeout_set(&in->timeout, in->respawn_timeout * 1000);
                }
        }
+       service_event("instance.stop", in->srv->name, in->name);
 }
 
 void
index 8d1217f09f151936acd9592f2df9bec66d98e693..642692963a2dfd3e949740f89ebdfbfedbc8b8ac 100644 (file)
@@ -24,6 +24,7 @@
 
 struct avl_tree services;
 static struct blob_buf b;
+static struct ubus_context *ctx;
 
 static void
 service_instance_add(struct service *s, struct blob_attr *attr)
@@ -146,6 +147,7 @@ service_update(struct service *s, struct blob_attr **tb, bool add)
 static void
 service_delete(struct service *s)
 {
+       service_event("service.stop", s->name, NULL);
        vlist_flush_all(&s->instances);
        avl_delete(&services, &s->avl);
        trigger_del(s);
@@ -242,6 +244,8 @@ service_handle_set(struct ubus_context *ctx, struct ubus_object *obj,
 
        avl_insert(&services, &s->avl);
 
+       service_event("service.start", s->name, NULL);
+
        return 0;
 }
 
@@ -447,8 +451,18 @@ service_start_early(char *name, char *cmdline)
        return service_handle_set(NULL, NULL, NULL, "add", b.head);
 }
 
-void ubus_init_service(struct ubus_context *ctx)
+void service_event(const char *type, const char *service, const char *instance)
+{
+       blob_buf_init(&b, 0);
+       blobmsg_add_string(&b, "service", service);
+       if (instance)
+               blobmsg_add_string(&b, "instance", instance);
+       ubus_notify(ctx, &main_object, type, b.head, -1);
+}
+
+void ubus_init_service(struct ubus_context *_ctx)
 {
+       ctx = _ctx;
        ubus_add_object(ctx, &main_object);
 }
 
index 46ba74609e9995b28d29243f510aeccc55f4a0b8..892a1473e04161a8df46f0ebd289c696eaa2b98a 100644 (file)
@@ -53,5 +53,6 @@ int service_start_early(char *name, char *cmdline);
 void service_validate_del(struct service *s);
 void service_validate_init(void);
 void service_init(void);
+void service_event(const char *type, const char *service, const char *instance);
 
 #endif