]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
bozo: bosserver -pidfiles option
authorMichael Meffie <mmeffie@sinenomine.net>
Wed, 24 Nov 2010 01:21:50 +0000 (20:21 -0500)
committerDerrick Brashear <shadow@dementix.org>
Fri, 7 Oct 2011 17:32:02 +0000 (10:32 -0700)
Add an option to bosserver to create pidfiles for long running
processes for simple, fs, and dafs bnode types, as well as the
bosserver process. The pidfiles are located in the server local
directory by default, or in the path specifed by the -pidfiles
command-line option.

Reviewed-on: http://gerrit.openafs.org/5497
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementix.org>
(cherry picked from commit bdf86d245fd55c5c7ac7ea81e3d6b6bafdbe1783)

Change-Id: Id76530b81e2e92c76a015510d04dc8d5e5fd75ce
Reviewed-on: http://gerrit.openafs.org/5537
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementix.org>
src/bozo/bnode.c
src/bozo/bnode.p.h
src/bozo/bosprototypes.h
src/bozo/bosserver.c
src/bozo/cronbnodeops.c
src/bozo/ezbnodeops.c
src/bozo/fsbnodeops.c

index 891e871e32f1dee7613c9d689362d8055e31698c..6f3e2c36d1b3262ec66c88121f83dc6d6709d4ab 100644 (file)
@@ -58,6 +58,7 @@ static struct bnode_stats {
 } bnode_stats;
 
 extern const char *DoCore;
+extern const char *DoPidFiles;
 #ifndef AFS_NT40_ENV
 extern char **environ;         /* env structure */
 #endif
@@ -994,6 +995,7 @@ bnode_NewProc(struct bnode *abnode, char *aexecString, char *coreName,
     tp->pid = cpid;
     tp->flags = BPROC_STARTED;
     tp->flags &= ~BPROC_EXITED;
+    BOP_PROCSTARTED(abnode, tp);
     bnode_Check(abnode);
     return 0;
 }
index 14ab9d7ba6625d42411d054a9d2726813075bf5e..971d272195008db2f89f78f237aa641264b86c14 100644 (file)
@@ -16,6 +16,7 @@
 #define        BOP_GETPARM(bnode, n, b, l)     ((*(bnode)->ops->getparm)((bnode),(n),(b),(l)))
 #define        BOP_RESTARTP(bnode)     ((*(bnode)->ops->restartp)((bnode)))
 #define BOP_HASCORE(bnode)     ((*(bnode)->ops->hascore)((bnode)))
+#define BOP_PROCSTARTED(bnode,p)       ((*(bnode)->ops->procstarted)((bnode),(p)))
 
 struct bnode_proc;
 
@@ -31,6 +32,7 @@ struct bnode_ops {
                     afs_int32 alen);
     int (*restartp) ( struct bnode *);
     int (*hascore) ( struct bnode *);
