sysmgr

a simplistic service supervisor (deprecated)
git clone git://git.ckyln.com/~cem/sysmgr.git
Log | Files | Refs | README | LICENSE

sysmgr-needs.c (928B)


      1 /* See LICENSE for copyright information
      2  * sysmgr-needs -- tool to check service dependencies.
      3  */
      4 #include <unistd.h>
      5 #include <stdlib.h>
      6 #include <stdio.h>
      7 #include <libgen.h>
      8 
      9 #include "util.h"
     10 
     11 int
     12 main(int argc, char *argv[])
     13 {
     14 	if (argc < 2) {
     15 		printf("usage: %s [service...]\n", basename(argv[0]));
     16 		return 1;
     17 	}
     18 
     19 	int i;
     20 	struct service sv;
     21 
     22 	/* We are doing two iterations, because we want to exit as soon as possible if
     23 	 * any of the given services do not exist.
     24 	 */
     25 	for (i = 1; i < argc; i++) {
     26 		sv_init(&sv, argv[i]);
     27 		if (access(sv.svfile, R_OK) == -1)
     28 			die("sysmgr: service file for '%s' doesn't exist.", sv.name);
     29 	}
     30 
     31 	for (i = 1; i < argc; i++) {
     32 		while(1) {
     33 			int pid;
     34 
     35 			sv_init(&sv, argv[i]);
     36 			FILE *pidfile;
     37 
     38 			pidfile = fopen(sv.pidfile, "r");
     39 			if (pidfile != NULL) {
     40 				fscanf(pidfile, "%d", &pid);
     41 				fclose(pidfile);
     42 
     43 				if (checkprocess(pid) == 0) break;
     44 			}
     45 			sleep(1);
     46 		}
     47 	}
     48 }