修改运行路径

This commit is contained in:
2026-06-24 11:32:45 +08:00
parent 1fc933e014
commit 2875918289
2 changed files with 9 additions and 3 deletions
+1 -1
View File
@@ -73,7 +73,7 @@ func generateSecret() string {
// getDefaultSocketPath returns the OS-aware default unix socket path.
func getDefaultSocketPath() string {
if runtime.GOOS == "linux" {
return "/opt/blog_go/web.sock"
return "/run/blog_go/web.sock"
}
return ""
}
+8 -2
View File
@@ -7,6 +7,7 @@ CONFIG_DIR="/etc/${SERVICE_NAME}"
DATA_DIR="/srv/${SERVICE_NAME}"
INSTALL_DIR="/opt/${SERVICE_NAME}"
BINARY_NAME="${SERVICE_NAME}"
SOCKET_DIR="/run/${SERVICE_NAME}"
SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service"
if [[ "${EUID}" -ne 0 ]]; then
@@ -31,6 +32,8 @@ fi
echo "创建目录..."
install -d -m 0750 -o "${SERVICE_USER}" -g "${SERVICE_USER}" "${CONFIG_DIR}" "${DATA_DIR}"
install -d -m 0755 -o "${SERVICE_USER}" -g "${SERVICE_USER}" "${INSTALL_DIR}"
install -d -m 0755 "${SOCKET_DIR}"
chown "${SERVICE_USER}:${SERVICE_USER}" "${SOCKET_DIR}"
echo "安装程序和模板文件..."
install -m 0755 -o root -g root "${SCRIPT_DIR}/${BINARY_NAME}" "${INSTALL_DIR}/${BINARY_NAME}"
@@ -42,7 +45,7 @@ chmod 0755 "${INSTALL_DIR}"
find "${INSTALL_DIR}/templates" -type d -exec chmod 0755 {} \;
find "${INSTALL_DIR}/templates" -type f -exec chmod 0644 {} \;
SOCKET_PATH="${INSTALL_DIR}/web.sock"
SOCKET_PATH="${SOCKET_DIR}/web.sock"
if [[ ! -f "${CONFIG_DIR}/config.yaml" ]]; then
SECRET=$(openssl rand -hex 32)
@@ -73,12 +76,15 @@ User=${SERVICE_USER}
Group=${SERVICE_USER}
WorkingDirectory=${INSTALL_DIR}
ExecStart=${INSTALL_DIR}/${BINARY_NAME} -config ${CONFIG_DIR}/config.yaml
ExecStartPost=/bin/chmod 666 ${SOCKET_DIR}/web.sock
Restart=on-failure
RestartSec=5s
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=full
ReadWritePaths=${CONFIG_DIR} ${DATA_DIR} ${INSTALL_DIR}
ReadWritePaths=${CONFIG_DIR} ${DATA_DIR} ${INSTALL_DIR} ${SOCKET_DIR}
RuntimeDirectory=${SERVICE_NAME}
RuntimeDirectoryMode=0755
[Install]
WantedBy=multi-user.target