From d0d99ccafbad60bca8aed5d29d072b3f31272ab0 Mon Sep 17 00:00:00 2001 From: Marcin Krol Date: Tue, 24 Oct 2017 22:54:29 +0000 Subject: [PATCH] - predefined functions for hook scripts --- hook.functions | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 hook.functions diff --git a/hook.functions b/hook.functions new file mode 100644 index 0000000..9b050d4 --- /dev/null +++ b/hook.functions @@ -0,0 +1,51 @@ +#!/bin/sh + +# concat file atomic way +atomic_concat() { + local file=$1; shift + > $file.new + chmod 600 $file.new + cat "$@" > $file.new + cp -f $file $file.dehydrated~ + mv -f $file.new $file +} + +lighttpd_reload() { + if [ ! -x /usr/sbin/lighttpd ] || [ ! -f /etc/lighttpd/server.pem ]; then + return + fi + + echo " + Hook: Overwritting /etc/lighttpd/server.pem and reloading lighttpd..." + atomic_concat /etc/lighttpd/server.pem "$FULLCHAINCERT" "$PRIVKEY" + /sbin/service lighttpd reload +} + +haproxy_reload() { + if [ ! -x /usr/sbin/haproxy ] || [ ! -f /etc/haproxy/server.pem ]; then + return + fi + + echo " + Hook: Overwritting /etc/haproxy/server.pem and restarting haproxy..." + atomic_concat /etc/haproxy/server.pem "$FULLCHAINCERT" "$PRIVKEY" + /sbin/service haproxy reload +} + +nginx_reload() { + if [ ! -f /etc/nginx/server.crt ] || [ ! -f /etc/nginx/server.key ]; then + return + fi + + echo " + Hook: Overwritting /etc/nginx/server.{crt,key} and reloading nginx..." + atomic_concat /etc/nginx/server.crt "$FULLCHAINCERT" + atomic_concat /etc/nginx/server.key "$PRIVKEY" + /sbin/service nginx reload +} + +httpd_reload() { + if [ ! -x /etc/rc.d/init.d/httpd ]; then + return + fi + + echo " + Hook: Reloading Apache..." + /sbin/service httpd graceful +} -- 2.46.0