rse 98/06/10 05:08:52
Modified: src CHANGES src/main http_main.c src/support httpd.8 apachectl apachectl.1 Log: Add httpd -t (test) option for running configuration syntax tests only. If something is broken it complains and exits with a return code non-equal to 0. This can be used manually by the user to check the Apache configuration after editing and is also automatically used by apachectl on (graceful) restart command to make sure Apache doesn't die on restarts because of a configuration which is now broken since the last (re)start. This way `apachectl restart' can be used inside cronjobs without having to expect Apache to be falling down. Additionally the httpd -t can be run via `apachectl configtest'. Submitted by: Ralf S. Engelschall Reviewed by: Martin Kraemer, Brian Behlendorf, Jim Jagielski, Dean Gaudet PR: 2393 Revision Changes Path 1.909 +11 -0 apache-1.3/src/CHANGES Index: CHANGES =================================================================== RCS file: /export/home/cvs/apache-1.3/src/CHANGES,v retrieving revision 1.908 retrieving revision 1.909 diff -u -r1.908 -r1.909 --- CHANGES 1998/06/10 11:28:47 1.908 +++ CHANGES 1998/06/10 12:08:47 1.909 @@ -1,5 +1,16 @@ Changes with Apache 1.3.1 + *) Add httpd -t (test) option for running configuration syntax tests only. + If something is broken it complains and exits with a return code + non-equal to 0. This can be used manually by the user to check the Apache + configuration after editing and is also automatically used by apachectl + on (graceful) restart command to make sure Apache doesn't die on restarts + because of a configuration which is now broken since the last (re)start. + This way `apachectl restart' can be used inside cronjobs without having + to expect Apache to be falling down. Additionally the httpd -t can be run + via `apachectl configtest'. + [Ralf S. Engelschall] PR#2393 + *) Minor display fix for "install" target of top-level Makefile: the displayed installation command was incorrect although the executed command was correct. Now they are in sync. 1.364 +23 -3 apache-1.3/src/main/http_main.c Index: http_main.c =================================================================== RCS file: /export/home/cvs/apache-1.3/src/main/http_main.c,v retrieving revision 1.363 retrieving revision 1.364 diff -u -r1.363 -r1.364 --- http_main.c 1998/06/10 11:23:11 1.363 +++ http_main.c 1998/06/10 12:08:49 1.364 @@ -877,7 +877,7 @@ fprintf(stderr, "Usage: %s [-d directory] [-f file]\n", bin); #endif fprintf(stderr, " %s [-C \"directive\"] [-c \"directive\"]\n", pad); - fprintf(stderr, " %s [-v] [-V] [-h] [-l] [-S]\n", pad); + fprintf(stderr, " %s [-v] [-V] [-h] [-l] [-S] [-t]\n", pad); fprintf(stderr, "Options:\n"); #ifdef SHARED_CORE fprintf(stderr, " -L directory : specify an alternate location for shared object files\n"); @@ -891,6 +891,7 @@ fprintf(stderr, " -h : list available configuration directives\n"); fprintf(stderr, " -l : list compiled-in modules\n"); fprintf(stderr, " -S : show parsed settings (currently only vhost settings)\n"); + fprintf(stderr, " -t : run syntax test for configuration files only\n"); exit(1); } @@ -4201,6 +4202,7 @@ int REALMAIN(int argc, char *argv[]) { int c; + int configtestonly = 0; #ifdef SecureWare if (set_auth_parameters(argc, argv) < 0) @@ -4227,7 +4229,7 @@ ap_setup_prelinked_modules(); while ((c = getopt(argc, argv, - "C:c:Xd:f:vVhlL:S" + "C:c:Xd:f:vVhlL:St" #ifdef DEBUG_SIGSTOP "Z:" #endif @@ -4283,6 +4285,9 @@ case 'S': ap_dump_settings = 1; break; + case 't': + configtestonly = 1; + break; case '?': usage(argv[0]); } @@ -4291,6 +4296,11 @@ ap_suexec_enabled = init_suexec(); server_conf = ap_read_config(pconf, ptrans, ap_server_confname); + if (configtestonly) { + fprintf(stderr, "Syntax OK\n"); + exit(0); + } + child_timeouts = !ap_standalone || one_process; if (ap_standalone) { @@ -5356,6 +5366,7 @@ char *cp; int run_as_service = 1; int install = 0; + int configtestonly = 0; common_init(); @@ -5380,7 +5391,7 @@ ap_setup_prelinked_modules(); - while ((c = getopt(argc, argv, "C:c:Xd:f:vVhlZ:iusS")) != -1) { + while ((c = getopt(argc, argv, "C:c:Xd:f:vVhlZ:iusSt")) != -1) { char **new; switch (c) { case 'c': @@ -5438,6 +5449,9 @@ case 'X': ++one_process; /* Weird debugging mode. */ break; + case 't': + configtestonly = 1; + break; case '?': usage(argv[0]); } @@ -5448,6 +5462,12 @@ } server_conf = ap_read_config(pconf, ptrans, ap_server_confname); + + if (configtestonly) { + fprintf(stderr, "Syntax OK\n"); + exit(0); + } + if (!child) { ap_log_pid(pconf, ap_pid_fname); } 1.10 +5 -0 apache-1.3/src/support/httpd.8 Index: httpd.8 =================================================================== RCS file: /export/home/cvs/apache-1.3/src/support/httpd.8,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- httpd.8 1998/05/12 11:14:31 1.9 +++ httpd.8 1998/06/10 12:08:51 1.10 @@ -149,6 +149,11 @@ Show the settings as parsed from the config file (currently only shows the virtualhost settings). .TP +.B \-t +Run syntax tests for configuration files only. The program immediately exits +after these syntax parsing with either a return code of 0 (Syntax OK) or +return code not equal to 0 (Syntax Error). +.TP .B \-X Run in single-process mode, for internal debugging purposes only; the daemon does not detach from the terminal or fork any children. Do NOT use this mode 1.7 +28 -7 apache-1.3/src/support/apachectl Index: apachectl =================================================================== RCS file: /export/home/cvs/apache-1.3/src/support/apachectl,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- apachectl 1998/03/31 12:53:46 1.6 +++ apachectl 1998/06/10 12:08:51 1.7 @@ -12,6 +12,7 @@ # 5 - httpd could not be started during a restart # 6 - httpd could not be restarted during a restart # 7 - httpd could not be restarted during a graceful restart +# 8 - configuration syntax error # # When multiple arguments are given, only the error from the _last_ # one is reported. Run "apachectl help" for usage info @@ -97,10 +98,16 @@ ERROR=5 fi else - if kill -HUP $PID ; then - echo "$0 $ARG: httpd restarted" + if $HTTPD -t >/dev/null 2>&1; then + if kill -HUP $PID ; then + echo "$0 $ARG: httpd restarted" + else + echo "$0 $ARG: httpd could not be restarted" + ERROR=6 + fi else - echo "$0 $ARG: httpd could not be restarted" + echo "$0 $ARG: configuration broken, ignoring restart" + echo "$0 $ARG: (run 'apachectl configtest' for details)" ERROR=6 fi fi @@ -115,10 +122,16 @@ ERROR=5 fi else - if kill -USR1 $PID ; then - echo "$0 $ARG: httpd gracefully restarted" + if $HTTPD -t >/dev/null 2>&1; then + if kill -USR1 $PID ; then + echo "$0 $ARG: httpd gracefully restarted" + else + echo "$0 $ARG: httpd could not be restarted" + ERROR=7 + fi else - echo "$0 $ARG: httpd could not be restarted" + echo "$0 $ARG: configuration broken, ignoring restart" + echo "$0 $ARG: (run 'apachectl configtest' for details)" ERROR=7 fi fi @@ -129,8 +142,15 @@ fullstatus) $LYNX $STATUSURL ;; + configtest) + if $HTTPD -t; then + : + else + ERROR=8 + fi + ;; *) - echo "usage: $0 (start|stop|restart|fullstatus|status|graceful|help)" + echo "usage: $0 (start|stop|restart|fullstatus|status|graceful|configtest|help)" cat <<EOF start - start httpd @@ -140,6 +160,7 @@ fullstatus - dump a full status screen; requires lynx and mod_status enabled status - dump a short status screen; requires lynx and mod_status enabled graceful - do a graceful restart by sending a SIGUSR1 or start if not running +configtest - do a configuration syntax test help - this screen EOF 1.5 +14 -3 apache-1.3/src/support/apachectl.1 Index: apachectl.1 =================================================================== RCS file: /export/home/cvs/apache-1.3/src/support/apachectl.1,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- apachectl.1 1998/03/31 12:53:46 1.4 +++ apachectl.1 1998/06/10 12:08:51 1.5 @@ -92,6 +92,9 @@ .BI restart Restarts the Apache daemon by sending it a SIGHUP. If the daemon is not running, it is started. +This command automatically checks the configuration files via +.BI configtest +before initiating the restart to make sure Apache doesn't die. .TP .BI fullstatus Displays a full status report from @@ -111,9 +114,17 @@ the daemon is not running, it is started. This differs from a normal restart in that currently open connections are not aborted. A side effect is that old log files will not be closed immediately. -This means that if used in a log rotation script, a substantial -delay may be necessary to ensure that the old log files are closed -before processing them. +This means that if used in a log rotation script, a substantial delay may be +necessary to ensure that the old log files are closed before processing them. +This command automatically checks the configuration files via +.BI configtest +before initiating the restart to make sure Apache doesn't die. +.TP +.BI configtest +Run a configuration file syntax test. It parses the configuration +files and either reports +.B "Syntax Ok" +or detailed information about the particular syntax error. .TP .BI help Displays a short help message.