- fp = fopen(initfile, "w");
- if (fp == NULL) {
- display_error("Cannot create /etc/init.d/citadel");
- return;
- }
-
- fprintf(fp, "#!/bin/sh\n"
- "#\n"
- "# Init file for Citadel\n"
- "#\n"
- "# chkconfig: - 79 30\n"
- "# description: Citadel service\n"
- "# processname: citserver\n"
- "# pidfile: %s/citadel.pid\n\n"
- "# uncomment this to create coredumps as described in\n"
- "# http://www.citadel.org/doku.php/faq:mastering_your_os:gdb#how.do.i.make.my.system.produce.core-files\n"
- "# ulimit -c unlimited\n"
- "\n"
- "CITADEL_DIR=%s\n"
- ,
- ctdl_run_dir,
- ctdl_sbin_dir
- );
- fprintf(fp, "\n"
- "test -d /var/run || exit 0\n"
- "\n"
- "case \"$1\" in\n"
- "\n"
- "start) echo -n \"Starting Citadel... \"\n"
- " if $CITADEL_DIR/citserver -lmail -d\n"
- " then\n"
- " echo \"ok\"\n"
- " else\n"
- " echo \"failed\"\n"
- " fi\n");
- fprintf(fp, " ;;\n"
- "stop) echo -n \"Stopping Citadel... \"\n"
- " if $CITADEL_DIR/sendcommand DOWN >/dev/null 2>&1 ; then\n"
- " echo \"ok\"\n"
- " else\n"
- " echo \"failed\"\n"
- " fi\n"
- " rm -f %s/citadel.pid 2>/dev/null\n"
- ,
- ctdl_run_dir
- );
- fprintf(fp, " ;;\n"
- "restart) if $CITADEL_DIR/sendcommand DOWN 1 >/dev/null 2>&1 ; then\n"
- " echo \"ok\"\n"
- " else\n"
- " echo \"failed\"\n"
- " fi\n"
- " ;;\n"
- "*) echo \"Usage: $0 {start|stop|restart}\"\n"
- " exit 1\n"
- " ;;\n"
- "esac\n"
- );
-
- fclose(fp);
- chmod(initfile, 0755);
-
- /* Set up the run levels. */
- rv = system("/bin/rm -f /etc/rc?.d/[SK]??citadel 2>/dev/null");
- snprintf(command, sizeof(command), "for x in 2 3 4 5 ; do [ -d /etc/rc$x.d ] && ln -s %s /etc/rc$x.d/S79citadel ; done 2>/dev/null", initfile);
- rv = system(command);
- snprintf(command, sizeof(command),"for x in 0 6 S; do [ -d /etc/rc$x.d ] && ln -s %s /etc/rc$x.d/K30citadel ; done 2>/dev/null", initfile);
- rv = system(command);
-