diff options
Diffstat (limited to 'hetzner-admin/run-command.sh')
| -rwxr-xr-x | hetzner-admin/run-command.sh | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/hetzner-admin/run-command.sh b/hetzner-admin/run-command.sh index c5b8ea5..d1f68f8 100755 --- a/hetzner-admin/run-command.sh +++ b/hetzner-admin/run-command.sh @@ -4,7 +4,14 @@ set -e # 管理画面から停止・起動できるサービス(名前は status/targets.txt の名前に合わせる) # Caddy / hetzner-admin / status は止めると管理画面に戻れなくなるので対象外 -SERVICES="golive whoisband blog todo git vpn ntfy mail" +SERVICES="golive whoisband blog todo git vpn ntfy mail code" +# docker compose ではなく systemd で動くサービス +service_unit() { + case "$1" in + code) echo code-server@yyamashita.service ;; + *) return 1 ;; + esac +} service_compose() { case "$1" in golive) echo /app/tokyo-livehouse-events/docker-compose.yml ;; @@ -26,22 +33,27 @@ case "$SSH_ORIGINAL_COMMAND" in "services") touch "$STOPPED_FILE" for name in $SERVICES; do - running=$(docker compose -f "$(service_compose "$name")" ps -q --status running 2>/dev/null | wc -l) - if [ "$running" -gt 0 ]; then state=running; else state=stopped; fi + if unit=$(service_unit "$name"); then + if systemctl is-active --quiet "$unit"; then state=running; else state=stopped; fi + else + running=$(docker compose -f "$(service_compose "$name")" ps -q --status running 2>/dev/null | wc -l) + if [ "$running" -gt 0 ]; then state=running; else state=stopped; fi + fi echo "$name $state" done ;; "stop "*|"start "*) action="${SSH_ORIGINAL_COMMAND%% *}" name="${SSH_ORIGINAL_COMMAND#* }" - compose=$(service_compose "$name") || { echo "Unknown service: $name" >&2; exit 1; } + unit=$(service_unit "$name") || compose=$(service_compose "$name") || { echo "Unknown service: $name" >&2; exit 1; } touch "$STOPPED_FILE" if [ "$action" = stop ]; then grep -qx "$name" "$STOPPED_FILE" || echo "$name" >> "$STOPPED_FILE" - docker compose -f "$compose" stop 2>&1 + # systemd は disable もして、再起動後も停止したままにする(docker の unless-stopped と同じ扱い) + if [ -n "$unit" ]; then systemctl disable --now "$unit" 2>&1; else docker compose -f "$compose" stop 2>&1; fi else sed -i "/^${name}\$/d" "$STOPPED_FILE" - docker compose -f "$compose" up -d 2>&1 + if [ -n "$unit" ]; then systemctl enable --now "$unit" 2>&1; else docker compose -f "$compose" up -d 2>&1; fi fi ;; "docker ps") |
