deploy.sh dynamically generates systemd units
- Remove static runtime/*.service files - generate_systemd_units() writes paths based on PROJECT_DIR - frps.service: ExecStart uses actual frps binary path - frps-manager.service: WorkingDir + gunicorn path from PROJECT_DIR - frpc@.service template also generated at deploy time
This commit is contained in:
@@ -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@<client-name>.service
|
|
||||||
#
|
|
||||||
# The <instance> specifier lets you run multiple frpc instances per host.
|
|
||||||
# Place per-instance configs under /etc/frpc/<instance>.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
|
|
||||||
@@ -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
|
|
||||||
@@ -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
|
|
||||||
+96
-29
@@ -1,16 +1,9 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# frps-manager one-shot deploy script.
|
# 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).
|
# Run as root (or with sudo).
|
||||||
#
|
#
|
||||||
# Usage: sudo bash scripts/deploy.sh [--dry-run] [--no-systemd] [--dev]
|
# 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
|
set -euo pipefail
|
||||||
|
|
||||||
@@ -34,6 +27,11 @@ cd "$PROJECT_DIR"
|
|||||||
log() { echo "[deploy] $*"; }
|
log() { echo "[deploy] $*"; }
|
||||||
die() { echo "[deploy][FATAL] $*" >&2; exit 1; }
|
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 -------------------------------------------------------
|
# --- distro detection -------------------------------------------------------
|
||||||
if [ -f /etc/os-release ]; then
|
if [ -f /etc/os-release ]; then
|
||||||
. /etc/os-release
|
. /etc/os-release
|
||||||
@@ -55,7 +53,7 @@ esac
|
|||||||
log "Detected: $OS_ID $OS_VER (pkg manager: $PKG)"
|
log "Detected: $OS_ID $OS_VER (pkg manager: $PKG)"
|
||||||
|
|
||||||
# --- frps download ----------------------------------------------------------
|
# --- frps download ----------------------------------------------------------
|
||||||
if [ ! -x runtime/bin/frps ]; then
|
if [ ! -x "$FRPS_BIN" ]; then
|
||||||
log "frps binary missing — fetching v0.70.1 from GitHub"
|
log "frps binary missing — fetching v0.70.1 from GitHub"
|
||||||
if [ "$DRY_RUN" = 1 ]; then
|
if [ "$DRY_RUN" = 1 ]; then
|
||||||
log "DRY: would download frp_0.70.1_linux_amd64.tar.gz"
|
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"
|
|| die "Failed to download frps"
|
||||||
tar xzf "$TMPDIR/frp.tgz" -C "$TMPDIR"
|
tar xzf "$TMPDIR/frp.tgz" -C "$TMPDIR"
|
||||||
mkdir -p runtime/bin
|
mkdir -p runtime/bin
|
||||||
cp "$TMPDIR"/frp_0.70.1_linux_${FRPS_ARCH}/frps runtime/bin/frps
|
cp "$TMPDIR"/frp_0.70.1_linux_${FRPS_ARCH}/frps "$FRPS_BIN"
|
||||||
chmod +x runtime/bin/frps
|
chmod +x "$FRPS_BIN"
|
||||||
log "Installed runtime/bin/frps"
|
log "Installed $FRPS_BIN"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -111,33 +109,101 @@ if [ "$DRY_RUN" = 0 ]; then
|
|||||||
venv/bin/python init_db.py
|
venv/bin/python init_db.py
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# --- frps systemd -----------------------------------------------------------
|
# --- generate systemd units -------------------------------------------------
|
||||||
|
generate_systemd_units() {
|
||||||
|
# frps.service — generated with actual binary + config paths
|
||||||
|
cat > /etc/systemd/system/frps.service <<EOF
|
||||||
|
[Unit]
|
||||||
|
Description=frps — fatedier/frp server
|
||||||
|
After=network-online.target
|
||||||
|
Wants=network-online.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
ExecStart=$FRPS_BIN -c $FRPS_INI
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=5
|
||||||
|
LimitNOFILE=65536
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# frps-manager.service — generated with actual project paths
|
||||||
|
cat > /etc/systemd/system/frps-manager.service <<EOF
|
||||||
|
[Unit]
|
||||||
|
Description=frps-manager — frps Web Management UI
|
||||||
|
After=network-online.target frps.service
|
||||||
|
Wants=frps.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
WorkingDirectory=$PROJECT_DIR
|
||||||
|
Environment=FLASK_SECRET=
|
||||||
|
Environment=FRPS_DASHBOARD_URL=http://127.0.0.1:7500
|
||||||
|
Environment=FRPS_DASHBOARD_USER=admin
|
||||||
|
Environment=FRPS_DASHBOARD_PASS=admin123
|
||||||
|
Environment=FRPS_BIND_PORT=7000
|
||||||
|
Environment=FRPS_VHOST_HTTP_PORT=80
|
||||||
|
Environment=FRPS_VHOST_HTTPS_PORT=443
|
||||||
|
ExecStart=$GUNICORN wsgi:app --bind 0.0.0.0:$PORT --workers 2 --timeout 30
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=5
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# frpc@.service template — for client hosts
|
||||||
|
cat > /etc/systemd/system/frpc@.service <<EOF
|
||||||
|
[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
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
if [ "$NO_SYSTEMD" = 0 ]; then
|
if [ "$NO_SYSTEMD" = 0 ]; then
|
||||||
log "Installing systemd unit frps.service"
|
log "Generating systemd units (project_dir=$PROJECT_DIR)"
|
||||||
if [ "$DRY_RUN" = 0 ]; then
|
if [ "$DRY_RUN" = 0 ]; then
|
||||||
$SUDO cp runtime/frps.service /etc/systemd/system/frps.service
|
generate_systemd_units
|
||||||
$SUDO systemctl daemon-reload
|
$SUDO systemctl daemon-reload
|
||||||
$SUDO systemctl enable frps.service
|
log "systemd units written to /etc/systemd/system/"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --- start frps ---
|
||||||
|
log "Starting frps.service"
|
||||||
|
if [ "$DRY_RUN" = 0 ]; then
|
||||||
|
$SUDO systemctl enable frps.service 2>/dev/null || true
|
||||||
$SUDO systemctl restart frps.service || true
|
$SUDO systemctl restart frps.service || true
|
||||||
sleep 2
|
sleep 2
|
||||||
if ! systemctl is-active --quiet frps.service; then
|
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
|
else
|
||||||
log "frps.service is active"
|
log "frps.service is active"
|
||||||
fi
|
fi
|
||||||
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
|
if [ "$DRY_RUN" = 0 ]; then
|
||||||
$SUDO cp runtime/frps-manager.service /etc/systemd/system/frps-manager.service
|
$SUDO systemctl enable frps-manager.service 2>/dev/null || true
|
||||||
$SUDO systemctl daemon-reload
|
|
||||||
$SUDO systemctl enable frps-manager.service
|
|
||||||
$SUDO systemctl restart frps-manager.service || true
|
$SUDO systemctl restart frps-manager.service || true
|
||||||
sleep 2
|
sleep 2
|
||||||
if ! systemctl is-active --quiet frps-manager.service; then
|
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
|
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
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
@@ -149,7 +215,7 @@ cat <<EOF
|
|||||||
================================================================
|
================================================================
|
||||||
frps-manager deployed!
|
frps-manager deployed!
|
||||||
|
|
||||||
Web UI: http://<this-host>:5390
|
Web UI: http://<this-host>:$PORT
|
||||||
Default: admin / admin (CHANGE IMMEDIATELY under "改密")
|
Default: admin / admin (CHANGE IMMEDIATELY under "改密")
|
||||||
|
|
||||||
frps bind: 0.0.0.0:7000
|
frps bind: 0.0.0.0:7000
|
||||||
@@ -157,15 +223,16 @@ cat <<EOF
|
|||||||
frps vhost_http: 0.0.0.0:80 (set FRPS_VHOST_HTTP_PORT in service to override)
|
frps vhost_http: 0.0.0.0:80 (set FRPS_VHOST_HTTP_PORT in service to override)
|
||||||
frps vhost_https: 0.0.0.0:443
|
frps vhost_https: 0.0.0.0:443
|
||||||
|
|
||||||
To customize, edit:
|
Systemd units (auto-generated with correct paths):
|
||||||
/etc/systemd/system/frps.service (frps CLI flags)
|
/etc/systemd/system/frps.service
|
||||||
/etc/systemd/system/frps-manager.service (Web UI port / env)
|
/etc/systemd/system/frps-manager.service
|
||||||
|
/etc/systemd/system/frpc@.service
|
||||||
|
|
||||||
To upgrade later:
|
To upgrade:
|
||||||
cd $PROJECT_DIR
|
cd $PROJECT_DIR
|
||||||
sudo systemctl stop frps-manager frps
|
sudo systemctl stop frps-manager frps
|
||||||
git pull
|
git pull
|
||||||
venv/bin/pip install -r requirements.txt
|
venv/bin/pip install -r requirements.txt
|
||||||
sudo systemctl start frps frps-manager
|
sudo bash scripts/deploy.sh # regenerates units + restarts
|
||||||
================================================================
|
================================================================
|
||||||
EOF
|
EOF
|
||||||
Reference in New Issue
Block a user