Skip to content

Commit d9339fb

Browse files
committed
fix: stop/start service appropriately in configure
When configuring the service, ensure the existing process is stopped using the appropriate means (either pm2 or systemctl). Then start the new process using the appropriate means, based on the chosen option: if --pm2 flag was provided then use pm2, if the systemd service unit is installed, then use systemctl. Otherwise the service is not started since neither pm2 nor systemd were selected.
1 parent 2706e75 commit d9339fb

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

bin/configure-auth-service.sh

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -903,16 +903,29 @@ function modify_config() {
903903

904904
# Restart the service for the configuration changes to take effect.
905905
function restart_service() {
906-
# If pm2 is present then presumably HAS is managed using it, otherwise
907-
# should assume that HAS is installed as a systemd service unit.
906+
# ignore errors when attempting to stop the service
907+
set +e
908+
# Stop the existing service, if it is running.
908909
if [[ -f ecosystem.config.js ]] && which pm2 >/dev/null 2>&1; then
909-
# try to have pm2 run as the unprivileged user by default
910+
# If pm2 is present then presumably HAS is managed using it, in which
911+
# case we use the pm2 commands to stop and delete the old application
912+
# before starting again (possibly via systemctl). This likely also helps
913+
# reload the settings properly without having kill the pm2 daemon.
914+
PM2_USER=${SUDO_USER:-${USER}}
915+
sudo -u $PM2_USER pm2 delete ecosystem.config.js
916+
sudo -u $PM2_USER pm2 save
917+
elif [[ -f /etc/systemd/system/helix-auth.service ]]; then
918+
sudo systemctl stop helix-auth
919+
fi
920+
set -e
921+
922+
# Start the service using the preferred process manager.
923+
if [[ "${CONFIG_FILE_NAME}" == "ecosystem.config.js" ]]; then
910924
PM2_USER=${SUDO_USER:-${USER}}
911-
sudo -u $PM2_USER pm2 kill
912925
sudo -u $PM2_USER pm2 start ecosystem.config.js
913926
SVC_RESTARTED=true
914927
elif [[ -f /etc/systemd/system/helix-auth.service ]]; then
915-
sudo systemctl restart helix-auth
928+
sudo systemctl start helix-auth
916929
SVC_RESTARTED=true
917930
fi
918931
return 0

0 commit comments

Comments
 (0)