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"));
47 printf("Executing %s\n", bin);
48 execlp(bin, "webcit", "-x9", "-p80", "uds", "/usr/local/citadel", NULL);
58 pid_t start_webcits() {
60 sprintf(bin, "%s/usr/local/webcit/webcit", getenv("APPDIR"));
63 printf("Executing %s\n", bin);
64 execlp(bin, "webcit", "-x9", "-s", "-p443", "uds", "/usr/local/citadel", NULL);
78 pid_t citserver_pid = start_citadel();
79 pid_t webcit_pid = start_webcit();
80 pid_t webcits_pid = start_webcits();
83 printf("LD_LIBRARY_PATH = %s\n", getenv("LD_LIBRARY_PATH"));
84 printf("PATH = %s\n", getenv("PATH"));
85 printf("APPDIR = %s\n", getenv("APPDIR"));
87 printf("waiting...\n");
88 who_exited = waitpid(-1, &status, 0);
89 printf("pid=%d exited, status=%d\n", who_exited, status);
91 if (who_exited == citserver_pid) {
92 if (WEXITSTATUS(status) == 0) {
93 printf("ctdlvisor: citserver exited normally - ending AppImage session\n");
96 citserver_pid = start_citadel();
99 if (who_exited == webcit_pid) webcit_pid = start_webcit();
100 if (who_exited == webcits_pid) webcits_pid = start_webcits();
102 sleep(1); // slow down any accidental loops
104 } while (who_exited >= 0);
106 printf("ctdlvisor: exiting.\n");