From cc171c3917d410d4ca95bf305a9f247378fdbb2f Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Thu, 1 Jun 2023 18:11:20 -0400 Subject: automatic apache configuration of fossil reverse proxy for virtual host of local hostname --- Makefile | 3 ++- src/fossil-disable-apache@.service | 9 +++++++++ src/fossil-enable-apache@.service | 14 ++++++++++++++ src/fossil.conf~template | 10 ++++++++++ src/user/fossil-httpd@.service | 2 +- 5 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 src/fossil-disable-apache@.service create mode 100644 src/fossil-enable-apache@.service create mode 100644 src/fossil.conf~template diff --git a/Makefile b/Makefile index da5a2bf..def9421 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -systemctl_start_units = fossil-user.socket +systemctl_start_units = fossil-user.socket fossil-enable-apache@-.service systemctl_user_start_units = fossil-httpd.socket ifneq (0,$(shell id -u)) @@ -56,6 +56,7 @@ SSH_USERNAME != if [ "$$SUDO_USER" ]; then echo "$$SUDO_USER"; else id -u; fi default: install start follow install: install -t "$(bindir)" -- $(executables) + install -m644 -t /etc/apache2/sites-available -- src/fossil.conf~template install -t /etc/ssh/ -- src/AuthorizedKeysCommand install -T -- src/AnonymousForceCommand /etc/ssh/user-"$(SSH_USERNAME)".AnonymousForceCommand install -m644 -t /etc/ssh/sshd_config.d -- src/fossil-user.conf diff --git a/src/fossil-disable-apache@.service b/src/fossil-disable-apache@.service new file mode 100644 index 0000000..4d763e0 --- /dev/null +++ b/src/fossil-disable-apache@.service @@ -0,0 +1,9 @@ +[Unit] +Description = Disable and clean up apache site + +[Service] +Type = oneshot +ExecStart = sh -xc 'rm -f \ +/etc/apache2/sites-available/fossil-%H.conf \ +/etc/apache2/sites-enabled/fossil-%H.conf' +ExecStart = systemctl reload apache2 diff --git a/src/fossil-enable-apache@.service b/src/fossil-enable-apache@.service new file mode 100644 index 0000000..d90a36f --- /dev/null +++ b/src/fossil-enable-apache@.service @@ -0,0 +1,14 @@ +[Unit] +Description = Create and enable apache2 site +ConditionPathExists = /etc/apache2/sites-available/fossil.conf~template +ConditionPathExists = !/etc/apache2/sites-available/fossil-%H.conf + +[Service] +Type = oneshot +ExecStart = sh -c '\ +sed -e s/%[H]/%H/ \ +< /etc/apache2/sites-available/fossil.conf~template \ +> /etc/apache2/sites-available/fossil-%H.conf \ +' +ExecStart = a2ensite fossil-%H +ExecStart = systemctl reload apache2 diff --git a/src/fossil.conf~template b/src/fossil.conf~template new file mode 100644 index 0000000..797f5e2 --- /dev/null +++ b/src/fossil.conf~template @@ -0,0 +1,10 @@ + + ServerName %H + ServerAdmin webmaster@%H + ErrorLog ${APACHE_LOG_DIR}/error.log + CustomLog ${APACHE_LOG_DIR}/access.log combined + DocumentRoot /var/www/html + ProxyPreserveHost on + ProxyPass / http://localhost:8079/ + ProxyPassReverse / http://localhost:8079/ + diff --git a/src/user/fossil-httpd@.service b/src/user/fossil-httpd@.service index eccc17c..9c4aec5 100644 --- a/src/user/fossil-httpd@.service +++ b/src/user/fossil-httpd@.service @@ -4,4 +4,4 @@ ConditionUser = !root [Service] StandardInput = socket -ExecStart = fossil http --repolist --nossl --host=localhost:8079 --localauth ${HOME}/src/ +ExecStart = fossil http --repolist --nossl --host=%H --localauth ${HOME}/src/ -- cgit v1.2.3