summaryrefslogtreecommitdiff
path: root/hetzner-admin/app.py
diff options
context:
space:
mode:
authoryyamashita <yyamashita@hetzner.yyamashita.com>2026-10-31 22:45:58 +0900
committeryyamashita <yyamashita@hetzner.yyamashita.com>2026-10-31 22:45:58 +0900
commit05e1418efa56a773c295a2e072796e220d8d8f51 (patch)
tree5669d97650919db74e6f5f0174880e6e9221d770 /hetzner-admin/app.py
parentf48002a02c7b75de8add369672c861f63e900df4 (diff)
hetzner-admin: stop/start individual services, shown as STOPPED on status page
- run-command.sh: services / stop <name> / start <name> for app and infra stacks (not caddy, hetzner-admin, status). Stopped names go to status/stopped.txt (gitignored). - status: a stopped service that does not respond is STOPPED (gray), excluded from uptime and DOWN alerts. If it responds it is UP as usual. - Infra deploy.sh skips stopped stacks; app repo pushes clear the flag. - claude-code@.service: Restart=on-failure, and restart-sessions.sh restarts one unit at a time, to avoid the tmux "server exited unexpectedly" race. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N5eS3U54gzjRXzm65Np1RS
Diffstat (limited to 'hetzner-admin/app.py')
-rw-r--r--hetzner-admin/app.py57
1 files changed, 56 insertions, 1 deletions
diff --git a/hetzner-admin/app.py b/hetzner-admin/app.py
index 90a1cca..ac3178c 100644
--- a/hetzner-admin/app.py
+++ b/hetzner-admin/app.py
@@ -65,6 +65,9 @@ COMMANDS = [
COMMAND_MAP = {label: cmd for label, cmd in COMMANDS}
+# 個別に停止・起動できるサービス(run-command.sh の SERVICES と status/targets.txt の名前に合わせる)
+SERVICES = ["golive", "whoisband", "blog", "todo", "git", "vpn", "ntfy", "mail"]
+
# ブラウザ側: JSON ⇔ WebAuthn の変換はブラウザ組み込みの
# parseCreationOptionsFromJSON / parseRequestOptionsFromJSON / toJSON に任せる
PASSKEY_JS = """<script>
@@ -107,6 +110,30 @@ HTML = """<!DOCTYPE html>
<body>
<h3>Server Admin</h3>
<p><a href="https://status.yyamashita.com">Status</a></p>
+<h4>Services</h4>
+{% if services is string %}
+<p style="color:red">{{ services }}</p>
+{% else %}
+<table>
+{% for name, state in services %}
+<tr>
+ <td>{{ name }}</td>
+ <td style="color:{{ 'green' if state == 'running' else 'gray' }}">{{ state }}</td>
+ <td>
+ <form method="post" action="/service" style="margin:0">
+ <input type="hidden" name="name" value="{{ name }}">
+ {% if state == "running" %}
+ <button name="action" value="stop" onclick="return confirm('Stop {{ name }}?')">Stop</button>
+ {% else %}
+ <button name="action" value="start">Start</button>
+ {% endif %}
+ </form>
+ </td>
+</tr>
+{% endfor %}
+</table>
+{% endif %}
+<h4>Commands</h4>
{% for label, _ in commands %}
<form method="post" action="/run" style="display:block;margin-bottom:8px">
<input type="hidden" name="cmd" value="{{ label }}">
@@ -177,9 +204,23 @@ def run_ssh(command):
client.close()
+def load_services():
+ """[(name, "running"|"stopped"), ...]。取得できなければエラーメッセージ(str)"""
+ try:
+ out = run_ssh("services")
+ except Exception as e:
+ return f"Error loading services: {e}"
+ states = dict(line.split(None, 1) for line in out.splitlines() if len(line.split()) == 2)
+ return [(name, states.get(name, "unknown")) for name in SERVICES]
+
+
def render_index(output=None):
return render_template_string(
- HTML, commands=COMMANDS, output=output, passkey_count=len(load_passkeys())
+ HTML,
+ commands=COMMANDS,
+ services=load_services(),
+ output=output,
+ passkey_count=len(load_passkeys()),
)
@@ -305,3 +346,17 @@ def run():
except Exception as e:
output = f"Error: {e}"
return render_index(output)
+
+
+@app.route("/service", methods=["POST"])
+@requires_auth
+def service():
+ name = request.form.get("name", "")
+ action = request.form.get("action", "")
+ if name not in SERVICES or action not in ("stop", "start"):
+ return render_index(f"Unknown service action: {action} {name}")
+ try:
+ output = run_ssh(f"{action} {name}")
+ except Exception as e:
+ output = f"Error: {e}"
+ return render_index(output)