instance: allow filling "data" with fields of arbitrary type
[project/procd.git] / service / instance.h
1 /*
2  * Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
3  * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License version 2.1
7  * as published by the Free Software Foundation
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  */
14
15 #ifndef __PROCD_INSTANCE_H
16 #define __PROCD_INSTANCE_H
17
18 #include <libubox/vlist.h>
19 #include <libubox/uloop.h>
20 #include "../utils/utils.h"
21
22 #define RESPAWN_ERROR   (5 * 60)
23
24 struct service_instance {
25         struct vlist_node node;
26         struct service *srv;
27         const char *name;
28
29         int8_t nice;
30         bool valid;
31
32         bool halt;
33         bool restart;
34         bool respawn;
35         int respawn_count;
36         struct timespec start;
37
38         uint32_t respawn_timeout;
39         uint32_t respawn_threshold;
40         uint32_t respawn_retry;
41
42         struct blob_attr *config;
43         struct uloop_process proc;
44         struct uloop_timeout timeout;
45
46         struct blob_attr *command;
47         struct blob_attr *trigger;
48         struct blobmsg_list env;
49         struct blobmsg_list data;
50         struct blobmsg_list netdev;
51         struct blobmsg_list file;
52         struct blobmsg_list limits;
53         struct blobmsg_list errors;
54 };
55
56 void instance_start(struct service_instance *in);
57 void instance_stop(struct service_instance *in);
58 bool instance_update(struct service_instance *in, struct service_instance *in_new);
59 void instance_init(struct service_instance *in, struct service *s, struct blob_attr *config);
60 void instance_free(struct service_instance *in);
61 void instance_dump(struct blob_buf *b, struct service_instance *in, int debug);
62
63 #endif