struct ctdb_client *client;
};
+const char *ctdbd_pidfile = NULL;
+
static void daemon_incoming_packet(void *, struct ctdb_req_header *);
static void print_exit_message(void)
tdb_null, NULL, NULL);
}
+static void ctdb_remove_pidfile(void)
+{
+ if (ctdbd_pidfile != NULL && !ctdb_is_child_process()) {
+ if (unlink(ctdbd_pidfile) == 0) {
+ DEBUG(DEBUG_INFO, ("Removed PID file %s\n",
+ ctdbd_pidfile));
+ } else {
+ DEBUG(DEBUG_WARNING, ("Failed to Remove PID file %s\n",
+ ctdbd_pidfile));
+ }
+ }
+}
+
+static void ctdb_create_pidfile(pid_t pid)
+{
+ if (ctdbd_pidfile != NULL) {
+ FILE *fp;
+
+ fp = fopen(ctdbd_pidfile, "w");
+ if (fp == NULL) {
+ DEBUG(DEBUG_ALERT,
+ ("Failed to open PID file %s\n", ctdbd_pidfile));
+ exit(11);
+ }
+
+ fprintf(fp, "%d\n", pid);
+ fclose(fp);
+ DEBUG(DEBUG_INFO, ("Created PID file %s\n", ctdbd_pidfile));
+ atexit(ctdb_remove_pidfile);
+ }
+}
+
/*
start the protocol going as a daemon
*/
block_signal(SIGPIPE);
ctdb->ctdbd_pid = getpid();
-
-
+ ctdb_create_pidfile(ctdb->ctdbd_pid);
DEBUG(DEBUG_ERR, ("Starting CTDBD as pid : %u\n", ctdb->ctdbd_pid));
if (ctdb->do_setsched) {
{ "dbdir-persistent", 0, POPT_ARG_STRING, &options.db_dir_persistent, 0, "directory for persistent tdb files", NULL },
{ "dbdir-state", 0, POPT_ARG_STRING, &options.db_dir_state, 0, "directory for internal state tdb files", NULL },
{ "reclock", 0, POPT_ARG_STRING, &options.recovery_lock_file, 0, "location of recovery lock file", "filename" },
+ { "pidfile", 0, POPT_ARG_STRING, &ctdbd_pidfile, 0, "location of PID file", "filename" },
{ "valgrinding", 0, POPT_ARG_NONE, &options.valgrinding, 0, "disable setscheduler SCHED_FIFO call, use mmap for tdbs", NULL },
{ "nosetsched", 0, POPT_ARG_NONE, &options.nosetsched, 0, "disable setscheduler SCHED_FIFO call, use mmap for tdbs", NULL },
{ "syslog", 0, POPT_ARG_NONE, &options.use_syslog, 0, "log messages to syslog", NULL },