diff --git a/runtime/frpc@.service b/runtime/frpc@.service deleted file mode 100644 index 4d22642..0000000 --- a/runtime/frpc@.service +++ /dev/null @@ -1,22 +0,0 @@ -# Example frpc systemd unit. Copy to /etc/systemd/system/frpc@.service on -# the frpc host, then: -# systemctl daemon-reload -# systemctl enable --now frpc@.service -# -# The specifier lets you run multiple frpc instances per host. -# Place per-instance configs under /etc/frpc/.ini. - -[Unit] -Description=frpc — fatedier/frp client (%i) -After=network-online.target -Wants=network-online.target - -[Service] -Type=simple -ExecStart=/usr/local/bin/frpc -c /etc/frpc/%i.ini -Restart=on-failure -RestartSec=5 -LimitNOFILE=65536 - -[Install] -WantedBy=multi-user.target \ No newline at end of file diff --git a/runtime/frps-manager.service b/runtime/frps-manager.service deleted file mode 100644 index 73006dd..0000000 --- a/runtime/frps-manager.service +++ /dev/null @@ -1,24 +0,0 @@ -[Unit] -Description=frps-manager — Flask web UI for managing frps -Documentation=https://github.com/fatedier/frp -After=network-online.target frps.service -Wants=network-online.target - -[Service] -Type=simple -User=root -WorkingDirectory=/fs/1000/ftp/Project/frps-manager -Environment="FRPS_VHOST_HTTP_PORT=80" -Environment="FRPS_VHOST_HTTPS_PORT=443" -ExecStart=/fs/1000/ftp/Project/frps-manager/venv/bin/gunicorn \ - --workers 2 \ - --bind 0.0.0.0:5390 \ - --access-logfile /fs/1000/ftp/Project/frps-manager/runtime/logs/web-access.log \ - --error-logfile /fs/1000/ftp/Project/frps-manager/runtime/logs/web-error.log \ - --timeout 60 \ - wsgi:app -Restart=on-failure -RestartSec=5 - -[Install] -WantedBy=multi-user.target \ No newline at end of file diff --git a/runtime/frps.service b/runtime/frps.service deleted file mode 100644 index 3c8383c..0000000 --- a/runtime/frps.service +++ /dev/null @@ -1,29 +0,0 @@ -[Unit] -Description=frps — frp server managed by frps-manager -Documentation=https://github.com/fatedier/frp -After=network-online.target -Wants=network-online.target - -[Service] -Type=simple -# frps 0.70 does not support SIGHUP reload — `systemctl reload` will be -# turned into a full restart by systemd (ExecReload forces a fresh start). -ExecStart=/fs/1000/ftp/Project/frps-manager/runtime/bin/frps \ - -c /fs/1000/ftp/Project/frps-manager/runtime/conf/frps.ini -# frps 0.70 doesn't implement SIGHUP reload — the manager invokes -# `systemctl restart frps.service` whenever a config change is applied. -ExecReload=/usr/bin/systemctl restart frps.service -Restart=on-failure -RestartSec=5 -LimitNOFILE=65536 -# Don't start before the web manager; if frps is down the web manager -# still works (it can reload / restart frps). - -# Hardening -NoNewPrivileges=true -PrivateTmp=true -ProtectSystem=full -ProtectHome=true - -[Install] -WantedBy=multi-user.target \ No newline at end of file diff --git a/scripts/deploy.sh b/scripts/deploy.sh index f07261b..5166696 100644 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -1,16 +1,9 @@ #!/usr/bin/env bash # frps-manager one-shot deploy script. -# Installs frps + frps-manager as systemd services on a Debian/Ubuntu or RHEL box. +# Dynamically generates systemd units with correct paths. # Run as root (or with sudo). # # Usage: sudo bash scripts/deploy.sh [--dry-run] [--no-systemd] [--dev] -# What it does: -# 1. Detects distro + package manager, installs system deps -# 2. Downloads the latest stable frps binary if runtime/bin/frps is missing -# 3. Creates a Python venv, installs requirements -# 4. Initializes the SQLite database -# 5. Generates a default frps.ini (admin user, default tenant, bindPort 7000) -# 6. Installs + starts systemd services (frps + frps-manager on :5390) set -euo pipefail @@ -34,6 +27,11 @@ cd "$PROJECT_DIR" log() { echo "[deploy] $*"; } die() { echo "[deploy][FATAL] $*" >&2; exit 1; } +FRPS_BIN="$PROJECT_DIR/runtime/bin/frps" +FRPS_INI="$PROJECT_DIR/runtime/conf/frps.ini" +GUNICORN="$PROJECT_DIR/venv/bin/gunicorn" +PORT=5390 + # --- distro detection ------------------------------------------------------- if [ -f /etc/os-release ]; then . /etc/os-release @@ -55,7 +53,7 @@ esac log "Detected: $OS_ID $OS_VER (pkg manager: $PKG)" # --- frps download ---------------------------------------------------------- -if [ ! -x runtime/bin/frps ]; then +if [ ! -x "$FRPS_BIN" ]; then log "frps binary missing — fetching v0.70.1 from GitHub" if [ "$DRY_RUN" = 1 ]; then log "DRY: would download frp_0.70.1_linux_amd64.tar.gz" @@ -75,9 +73,9 @@ if [ ! -x runtime/bin/frps ]; then || die "Failed to download frps" tar xzf "$TMPDIR/frp.tgz" -C "$TMPDIR" mkdir -p runtime/bin - cp "$TMPDIR"/frp_0.70.1_linux_${FRPS_ARCH}/frps runtime/bin/frps - chmod +x runtime/bin/frps - log "Installed runtime/bin/frps" + cp "$TMPDIR"/frp_0.70.1_linux_${FRPS_ARCH}/frps "$FRPS_BIN" + chmod +x "$FRPS_BIN" + log "Installed $FRPS_BIN" fi fi @@ -111,33 +109,101 @@ if [ "$DRY_RUN" = 0 ]; then venv/bin/python init_db.py fi -# --- frps systemd ----------------------------------------------------------- +# --- generate systemd units ------------------------------------------------- +generate_systemd_units() { + # frps.service — generated with actual binary + config paths + cat > /etc/systemd/system/frps.service < /etc/systemd/system/frps-manager.service < /etc/systemd/system/frpc@.service </dev/null || true $SUDO systemctl restart frps.service || true sleep 2 if ! systemctl is-active --quiet frps.service; then - log "frps.service not active — check 'journalctl -u frps'" + log "WARNING: frps.service not active — check 'journalctl -u frps'" else log "frps.service is active" fi fi - log "Installing systemd unit frps-manager.service (port 5390)" + # --- start frps-manager --- + log "Starting frps-manager.service (port $PORT)" if [ "$DRY_RUN" = 0 ]; then - $SUDO cp runtime/frps-manager.service /etc/systemd/system/frps-manager.service - $SUDO systemctl daemon-reload - $SUDO systemctl enable frps-manager.service + $SUDO systemctl enable frps-manager.service 2>/dev/null || true $SUDO systemctl restart frps-manager.service || true sleep 2 if ! systemctl is-active --quiet frps-manager.service; then - log "frps-manager.service not active — check 'journalctl -u frps-manager'" + log "WARNING: frps-manager.service not active — check 'journalctl -u frps-manager'" else - log "frps-manager.service is active on http://0.0.0.0:5390" + log "frps-manager.service is active on http://0.0.0.0:$PORT" fi fi else @@ -149,7 +215,7 @@ cat <:5390 + Web UI: http://:$PORT Default: admin / admin (CHANGE IMMEDIATELY under "改密") frps bind: 0.0.0.0:7000 @@ -157,15 +223,16 @@ cat <