From 3665a9131c4f0bac07727a5f908905e9a6348535 Mon Sep 17 00:00:00 2001 From: Ondrej Kubik Date: Sat, 4 Nov 2017 19:20:37 +0000 Subject: splitting hooks and using snapctl instead of local settings file Signed-off-by: Ondrej Kubik --- snap/hooks/configure | 28 +++------------------------- snap/hooks/install | 12 ++++++++++++ snap/hooks/post-refresh | 1 + 3 files changed, 16 insertions(+), 25 deletions(-) create mode 100755 snap/hooks/install create mode 120000 snap/hooks/post-refresh (limited to 'snap/hooks') diff --git a/snap/hooks/configure b/snap/hooks/configure index 1e2b0ec7..60ce81e8 100755 --- a/snap/hooks/configure +++ b/snap/hooks/configure @@ -1,32 +1,10 @@ #!/bin/bash +exec >> $SNAP_COMMON/hook.log 2>&1 +echo "$(date '+%Y-%m-%d %H:%M:%S') $0: Entering hook" + # read wekan config . $SNAP/bin/config -# create run dir, we're going to use it for unix socket -mkdir -p $SNAP_DATA/share -mkdir -p $SNAP_DATA/shared - # settings were altered by user, safest way to get them applied is to restart service -# TODO: remove this workaround once it's not needed -# for the moment we can't read settings outside of the hook, -# so store all settings in helpper script which is then picked by main wrapper -echo -e "#!/bin/sh\n" > $SETTINGS_FILE -for key in ${keys[@]} -do - # snappy is picky about key syntax, using mapping - MAP_KEY="KEY_$key" - if value=$(snapctl get ${!MAP_KEY}); then - echo "export $key='$value'" >> $SETTINGS_FILE - elif [ -d "${!key}" ]; then - # store back value from SETTINGS_FILE - echo "export $key='${!key}'" >> $SETTINGS_FILE - fi -done - -# set file executable -chmod 755 $SETTINGS_FILE -# we can't use snapctl to restart service, may be one day .... - -echo "Setting has been updated, restart service." diff --git a/snap/hooks/install b/snap/hooks/install new file mode 100755 index 00000000..14087eaa --- /dev/null +++ b/snap/hooks/install @@ -0,0 +1,12 @@ +#!/bin/bash + +exec >> $SNAP_COMMON/hook.log 2>&1 +echo "$(date '+%Y-%m-%d %H:%M:%S') $0: Entering hook" + +# coppy caddy file in place +[ ! -e $SNAP_COMMON/Caddyfile ] && cp $SNAP/Caddyfile $SNAP_COMMON/Caddyfile + +# create run dir, we're going to use it for unix socket +mkdir -p $SNAP_DATA/share +mkdir -p $SNAP_DATA/shared + diff --git a/snap/hooks/post-refresh b/snap/hooks/post-refresh new file mode 120000 index 00000000..f7ffc47a --- /dev/null +++ b/snap/hooks/post-refresh @@ -0,0 +1 @@ +install \ No newline at end of file -- cgit v1.2.3-1-g7c22 From e077c85d003fb3cfd837ad8064ade767fa8fe04f Mon Sep 17 00:00:00 2001 From: Ondrej Kubik Date: Sat, 4 Nov 2017 19:23:28 +0000 Subject: Adding caddy support Signed-off-by: Ondrej Kubik --- snap/hooks/configure | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'snap/hooks') diff --git a/snap/hooks/configure b/snap/hooks/configure index 60ce81e8..fd18da33 100755 --- a/snap/hooks/configure +++ b/snap/hooks/configure @@ -7,4 +7,16 @@ echo "$(date '+%Y-%m-%d %H:%M:%S') $0: Entering hook" . $SNAP/bin/config # settings were altered by user, safest way to get them applied is to restart service +# first check if caddy service is enabled +value=$(snapctl get caddy-enabled) +if [ "$value" = "true" ]; then + # update caddy file + bind_port=$(snapctl get caddy-bind-port) + port=$(snapctl get port) + [ "x" != "x${bind_port}" ] && sed -i 's|proxy / localhost:.* {|proxy / localhost:'"${bind_port}"' {|g' $SNAP_COMMON/Caddyfile + [ "x" != "x$port" ] && sed -i 's|http://:.*|http://:'"${port}"'|g' $SNAP_COMMON/Caddyfile + snapctl start caddy-service 2>&1 || true +else + snapctl stop caddy-service 2>&1 || true +fi -- cgit v1.2.3-1-g7c22 From d7ea73ff8287d69583b74f779470fce6d34f30db Mon Sep 17 00:00:00 2001 From: Ondrej Kubik Date: Sat, 4 Nov 2017 19:24:06 +0000 Subject: adding uspport for snapctl restart Signed-off-by: Ondrej Kubik --- snap/hooks/configure | 3 +++ 1 file changed, 3 insertions(+) (limited to 'snap/hooks') diff --git a/snap/hooks/configure b/snap/hooks/configure index fd18da33..15d68a19 100755 --- a/snap/hooks/configure +++ b/snap/hooks/configure @@ -20,3 +20,6 @@ else snapctl stop caddy-service 2>&1 || true fi +# restart mongo and wekan service +snapctl restart mongodb 2>&1 || true +snapctl restart wekan 2>&1 || true -- cgit v1.2.3-1-g7c22 From 9c9694bcd127810cf37667bc3ddc9ef7558996d3 Mon Sep 17 00:00:00 2001 From: Ondrej Kubik Date: Wed, 6 Dec 2017 14:49:18 +0000 Subject: Fixing snapctl start/stop to control service lifecycle Adding disable and enable options for snapctl start/stop Signed-off-by: Ondrej Kubik --- snap/hooks/configure | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'snap/hooks') diff --git a/snap/hooks/configure b/snap/hooks/configure index 15d68a19..b215cc85 100755 --- a/snap/hooks/configure +++ b/snap/hooks/configure @@ -15,11 +15,10 @@ if [ "$value" = "true" ]; then port=$(snapctl get port) [ "x" != "x${bind_port}" ] && sed -i 's|proxy / localhost:.* {|proxy / localhost:'"${bind_port}"' {|g' $SNAP_COMMON/Caddyfile [ "x" != "x$port" ] && sed -i 's|http://:.*|http://:'"${port}"'|g' $SNAP_COMMON/Caddyfile - snapctl start caddy-service 2>&1 || true + snapctl start --enable ${SNAP_NAME}.caddy 2>&1 || true else - snapctl stop caddy-service 2>&1 || true + snapctl stop --disable ${SNAP_NAME}.caddy 2>&1 || true fi -# restart mongo and wekan service -snapctl restart mongodb 2>&1 || true -snapctl restart wekan 2>&1 || true +# restart all services +snapctl restart ${SNAP_NAME} 2>&1 || true -- cgit v1.2.3-1-g7c22 From ff320f7b3a40072de641dcdcab935c69f6f8584a Mon Sep 17 00:00:00 2001 From: Ondrej Kubik Date: Wed, 6 Dec 2017 17:50:39 +0000 Subject: enabling verbose logging from configure hook Signed-off-by: Ondrej Kubik --- snap/hooks/configure | 2 ++ 1 file changed, 2 insertions(+) (limited to 'snap/hooks') diff --git a/snap/hooks/configure b/snap/hooks/configure index b215cc85..5d121e15 100755 --- a/snap/hooks/configure +++ b/snap/hooks/configure @@ -3,6 +3,8 @@ exec >> $SNAP_COMMON/hook.log 2>&1 echo "$(date '+%Y-%m-%d %H:%M:%S') $0: Entering hook" +set -x + # read wekan config . $SNAP/bin/config -- cgit v1.2.3-1-g7c22