// This is a supervisor program that handles start/stop/restart of
// the various Citadel System components, when we are running in
-// a Docker container.
+// a container.
//
// Copyright (c) 2021 by the citadel.org team
//
pid_t webcit_pid;
pid_t webcits_pid;
int shutting_down = 0;
+char *logging_flag = "-x1";
// Call this instead of exit() just for common diagnostics etc.
void ctdlvisor_exit(int code) {
pid_t pid = fork();
if (pid == 0) {
fprintf(stderr, "ctdlvisor: executing citserver\n");
- detach_from_tty();
- execlp("/usr/local/citadel/citserver", "citserver", "-x9", "-h", CTDL_DIR, NULL);
+ //detach_from_tty();
+ execlp("/usr/local/citadel/citserver", "citserver", logging_flag, "-h", CTDL_DIR, NULL);
exit(errno);
}
else {
pid_t pid = fork();
if (pid == 0) {
fprintf(stderr, "ctdlvisor: executing webcit (http)\n");
- detach_from_tty();
- execlp("/usr/local/webcit/webcit", "webcit", "-x9", "-p", "80", "uds", CTDL_DIR, NULL);
+ //detach_from_tty();
+ execlp("/usr/local/webcit/webcit", "webcit", logging_flag, "-p", "80", "uds", CTDL_DIR, NULL);
exit(errno);
}
else {
pid_t pid = fork();
if (pid == 0) {
fprintf(stderr, "ctdlvisor: executing webcit (https)\n");
- detach_from_tty();
- execlp("/usr/local/webcit/webcit", "webcit", "-x9", "-s", "-p", "443", "uds", CTDL_DIR, NULL);
+ //detach_from_tty();
+ execlp("/usr/local/webcit/webcit", "webcit", logging_flag, "-s", "-p", "443", "uds", CTDL_DIR, NULL);
exit(errno);
}
else {
int main(int argc, char **argv) {
int a;
int migrate_mode = 0;
+ int database_cleanup_mode = 0;
fprintf(stderr, "ctdlvisor: Welcome to the Citadel System running in a container.\n");
fprintf(stderr, "ctdlvisor: command line arguments: ");
symlink(CTDL_DIR "/keys", "/usr/local/webcit/keys");
/* parse command-line arguments */
- while ((a=getopt(argc, argv, "cm")) != EOF) switch(a) {
+ while ((a=getopt(argc, argv, "cmdx:")) != EOF) switch(a) {
// test this binary for compatibility and exit
case 'c':
migrate_mode = 1;
break;
+ // run database_cleanup.sh only
+ case 'd':
+ database_cleanup_mode = 1;
+ break;
+
+ // logging level
+ case 'x':
+ logging_flag = malloc(50);
+ snprintf(logging_flag, 50, "-x%d", atoi(optarg));
+ break;
+
// any other parameter makes it crash and burn
default:
- fprintf(stderr, "usage\n");
+ fprintf(stderr, "%s: usage: %s [-c] [-m] [-d] [-x log_level]\n");
exit(1);
}
kill(citserver_pid, SIGTERM);
}
+ // "database cleanup mode" means we just start the server and then run database_cleanup.sh interactively
+ else if (database_cleanup_mode) {
+ citserver_pid = start_citadel();
+ fprintf(stderr, "ctdlvisor: waiting a moment for citserver to initialize...\n");
+ sleep(5);
+ char bin[1024];
+ sprintf(bin, "/usr/local/citadel/database_cleanup.sh -h %s", CTDL_DIR);
+ system(bin);
+ kill(citserver_pid, SIGTERM);
+ }
+
// Otherwise, it's just a normal happy day in Citadel land.
else {
signal(SIGTERM, signal_handler);