+    int (*procstarted) ( struct bnode *, struct bnode_proc * );
 };
 
 struct bnode_type {
@@ -139,3 +141,5 @@ extern afs_int32 bnode_Create(char *atype, char *ainstance, struct bnode ** abp,
 extern struct bnode *bnode_FindInstance(char *aname);
 extern int bnode_WaitStatus(struct bnode *abnode, int astatus);
 extern int bnode_SetStat(struct bnode *abnode, int agoal);
+extern int bnode_CreatePidFile(struct bnode *abnode, struct bnode_proc *aproc, char *name);
+extern int bnode_DestroyPidFile(struct bnode *abnode, struct bnode_proc *aproc);
index 38403aee97bad213a06782409bca005480ef2441..1f666fd01030a3a57cdbd06a77b977fd23d8cebc 100644 (file)
 #ifndef _BOSPROTOTYPES_H_
 #define _BOSPROTOTYPES_H_
 
+#ifdef AFS_NT40_ENV
+typedef int pid_t;
+#endif
+
 #include <rx/rxkad.h>
 
 /* bnode.c */
@@ -43,6 +47,8 @@ int bnode_Deactivate(struct bnode *abnode);
 void bozo_Log(char *format, ... );
 int bozo_ReBozo(void);
 int WriteBozoFile(char *aname);
+int bozo_CreatePidFile(char *ainst, char *aname, pid_t apid);
+int bozo_DeletePidFile(char *ainst, char *aname);
 
 /* bosoprocs.c */
 int GetRequiredDirPerm(const char *path);
index e05663be7b08a163fdadc861e0685880d4973ef2..dca7ec65234da260c381b6e575a6c6090614ab70 100644 (file)
@@ -70,6 +70,7 @@ FILE *bozo_logFile;
 const char *DoCore;
 int DoLogging = 0;
 int DoSyslog = 0;
+const char *DoPidFiles = NULL;
 #ifndef AFS_NT40_ENV
 int DoSyslogFacility = LOG_DAEMON;
 #endif
@@ -727,6 +728,90 @@ background(void)
 #endif /* ! AFS_NT40_ENV */
 #endif
 
+static char *
+make_pid_filename(char *ainst, char *aname)
+{
+    char *buffer = NULL;
+    int length;
+
+    length = strlen(DoPidFiles) + strlen(ainst) + 6;
+    if (aname && *aname) {
+       length += strlen(aname) + 1;
+    }
+    buffer = malloc(length * sizeof(char));
+    if (!buffer) {
+       if (aname) {
+           bozo_Log("Failed to alloc pid filename buffer for %s.%s.\n",
+                    ainst, aname);
+       } else {
+           bozo_Log("Failed to alloc pid filename buffer for %s.\n", ainst);
+       }
+    } else {
+       if (aname && *aname) {
+           snprintf(buffer, length, "%s/%s.%s.pid", DoPidFiles, ainst,
+                    aname);
+       } else {
+           snprintf(buffer, length, "%s/%s.pid", DoPidFiles, ainst);
+       }
+    }
+    return buffer;
+}
+
+/**
+ * Write a file containing the pid of the named process.
+ *
+ * @param ainst instance name
+ * @param aname sub-process name of the instance, may be null
+ * @param apid  process id of the newly started process
+ *
+ * @returns status
+ */
+int
+bozo_CreatePidFile(char *ainst, char *aname, pid_t apid)
+{
+    int code = 0;
+    char *pidfile = NULL;
+    FILE *fp;
+
+    pidfile = make_pid_filename(ainst, aname);
+    if (!pidfile) {
+       return ENOMEM;
+    }
+    if ((fp = fopen(pidfile, "w")) == NULL) {
+       bozo_Log("Failed to open pidfile %s; errno=%d\n", pidfile, errno);
+       free(pidfile);
+       return errno;
+    }
+    if (fprintf(fp, "%ld\n", afs_printable_int32_ld(apid)) < 0) {
+       code = errno;
+    }
+    if (fclose(fp) != 0) {
+       code = errno;
+    }
+    free(pidfile);
+    return code;
+}
+
+/**
+ * Clean a pid file for a process which just exited.
+ *
+ * @param ainst instance name
+ * @param aname sub-process name of the instance, may be null
+ *
+ * @returns status
+ */
+int
+bozo_DeletePidFile(char *ainst, char *aname)
+{
+    char *pidfile = NULL;
+    pidfile = make_pid_filename(ainst, aname);
+    if (pidfile) {
+       unlink(pidfile);
+       free(pidfile);
+    }
+    return 0;
+}
+
 /* start a process and monitor it */
 
 #include "AFS_component_version_number.c"
@@ -871,6 +956,10 @@ main(int argc, char **argv, char **envp)
                printf("Invalid audit interface '%s'\n", interface);
                exit(1);
            }
+       } else if (strncmp(argv[code], "-pidfiles=", 10) == 0) {
+           DoPidFiles = (argv[code]+10);
+       } else if (strncmp(argv[code], "-pidfiles", 9) == 0) {
+           DoPidFiles = AFSDIR_BOSCONFIG_DIR;
        }
        else {
 
@@ -884,6 +973,7 @@ main(int argc, char **argv, char **envp)
                   "[-syslog[=FACILITY]] "
                   "[-enable_peer_stats] [-enable_process_stats] "
                   "[-cores=<none|path>] \n"
+                  "[-pidfiles[=path]] "
                   "[-nofork] " "[-help]\n");
 #else
            printf("Usage: bosserver [-noauth] [-log] "
@@ -892,6 +982,7 @@ main(int argc, char **argv, char **envp)
                   "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals]"
                   "[-enable_peer_stats] [-enable_process_stats] "
                   "[-cores=<none|path>] \n"
+                  "[-pidfiles[=path]] "
                   "[-help]\n");
 #endif
            fflush(stdout);
@@ -1053,6 +1144,10 @@ main(int argc, char **argv, char **envp)
     afsconf_SetNoAuthFlag(tdir, noAuth);
     afsconf_BuildServerSecurityObjects(tdir, 0, &securityClasses, &numClasses);
 
+    if (DoPidFiles) {
+       bozo_CreatePidFile("bosserver", NULL, getpid());
+    }
+
     /* Disable jumbograms */
     rx_SetNoJumbo();
 
index 01026e3456458b3a33e930ce83e984bad1962a29..d1adc5acbb220321f5a041e29ed1d11749b981b6 100644 (file)
@@ -37,6 +37,7 @@ static int cron_delete(struct bnode *bnode);
 static int cron_timeout(struct bnode *bnode);
 static int cron_getstat(struct bnode *bnode, afs_int32 *status);
 static int cron_setstat(struct bnode *bnode, afs_int32 status);
+static int cron_procstarted(struct bnode *bnode, struct bnode_proc *proc);
 static int cron_procexit(struct bnode *bnode, struct bnode_proc *proc);
 static int cron_getstring(struct bnode *bnode, char *abuffer, afs_int32 alen);
 static int cron_getparm(struct bnode *bnode, afs_int32, char *, afs_int32);
