From e225e9973fd5609d926b61a58d92a95002dcfe1d Mon Sep 17 00:00:00 2001 From: Steffen Volkmann Date: Sun, 6 Oct 2019 15:43:34 +0200 Subject: [PATCH] run.sh: integrate handling for tirex daemon Implements issue67 --- run.sh | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/run.sh b/run.sh index 3f6c9a3..c9a5a34 100755 --- a/run.sh +++ b/run.sh @@ -2,6 +2,8 @@ set -x +STOP_CONT="no" + function createPostgresConfig() { cp /etc/postgresql/10/main/postgresql.custom.conf.tmpl /etc/postgresql/10/main/postgresql.custom.conf sudo -u postgres echo "autovacuum = $AUTOVACUUM" >> /etc/postgresql/10/main/postgresql.custom.conf @@ -12,6 +14,39 @@ function setPostgresPassword() { sudo -u postgres psql -c "ALTER USER renderer PASSWORD '${PGPASSWORD:-renderer}'" } + +# handler for term signal +function sighandler_TERM() { + echo "signal SIGTERM received\n" + + echo "terminate apache2" + service apache2 stop + + PID=`ps -eaf | grep renderd | grep -v grep | awk '{print $2}'` + if [[ "" != "$PID" ]]; then + echo "send SIGTERM to renderd PID=$PID" + kill -n 15 $PID + fi + + PID=`ps -eaf | grep tirex-master | grep -v grep | awk '{print $2}'` + if [[ "" != "$PID" ]]; then + echo "send SIGTERM to tirex-master PID=$PID" + kill -n 15 $PID + fi + + PID=`ps -eaf | grep tirex-backend-manager | grep -v grep | awk '{print $2}'` + if [[ "" != "$PID" ]]; then + echo "send SIGTERM to tirex-backend-manager PID=$PID" + kill -n 15 $PID + fi + + echo "terminate postgresql" + service postgresql stop + + STOP_CONT="yes" +} + + if [ "$#" -ne 1 ]; then echo "usage: " echo "commands:" @@ -20,6 +55,7 @@ if [ "$#" -ne 1 ]; then echo "environment variables:" echo " THREADS: defines number of threads used for importing / tile rendering" echo " UPDATES: consecutive updates (enabled/disabled)" + echo " RENDERERAPP: select render application renderd (default) or tirex" exit 1 fi @@ -67,6 +103,9 @@ if [ "$1" = "import" ]; then fi if [ "$1" = "run" ]; then + # add handler for signal SIHTERM + trap 'sighandler_TERM' 15 + # Clean /tmp rm -rf /tmp/* @@ -92,9 +131,22 @@ if [ "$1" = "run" ]; then /etc/init.d/cron start fi - # Run - sudo -u renderer renderd -f -c /usr/local/etc/renderd.conf - service postgresql stop + if [ "$RENDERERAPP" = "renderd" ]; then + # start renderd + sudo -u renderer renderd -f -c /usr/local/etc/renderd.conf & + + elif [ "$RENDERERAPP" = "tirex" ]; then + # start tirex + sudo -u renderer tirex-backend-manager -f & + sudo -u renderer tirex-master -d -f & + else + echo "RENDERERAPP not valid use renderd or tirex" + fi + + echo "wait for terminate signal" + while [ "$STOP_CONT" = "no" ] ; do + sleep 1 + done exit 0 fi