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