@@ -54,6 +55,7 @@ struct bnode_ops cronbnode_ops = {
     cron_getparm,
     cron_restartp,
     cron_hascore,
+    cron_procstarted,
 };
 
 struct cronbnode {
@@ -275,6 +277,12 @@ cron_setstat(struct bnode *bn, afs_int32 astatus)
     return 0;
 }
 
+static int
+cron_procstarted(struct bnode *bn, struct bnode_proc *aproc)
+{
+    return 0;  /* no op */
+}
+
 static int
 cron_procexit(struct bnode *bn, struct bnode_proc *aproc)
 {
index b7916465e44e13036e326dfa5cb6e055e9e9e9d7..8a8494f391ea0a45e0958a767c61e582c8f64a52 100644 (file)
@@ -28,6 +28,7 @@
 #include "bnode.h"
 #include "bosprototypes.h"
 
+extern char *DoPidFiles;
 
 struct bnode *ez_create(char *, char *, char *, char *, char *, char *);
 static int ez_hascore(struct bnode *bnode);
@@ -39,6 +40,7 @@ static int ez_setstat(struct bnode *bnode, afs_int32 status);
 static int ez_procexit(struct bnode *bnode, struct bnode_proc *proc);
 static int ez_getstring(struct bnode *bnode, char *abuffer, afs_int32 alen);
 static int ez_getparm(struct bnode *bnode, afs_int32, char *, afs_int32);
+static int ez_procstarted(struct bnode *bnode, struct bnode_proc *proc);
 
 #define        SDTIME          60      /* time in seconds given to a process to evaporate */
 
@@ -53,6 +55,7 @@ struct bnode_ops ezbnode_ops = {
     ez_getparm,
     ez_restartp,
     ez_hascore,
+    ez_procstarted
 };
 
 static int
@@ -185,6 +188,17 @@ ez_setstat(struct bnode *bn, afs_int32 astatus)
     return 0;
 }
 
+static int
+ez_procstarted(struct bnode *bn, struct bnode_proc *aproc)
+{
+    int code = 0;
+
+    if (DoPidFiles) {
+       code = bozo_CreatePidFile(bn->name, NULL, aproc->pid);
+    }
+    return code;;
+}
+
 static int
 ez_procexit(struct bnode *bn, struct bnode_proc *aproc)
 {
@@ -193,6 +207,10 @@ ez_procexit(struct bnode *bn, struct bnode_proc *aproc)
     /* process has exited */
     afs_int32 code;
 
+    if (DoPidFiles) {
+       bozo_DeletePidFile(bn->name, NULL);
+    }
+
     abnode->waitingForShutdown = 0;
     abnode->running = 0;
     abnode->killSent = 0;
index a81374d7fcc8eba75e9a9481c367a079cfb0e230..285786179139bb5972f5d651877853108ef19c92 100644 (file)
@@ -35,6 +35,7 @@
 #include "bnode.h"
 #include "bosprototypes.h"
 
+extern char *DoPidFiles;
 static int emergency = 0;
 
 /* if this file exists, then we have to salvage the file system */
@@ -109,6 +110,7 @@ static int fs_delete(struct bnode *abnode);
 static int fs_timeout(struct bnode *abnode);
 static int fs_getstat(struct bnode *abnode, afs_int32 * astatus);
 static int fs_setstat(struct bnode *abnode, afs_int32 astatus);
+static int fs_procstarted(struct bnode *abnode, struct bnode_proc *aproc);
 static int fs_procexit(struct bnode *abnode, struct bnode_proc *aproc);
 static int fs_getstring(struct bnode *abnode, char *abuffer, afs_int32 alen);
 static int fs_getparm(struct bnode *abnode, afs_int32 aindex,
@@ -138,6 +140,7 @@ struct bnode_ops fsbnode_ops = {
     fs_getparm,
     fs_restartp,
     fs_hascore,
+    fs_procstarted,
 };
 
 /* demand attach fs bnode ops */
@@ -152,6 +155,7 @@ struct bnode_ops dafsbnode_ops = {
     dafs_getparm,
     fs_restartp,
     fs_hascore,
+    fs_procstarted,
 };
 
 /* Quick inline function to safely convert a fsbnode to a bnode without
@@ -711,6 +715,17 @@ fs_setstat(struct bnode *abnode, afs_int32 astatus)
     return NudgeProcs((struct fsbnode *) abnode);
 }
 
+static int
+fs_procstarted(struct bnode *bn, struct bnode_proc *aproc)
+{
+    int code = 0;
+
+    if (DoPidFiles) {
+       code = bozo_CreatePidFile(bn->name, aproc->coreName, aproc->pid);
+    }
+    return code;
+}
+
 static int
 fs_procexit(struct bnode *bn, struct bnode_proc *aproc)
 {
@@ -718,6 +733,10 @@ fs_procexit(struct bnode *bn, struct bnode_proc *aproc)
 
     /* process has exited */
 
+    if (DoPidFiles) {
+       bozo_DeletePidFile(bn->name, aproc->coreName);
+    }
+
     if (aproc == abnode->volProc) {
        abnode->volProc = 0;
        abnode->volRunning = 0;