5a768418fc5cd38abcabedb808648f1682f6dd87
[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 jail {
26 bool procfs;
27 bool sysfs;
28 bool ubus;
29 bool log;
30 char *name;
31 struct blobmsg_list mount;
32 int argc;
33 };
34
35 struct service_instance {
36 struct vlist_node node;
37 struct service *srv;
38 const char *name;
39
40 int8_t nice;
41 bool valid;
42
43 uid_t uid;
44 gid_t gid;
45
46 bool halt;
47 bool restart;
48 bool respawn;
49 int respawn_count;
50 struct timespec start;
51
52 bool trace;
53 bool has_jail;
54 struct jail jail;
55 char *seccomp;
56
57 uint32_t respawn_timeout;
58 uint32_t respawn_threshold;
59 uint32_t respawn_retry;
60
61 struct blob_attr *config;
62 struct uloop_process proc;
63 struct uloop_timeout timeout;
64 struct ustream_fd _stdout;
65 struct ustream_fd _stderr;
66
67 struct blob_attr *command;
68 struct blob_attr *trigger;
69 struct blobmsg_list env;
70 struct blobmsg_list data;
71 struct blobmsg_list netdev;
72 struct blobmsg_list file;
73 struct blobmsg_list limits;
74 struct blobmsg_list errors;
75 };
76
77 void instance_start(struct service_instance *in);
78 void instance_stop(struct service_instance *in);
79 bool instance_update(struct service_instance *in, struct service_instance *in_new);
80 void instance_init(struct service_instance *in, struct service *s, struct blob_attr *config);
81 void instance_free(struct service_instance *in);
82 void instance_dump(struct blob_buf *b, struct service_instance *in, int debug);
83
84 #endif