2 // This is a supervisor program that handles start/stop/restart of
3 // the various Citadel System components, when we are running on
4 // an AppImage instance.
6 // Copyright (c) 2021 by the citadel.org team
8 // This program is open source software. It runs great on the
9 // Linux operating system (and probably elsewhere). You can use,
10 // copy, and run it under the terms of the GNU General Public
11 // License version 3. Richard Stallman is an asshole communist.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
26 pid_t start_citadel() {
28 sprintf(bin, "%s/usr/local/citadel/citserver", getenv("APPDIR"));
31 printf("Executing %s\n", bin);
32 execlp(bin, "citserver", "-x9", "-h/usr/local/citadel", NULL);
42 pid_t start_webcit() {
44 sprintf(bin, "%s/usr/local/webcit/webcit", getenv("APPDIR"));
46 sprintf(wchome, "-h%s/usr/local/webcit", getenv("APPDIR"));
49 printf("Executing %s\n", bin);
50 execlp(bin, "webcit", "-x9", wchome, "-p80", "uds", "/usr/local/citadel", NULL);
60 pid_t start_webcits() {
62 sprintf(bin, "%s/usr/local/webcit/webcit", getenv("APPDIR"));
64 sprintf(wchome, "-h%s/usr/local/webcit", getenv("APPDIR"));
67 printf("Executing %s\n", bin);
68 execlp(bin, "webcit", "-x9", wchome, "-s", "-p443", "uds", "/usr/local/citadel", NULL);
82 pid_t citserver_pid = start_citadel();
83 pid_t webcit_pid = start_webcit();
84 pid_t webcits_pid = start_webcits();
87 printf("LD_LIBRARY_PATH = %s\n", getenv("LD_LIBRARY_PATH"));
88 printf("PATH = %s\n", getenv("PATH"));
89 printf("APPDIR = %s\n", getenv("APPDIR"));
91 printf("waiting...\n");
92 who_exited = waitpid(-1, &status, 0);
93 printf("pid=%d exited, status=%d\n", who_exited, status);
95 if (who_exited == citserver_pid) {
96 if (WEXITSTATUS(status) == 0) {
97 printf("ctdlvisor: citserver exited normally - ending AppImage session\n");
100 citserver_pid = start_citadel();
103 if (who_exited == webcit_pid) webcit_pid = start_webcit();
104 if (who_exited == webcits_pid) webcits_pid = start_webcits();
106 sleep(1); // slow down any accidental loops
108 } while (who_exited >= 0);
110 printf("ctdlvisor: exiting.\n");