summaryrefslogtreecommitdiff
path: root/svc/src/dat.h
blob: f2cdec231ba41e71275e97af60ea6cfc5f2bc42b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
 * Shared between the supervisor (init.c) and the control
 * filesystem (fs.c).
 */

enum
{
	/* states */
	Sstopped,
	Swaiting,	/* wants to run; a needs= is not up yet */
	Sstarting,	/* started; not yet ready */
	Srunning,
	Sfailed,
	Sdone,		/* ready=exit service that finished cleanly */

	/* kinds, from ready= */
	Kexec,		/* up as soon as started; watch the process */
	Ksrv,		/* up when /srv/x appears; watch that file */
	Kdial,		/* up when a dial succeeds; watch the process */
	Kexit,		/* oneshot; done when it exits cleanly */

	Maxargs		= 64,
	Maxneeds	= 32,
	Maxrestarts	= 5,		/* within Restartwindow seconds */
	Restartwindow	= 60,
	Restartwait	= 1,		/* seconds between restarts */
	Readywait	= 30,		/* seconds to become ready */
	Stopwait	= 5,		/* seconds before killing */
	Tickms		= 250,		/* poll interval */
};

typedef struct Svc Svc;
struct Svc
{
	char	*name;
	char	*exec;
	char	*argv[Maxargs];
	int	argc;
	char	*env[Maxargs];
	int	envc;
	char	*restart;
	int	enable;

	int	kind;
	char	*readyarg;
	char	*needs[Maxneeds];
	int	nneeds;

	int	wanted;			/* should it be running? */
	int	stopping;		/* we asked it to go; not a crash */
	int	pid;
	int	state;
	long	tstart;
	long	tstop;			/* when we asked it to stop */
	long	tretry;			/* earliest time to start again */
	int	restarts;
	long	rtimes[Maxrestarts];
	int	rnext;
	char	*exits;

	int	mark;			/* cycle detection */
	Svc	*next;
};

extern Svc	*svcs;
extern char	*statename[];
extern char	*svcdir;
extern char	*logdir;
extern int	verbose;
extern QLock	statelock;	/* covers svcs and the command queue */

/* init.c */
Svc*	findname(char*);
void	startsvc(Svc*);
void	stopsvc(Svc*);
char*	statusline(Svc*);	/* malloc'd ndb line, with newline */
char*	allstatus(void);	/* malloc'd, every service */

/* command queue: the filesystem asks, the supervisor acts */
char*	queuecmd(char *verb, char *name);	/* nil ok, else error */
void	draincmds(void);
int	cmdspending(void);

/* fs.c */
void	startfs(char *srvname, char *mtpt);