dout_dir: INSTALL_PREFIX "/var/log/ceph", // if daemonize == true
dout_sym_dir: INSTALL_PREFIX "/var/log/ceph", // if daemonize == true
logger_dir: INSTALL_PREFIX "/var/log/ceph/stat",
+ pid_file: 0,
+
conf_file: INSTALL_PREFIX "/etc/ceph/ceph.conf",
dump_conf: false,
debug_after: 0,
// -- misc --
- use_abspaths: false, // make monitorstore et al use absolute path (to workaround FUSE chdir("/"))
+ use_abspaths: false, // make monitorstore et al use absolute path (to workaround FUSE chdir("/"))
// --- clock ---
clock_lock: false,
CF_READ_STR("global", "dout dir", dout_dir);
CF_READ_STR("global", "dout sym dir", dout_sym_dir);
CF_READ_STR("global", "logger dir", logger_dir);
+ CF_READ_STR("global", "pid file", pid_file);
CF_READ("debug", "debug", debug);
CF_READ("debug", "lockdep", debug_lockdep);
//else if (strcmp(args[i], "--fake_osd_sync") == 0)
//g_conf.fake_osd_sync = atoi(args[++i]);
-
-
+
else if (strcmp(args[i], "--dout_dir") == 0 && isarg)
g_conf.dout_dir = args[++i];
else if (//strcmp(args[i], "-o") == 0 ||
g_conf.dout_sym_dir = args[++i];
else if (strcmp(args[i], "--logger_dir") == 0 && isarg)
g_conf.logger_dir = args[++i];
+ else if ((strcmp(args[i], "--pid_file") == 0 ||
+ strcmp(args[i], "-p") == 0) && isarg)
+ g_conf.pid_file = args[++i];
else if (strcmp(args[i], "--conf_file") == 0 && isarg)
g_conf.conf_file = args[++i];
}
};
+
+static void write_pid_file(int pid)
+{
+ if (!g_conf.pid_file)
+ return;
+
+ int fd = ::open(g_conf.pid_file, O_CREAT|O_TRUNC|O_WRONLY, 0644);
+ if (fd >= 0) {
+ char buf[20];
+ int len = sprintf(buf, "%d\n", pid);
+ ::write(fd, buf, len);
+ ::close(fd);
+ }
+}
+
+static void remove_pid_file()
+{
+ if (!g_conf.pid_file)
+ return;
+
+ // only remove it if it has OUR pid in it!
+ int fd = ::open(g_conf.pid_file, O_RDONLY);
+ if (fd >= 0) {
+ char actual[20], correct[20];
+ sprintf(correct, "%d\n", getpid());
+ ::read(fd, actual, 20);
+ ::close(fd);
+
+ if (strncmp(actual, correct, 20) == 0)
+ ::unlink(g_conf.pid_file);
+ }
+}
+
int Rank::start(bool nodaemon)
{
// register at least one entity, first!
<< dendl;
}
dout(1) << "rank.start daemonizing" << dendl;
- daemon(1, 0); /* fixme.. we should chdir(/) too! */
+
+ // be polite
+ if (g_conf.use_abspaths)
+ ::chdir("/");
+
+ pid_t child = fork();
+ if (child) {
+ write_pid_file(child);
+ _exit(0);
+ }
+
_dout_rename_output_file();
+ } else {
+ write_pid_file(getpid());
}
// some debug hackery?
dout(10) << "wait: done." << dendl;
dout(1) << "shutdown complete." << dendl;
+ remove_pid_file();
started = false;
my_type = -1;
}