From 4953c508a4ee7f0d815ad5bffc30c499ac90df54 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 28 Jun 2023 15:52:19 +0000 Subject: [PATCH] Modified start_service to use timeouts and start script with alert --- bin/start | 3 ++- bin/upgrade | 2 +- lib/baserow.sh | 2 +- lib/caddy.sh | 4 ++-- lib/collabora.sh | 2 +- lib/element.sh | 2 +- lib/functions.sh | 9 ++------- lib/gitea.sh | 2 +- lib/jitsi.sh | 2 +- lib/ldap.sh | 2 +- lib/listmonk.sh | 2 +- lib/mail.sh | 2 +- lib/matrix.sh | 2 +- lib/nextcloud.sh | 2 +- lib/panel.sh | 2 +- lib/pdns.sh | 2 +- lib/pdnsadmin.sh | 2 +- lib/pdnsmysql.sh | 2 +- lib/postgresql.sh | 2 +- lib/vaultwarden.sh | 2 +- lib/wireguard.sh | 2 +- 21 files changed, 24 insertions(+), 28 deletions(-) diff --git a/bin/start b/bin/start index 39119f1..04d169a 100755 --- a/bin/start +++ b/bin/start @@ -23,7 +23,8 @@ startservice() { SPINPID=$! NC_COMMAND=`grep start_service /federated/lib/$SERVICE.sh | awk -F\" '{ print $4 }'` - start_service_withalert "$SERVICE" "$NC_COMMAND" + RETRY=`grep start_service /federated/lib/caddy.sh | awk -F\" '{ print $6 }'` + start_service_withalert "$SERVICE" "$NC_COMMAND" "$RETRY" kill -9 $SPINPID &> /dev/null echo -ne "done.\n" diff --git a/bin/upgrade b/bin/upgrade index 8b3674d..4489319 100755 --- a/bin/upgrade +++ b/bin/upgrade @@ -1,4 +1,4 @@ -#!/bin/bash -x +#!/bin/bash . /federated/lib/functions.sh diff --git a/lib/baserow.sh b/lib/baserow.sh index ee587c1..a7af766 100644 --- a/lib/baserow.sh +++ b/lib/baserow.sh @@ -82,7 +82,7 @@ echo -ne "done." start_baserow() { # Start service with command to make sure it's up before proceeding - start_service "baserow" "docker exec baserow curl http://localhost:8000 &> /dev/null" + start_service "baserow" "docker exec baserow curl http://localhost:8000 &> /dev/null" "7" # Move createuser.sh and set it executable mv /federated/apps/baserow/data/createuser.sh /federated/apps/baserow/data/baserow/data/ diff --git a/lib/caddy.sh b/lib/caddy.sh index 6af5cf6..c9c1686 100644 --- a/lib/caddy.sh +++ b/lib/caddy.sh @@ -108,8 +108,8 @@ kill -9 $SPINPID &> /dev/null echo -ne "done." } start_caddy() { - # Start service with command to make sure it's up before proceeding - start_service "caddy" "nc -z 172.99.0.31 80 &> /dev/null" + # Start service with command and retry amount to make sure it's up before proceeding + start_service "caddy" "nc -z 172.99.0.31 80 &> /dev/null" "7" kill -9 $SPINPID &> /dev/null echo -ne "done." diff --git a/lib/collabora.sh b/lib/collabora.sh index 4646876..db4a34f 100644 --- a/lib/collabora.sh +++ b/lib/collabora.sh @@ -65,7 +65,7 @@ echo -ne "done." } start_collabora() { # Start service with command to make sure it's up before proceeding - start_service "collabora" "nc -z 172.99.0.17 9980 &> /dev/null" + start_service "collabora" "nc -z 172.99.0.17 9980 &> /dev/null" "7" kill -9 $SPINPID &> /dev/null echo -ne "done." diff --git a/lib/element.sh b/lib/element.sh index 020bd1c..276b994 100644 --- a/lib/element.sh +++ b/lib/element.sh @@ -130,7 +130,7 @@ echo -ne "done." } start_element() { # Start service with command to make sure it's up before proceeding - start_service "element" "nc -z 172.99.0.20 80 &> /dev/null" + start_service "element" "nc -z 172.99.0.20 80 &> /dev/null" "7" kill -9 $SPINPID &> /dev/null echo -ne "done." diff --git a/lib/functions.sh b/lib/functions.sh index e2c3356..5156866 100644 --- a/lib/functions.sh +++ b/lib/functions.sh @@ -160,17 +160,12 @@ start_service_upgrade() { start_service_withalert() { SERVICE="$1" COMMAND="$2" - - # Start /federated/apps/SERVICE with output to /dev/null -# echo -ne "\n* Starting /federated/apps/$SERVICE service.." -# spin & -# SPINPID=$! + RETRY="$3" docker-compose -f /federated/apps/$SERVICE/docker-compose.yml -p $SERVICE up -d &> /dev/null # Keep trying service port to make sure it's up before # we proceed - RETRY="4" while [ $RETRY -gt 0 ]; do bash -c "eval $COMMAND" &> /dev/null if [ $? -eq 0 ]; then @@ -212,6 +207,7 @@ start_service_upgrade() { start_service() { SERVICE="$1" COMMAND="$2" + RETRY="$3" # Start /federated/apps/SERVICE with output to /dev/null echo -ne "\n* Starting /federated/apps/$SERVICE service.." @@ -227,7 +223,6 @@ start_service() { # Keep trying service port to make sure it's up before # we proceed - RETRY="30" while [ $RETRY -gt 0 ]; do bash -c "$COMMAND" &> /dev/null if [ $? -eq 0 ]; then diff --git a/lib/gitea.sh b/lib/gitea.sh index bb4b5a0..f1f1a52 100644 --- a/lib/gitea.sh +++ b/lib/gitea.sh @@ -159,7 +159,7 @@ echo -ne "done." } start_gitea() { # Start service with command to make sure it's up before proceeding - start_service "gitea" "nc -z 172.99.0.30 3000 &> /dev/null" + start_service "gitea" "nc -z 172.99.0.30 3000 &> /dev/null" "7" # Copy creategitea.sh inside gitea container mv /federated/apps/gitea/data/creategitea.sh /federated/apps/gitea/data/data/creategitea.sh diff --git a/lib/jitsi.sh b/lib/jitsi.sh index 6d445e9..1bcbdbd 100644 --- a/lib/jitsi.sh +++ b/lib/jitsi.sh @@ -614,7 +614,7 @@ echo -ne "done." start_jitsi() { # Start service with command to make sure it's up before proceeding - start_service "jitsi" "nc -z 172.99.0.25 443 &> /dev/null" + start_service "jitsi" "nc -z 172.99.0.25 443 &> /dev/null" "8" kill -9 $SPINPID &> /dev/null echo -ne "done." diff --git a/lib/ldap.sh b/lib/ldap.sh index cda8566..e80ff3f 100644 --- a/lib/ldap.sh +++ b/lib/ldap.sh @@ -159,7 +159,7 @@ echo -ne "done." } start_ldap() { # Start service with command to make sure it's up before proceeding - start_service "ldap" "nc -z 172.99.0.15 636 &> /dev/null" + start_service "ldap" "nc -z 172.99.0.15 636 &> /dev/null" "40" # Run our ldap.sh script inside the ldap container # This imports the inital LDAP configuration diff --git a/lib/listmonk.sh b/lib/listmonk.sh index f6310c6..1ccc89c 100644 --- a/lib/listmonk.sh +++ b/lib/listmonk.sh @@ -81,7 +81,7 @@ start_listmonk() { docker exec postgresql psql -U listmonk -c "update settings set value='[{\"host\": \"mail.$DOMAIN\", \"port\": 587, \"enabled\": true, \"password\": \"$ADMINPASS\", \"tls_type\": \"STARTTLS\", \"username\": \"admin\", \"max_conns\": 10, \"idle_timeout\": \"15s\", \"wait_timeout\": \"5s\", \"auth_protocol\": \"login\", \"email_headers\": [], \"hello_hostname\": \"\", \"max_msg_retries\": 2, \"tls_skip_verify\": false}, {\"host\": \"smtp.gmail.com\", \"port\": 465, \"enabled\": false, \"password\": \"password\", \"tls_type\": \"TLS\", \"username\": \"username@gmail.com\", \"max_conns\": 10, \"idle_timeout\": \"15s\", \"wait_timeout\": \"5s\", \"auth_protocol\": \"login\", \"email_headers\": [], \"hello_hostname\": \"\", \"max_msg_retries\": 2, \"tls_skip_verify\": false}]' where key='smtp';" &> /dev/null # Start service with command to make sure it's up before proceeding - start_service "listmonk" "nc -z 172.99.0.21 9000 &> /dev/null" + start_service "listmonk" "nc -z 172.99.0.21 9000 &> /dev/null" "8" kill -9 $SPINPID &> /dev/null echo -ne "done." diff --git a/lib/mail.sh b/lib/mail.sh index 2d0ea35..6525879 100644 --- a/lib/mail.sh +++ b/lib/mail.sh @@ -154,7 +154,7 @@ EOF } start_mail() { # Start service with command to make sure it's up before proceeding - start_service "mail" "nc -z 172.99.0.16 25 &> /dev/null" + start_service "mail" "nc -z 172.99.0.16 25 &> /dev/null" "9" # Generate the DKIM DNS key and setup docker exec mail setup config dkim diff --git a/lib/matrix.sh b/lib/matrix.sh index 31f220a..8ff4985 100644 --- a/lib/matrix.sh +++ b/lib/matrix.sh @@ -108,7 +108,7 @@ echo -ne "done." } start_matrix() { # Start service with command to make sure it's up before proceeding - start_service "matrix" "nc -z 172.99.0.19 8008 &> /dev/null" + start_service "matrix" "nc -z 172.99.0.19 8008 &> /dev/null" "8" kill -9 $SPINPID &> /dev/null echo -ne "done." diff --git a/lib/nextcloud.sh b/lib/nextcloud.sh index 5f138f6..3c4fcc9 100644 --- a/lib/nextcloud.sh +++ b/lib/nextcloud.sh @@ -250,7 +250,7 @@ chmod +x /federated/apps/nextcloud/data/config.sh start_nextcloud() { # Start service with command to make sure it's up before proceeding - start_service "nextcloud" "nc -z 172.99.0.18 80 &> /dev/null" + start_service "nextcloud" "nc -z 172.99.0.18 80 &> /dev/null" "35" # Move config.sh and sidemenu config, set config.sh executable mv /federated/apps/nextcloud/data/config.sh /federated/apps/nextcloud/data/configs.json /federated/apps/nextcloud/data/var/www/html/ diff --git a/lib/panel.sh b/lib/panel.sh index 7c723c7..5c4ea73 100644 --- a/lib/panel.sh +++ b/lib/panel.sh @@ -70,7 +70,7 @@ echo -ne "done." } start_panel() { # Start service with command to make sure it's up before proceeding - start_service "panel" "nc -z 172.99.0.23 80 &> /dev/null" + start_service "panel" "nc -z 172.99.0.23 80 &> /dev/null" "7" kill -9 $SPINPID &> /dev/null echo -ne "done." diff --git a/lib/pdns.sh b/lib/pdns.sh index 100e67a..a61f108 100644 --- a/lib/pdns.sh +++ b/lib/pdns.sh @@ -100,7 +100,7 @@ echo -ne "done." } start_pdns() { # Start service with command to make sure it's up before proceeding - start_service "pdns" "nc -z 172.99.0.11 8081 &> /dev/null" + start_service "pdns" "nc -z 172.99.0.11 8081 &> /dev/null" "7" # Create DNS records for newdomain # docker exec pdns pdnsutil create-zone $DOMAIN diff --git a/lib/pdnsadmin.sh b/lib/pdnsadmin.sh index a26bca0..2e4b2b2 100644 --- a/lib/pdnsadmin.sh +++ b/lib/pdnsadmin.sh @@ -94,7 +94,7 @@ echo -ne "done." } start_pdnsadmin() { # Start service with command to make sure it's up before proceeding - start_service "pdnsadmin" "nc -z 172.99.0.12 9494 &> /dev/null" + start_service "pdnsadmin" "nc -z 172.99.0.12 9494 &> /dev/null" "8" # Run MySQL command to create admin user for pdns admin interface docker exec pdnsmysql bash -c "mysql -updns -p$MYSQL_PASSWORD pdns -e '$PDNS_MYSQL_COMMAND;'" diff --git a/lib/pdnsmysql.sh b/lib/pdnsmysql.sh index b634607..b69d840 100644 --- a/lib/pdnsmysql.sh +++ b/lib/pdnsmysql.sh @@ -53,7 +53,7 @@ echo -ne "done." } start_pdnsmysql() { # Start service with command to make sure it's up before proceeding - start_service "pdnsmysql" "nc -z 172.99.0.10 3306 &> /dev/null" + start_service "pdnsmysql" "nc -z 172.99.0.10 3306 &> /dev/null" "8" kill -9 $SPINPID &> /dev/null echo -ne "done." diff --git a/lib/postgresql.sh b/lib/postgresql.sh index 48df423..42e9a8d 100644 --- a/lib/postgresql.sh +++ b/lib/postgresql.sh @@ -103,7 +103,7 @@ echo -ne "done." } start_postgresql() { # Start service with command to make sure it's up before proceeding - start_service "postgresql" "nc -z 172.99.0.14 5432 &> /dev/null" + start_service "postgresql" "nc -z 172.99.0.14 5432 &> /dev/null" "8" # Tune PostgreSQL sed -i "s#shared_buffers =.*#shared_buffers = 800MB#g" /federated/apps/postgresql/data/var/lib/postgresql/data/postgresql.conf diff --git a/lib/vaultwarden.sh b/lib/vaultwarden.sh index 056933a..5bba239 100644 --- a/lib/vaultwarden.sh +++ b/lib/vaultwarden.sh @@ -62,7 +62,7 @@ echo -ne "done." } start_vaultwarden() { # Start service with command to make sure it's up before proceeding - start_service "vaultwarden" "nc -z 172.99.0.22 80 &> /dev/null" + start_service "vaultwarden" "nc -z 172.99.0.22 80 &> /dev/null" "8" kill -9 $SPINPID &> /dev/null echo -ne "done." diff --git a/lib/wireguard.sh b/lib/wireguard.sh index a309f69..4cab37b 100644 --- a/lib/wireguard.sh +++ b/lib/wireguard.sh @@ -84,7 +84,7 @@ echo -ne "done." start_wireguard() { # Start service with command to make sure it's up before proceeding - start_service "wireguard" "nc -uvz 172.99.0.24 51820 &> /dev/null" + start_service "wireguard" "nc -uvz 172.99.0.24 51820 &> /dev/null" "8" kill -9 $SPINPID &> /dev/null echo -ne "done."