@@ -24,6 +24,29 @@ success() { echo -e "${GREEN}[$(date '+%Y-%m-%d %H:%M:%S')] [OK] - ${RESET} $1";
2424warn () { echo -e " ${YELLOW} [$( date ' +%Y-%m-%d %H:%M:%S' ) ] [WARN] - ${RESET} $1 " ; }
2525error () { echo -e " ${RED} [$( date ' +%Y-%m-%d %H:%M:%S' ) ] [ERROR] - ${RESET} $1 " ; }
2626
27+ # ========== Capture Active Services ==========
28+ declare -a ACTIVE_SERVICES_BEFORE_UPGRADE=()
29+ ALL_SERVICES=(
30+ hysteria-caddy.service
31+ hysteria-server.service
32+ hysteria-auth.service
33+ hysteria-scheduler.service
34+ hysteria-telegram-bot.service
35+ hysteria-normal-sub.service
36+ hysteria-caddy-normalsub.service
37+ hysteria-webpanel.service
38+ hysteria-ip-limit.service
39+ )
40+
41+ info " Checking for active services before upgrade..."
42+ for SERVICE in " ${ALL_SERVICES[@]} " ; do
43+ if systemctl is-active --quiet " $SERVICE " ; then
44+ ACTIVE_SERVICES_BEFORE_UPGRADE+=(" $SERVICE " )
45+ info " Service '$SERVICE ' is active and will be restarted."
46+ fi
47+ done
48+
49+
2750# ========== New Function to Install Go and Compile Auth Binary ==========
2851install_go_and_compile_auth () {
2952 info " Checking for Go and compiling authentication binary..."
@@ -157,26 +180,18 @@ else
157180fi
158181
159182# ========== Restart Services ==========
160- SERVICES=(
161- hysteria-caddy.service
162- hysteria-server.service
163- hysteria-auth.service
164- hysteria-scheduler.service
165- hysteria-telegram-bot.service
166- hysteria-normal-sub.service
167- hysteria-caddy-normalsub.service
168- hysteria-webpanel.service
169- hysteria-ip-limit.service
170- )
183+ info " Reloading systemd daemon..."
184+ systemctl daemon-reload
171185
172- info " Restarting available services..."
173- for SERVICE in " ${SERVICES[@]} " ; do
174- if systemctl status " $SERVICE " & > /dev/null; then
186+ info " Restarting services that were active before the upgrade..."
187+ if [ ${# ACTIVE_SERVICES_BEFORE_UPGRADE[@]} -eq 0 ]; then
188+ warn " No relevant services were active before the upgrade. Skipping restart."
189+ else
190+ for SERVICE in " ${ACTIVE_SERVICES_BEFORE_UPGRADE[@]} " ; do
175191 systemctl restart " $SERVICE " && success " $SERVICE restarted." || warn " $SERVICE failed to restart."
176- else
177- warn " $SERVICE not found. Skipping..."
178- fi
179- done
192+ done
193+ fi
194+
180195
181196# ========== Final Check ==========
182197if systemctl is-active --quiet hysteria-server.service; then
0 commit comments