56ce797ef710cd1e50ddd1a5addb787c90331e8c
[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 <libubox/ustream.h>
21 #include "../utils/utils.h"
22
23 #define RESPAWN_ERROR   (5 * 60)
24
25 struct service_instance {
26         struct vlist_node node;
27         struct service *srv;
28         const char *name;
29
30         int8_t nice;
31         bool valid;
32
33         uid_t uid;
34         gid_t gid;
35
36         bool halt;
37         bool restart;
38         bool respawn;
39         int respawn_count;
40         struct timespec start;
41
42         uint32_t respawn_timeout;
43         uint32_t respawn_threshold;
44         uint32_t respawn_retry;
45
46         struct blob_attr *config;
47         struct uloop_process proc;
48         struct uloop_timeout timeout;
49         struct ustream_fd stdout;
50         struct ustream_fd stderr;
51
52         struct blob_attr *command;
53         struct blob_attr *trigger;
54         struct blobmsg_list env;
55         struct blobmsg_list data;
56         struct blobmsg_list netdev;
57         struct blobmsg_list file;
58         struct blobmsg_list limits;
59         struct blobmsg_list errors;
60 };
61
62 void instance_start(struct service_instance *in);
63 void instance_stop(struct service_instance *in);
64 bool instance_update(struct service_instance *in, struct service_instance *in_new);
65 void instance_init(struct service_instance *in, struct service *s, struct blob_attr *config);
66 void instance_free(struct service_instance *in);
67 void instance_dump(struct blob_buf *b, struct service_instance *in, int debug);
68
69 #endif