/********************************************************************* v.1 archangel.c angels the angel, in case of machine reboots, or other ills. Requirments: angel in ewtoo crontab access Installing: place this file in src directory edit Makefile to have it to compile archangel.c, useing the 'angel' procedure as a template follow procs for installing extras in angel.c follow procs for adding entry to crontab modify the defines in archangel.c to get the MATCH_STRING type ps -x from shell while the angel is running, and replace in code. to get ROOT, use the ROOT dirs for LIVE and CODING. modify BOOT_ANGEL and ARCH_LOCK as needed for your talker's directory setup Notes: if you run this on a system other than linux, or with a funky 'ps' command, the command line options to it will have to be modified Bug Reports: send to phypor@benland.muc.edu Licences: freely distributable and modifiable, as long as this full header kept with any distributions and any modifications to original marked plainly so. Warrenty: non, the author is in no way responsible for use, misuse, abuse, or any other actions misactions, reactions of this code, its provided as is. Author: phypor "if it breaks you get to keep both pieces" ~old linux proverb;) **************** installing entry in crontab **************** from shell invoke crontab -e and put # every ten mins, of every hour, of every day */10 * * * * /home/clouds/live/bin/archangel & in the file, modifing as wanted to change how often this runs also modify the path to the live archangel for Your Talker **************** end installing in crontab ****************** ************ installing lock file into angel.c ************** ** at the top of the file put this, ** ** modify to how looks in archangel.c ** #define ARCH_LOCK "out/archlock" if (chdir(ROOT) < 0) error("Can't change to root directory.\n"); ** add this line ** unlink (ARCH_LOCK); ******************* if (strcmp(angel_name, argv[0])) log("error", "Total barf.. crashing lots... Giving up"); log("error", "Question is, what now ??"); ** add these two lines ** alive_fd = creat (ARCH_LOCK, S_IRUSR | S_IWUSR); close (alive_fd); ************************* exit(-1); **************** end installing in angel.c ****************** ********************************************************************/ #include #include #include #include #include #include #include #include #include void log ( char *, char * ); #ifdef CODING #define MATCH_STRING ".oO> Clouds Clouds = 0) exit (XS_LOCK_EXISTS); command = popen("ps -x", "r"); if (!command) { log ("archangel", "Erg! Failed to open ps process."); exit (XS_NO_POPEN); } for (memset (line, 0, 1024); fgets (line, 1024, command); memset (line, 0, 1024)) { if (strstr (line, MATCH_STRING) || strstr (MATCH_STRING, line)) { /* angel is running on process list */ wait (0); /* wait for child to exit */ fclose (command); exit (XS_OK); } } wait (0); fclose (command); log ("archangel", "Angel down, booting..."); system (BOOT_ANGEL); exit (XS_OK); } void log ( char * filename, char * str ) { int fd; time_t tm; char path[160]; char out[1024]; memset (path, 0, 160); sprintf (path, "logs/%s.log", filename); fd = open (path, O_CREAT | O_WRONLY | O_SYNC | O_APPEND, S_IRUSR | S_IWUSR); if (fd < 0) return; memset (out, 0, 1024); tm = time (0); sprintf (out, "%s %s\n", ctime (&tm), str); write (fd, out, strlen(out)); close(fd); }