add new option
[basic-https-conf] / web-conf
index 0e06cdf8bab5bc55a09330614dc843cc6a38decc..eb87f17d93670d7b8903495dfebb5eff99c58531 100755 (executable)
--- a/web-conf
+++ b/web-conf
@@ -1,17 +1,21 @@
 #!/bin/bash
-# Copyright (C) 2016 Ian Kelling
+# This file is part of web-conf which configures web servers
+# Copyright (C) 2024  Ian Kelling
 
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
 
-#     http://www.apache.org/licenses/LICENSE-2.0
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
 
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# SPDX-License-Identifier: GPL-3.0-or-later
 
 [[ $EUID == 0 ]] || exec sudo -E "$BASH_SOURCE" "$@"
 
@@ -49,6 +53,9 @@ EXTRA_SETTINGS_FILE can be - for stdin
                   which is root@$(hostname --fqdn) on this host.
 -f [ADDR:]PORT    Enable proxy to [ADDR:]PORT. ADDR default is 127.0.0.1
 -i                Insecure, no ssl.
+-l                Allow failure of restarting apache/nginx. Useful for scripts where
+                  we want to do the configuration, but don't mind if the web
+                  server has some preexisting problem or other problem to fix later.
 -p PORT           Main port to listen on, default 443. 80 implies -i.
 -r DIR            DocumentRoot
 -s                Allow symlinks from the doucment root
@@ -67,8 +74,9 @@ ssl=true
 extra_settings=
 port=443
 do_root_settings=true
-temp=$(getopt -l help a:c:e:if:p:r:sth "$@") || usage 1
+temp=$(getopt -l help a:c:e:if:lp:r:sth "$@") || usage 1
 vhostip='*'
+allow_server_fail=false
 eval set -- "$temp"
 while true; do
   case $1 in
@@ -80,6 +88,7 @@ while true; do
     -e) email="$2"; shift 2 ;;
     -f) proxy="$2"; shift 2 ;;
     -i) ssl=false; shift ;;
+    -l) allow_server_fail=true; shift ;;
     -p) port="$2"; shift 2 ;;
     -r) root="$2"; shift 2 ;;
     -t) do_root_settings=false; shift ;;
@@ -346,7 +355,14 @@ EOF
 
 
   a2enmod -q ssl rewrite # rewrite needed for httpredir
-  service apache2 restart
+
+  if $allow_server_fail; then
+    if ! service apache2 restart; then
+      echo "$0: warning: apache2 restart failed. ignoring due to -l flag" >&2
+    fi
+  else
+    service apache2 restart
+  fi
 
   # I rarely look at how much traffic I get, so let's keep that info
   # around for longer than the default of 2 weeks.
@@ -458,7 +474,13 @@ EOF
 EOF
 
 
-  service nginx restart
+  if $allow_server_fail; then
+    if ! service nginx restart; then
+      echo "$0: warning: nginx restart failed. ignoring due to -l flag" >&2
+    fi
+  else
+    service nginx restart
+  fi
 
 fi ####### end if nginx