修改运行路径
This commit is contained in:
+1
-1
@@ -73,7 +73,7 @@ func generateSecret() string {
|
|||||||
// getDefaultSocketPath returns the OS-aware default unix socket path.
|
// getDefaultSocketPath returns the OS-aware default unix socket path.
|
||||||
func getDefaultSocketPath() string {
|
func getDefaultSocketPath() string {
|
||||||
if runtime.GOOS == "linux" {
|
if runtime.GOOS == "linux" {
|
||||||
return "/opt/blog_go/web.sock"
|
return "/run/blog_go/web.sock"
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-2
@@ -7,6 +7,7 @@ CONFIG_DIR="/etc/${SERVICE_NAME}"
|
|||||||
DATA_DIR="/srv/${SERVICE_NAME}"
|
DATA_DIR="/srv/${SERVICE_NAME}"
|
||||||
INSTALL_DIR="/opt/${SERVICE_NAME}"
|
INSTALL_DIR="/opt/${SERVICE_NAME}"
|
||||||
BINARY_NAME="${SERVICE_NAME}"
|
BINARY_NAME="${SERVICE_NAME}"
|
||||||
|
SOCKET_DIR="/run/${SERVICE_NAME}"
|
||||||
SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service"
|
SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service"
|
||||||
|
|
||||||
if [[ "${EUID}" -ne 0 ]]; then
|
if [[ "${EUID}" -ne 0 ]]; then
|
||||||
@@ -31,6 +32,8 @@ fi
|
|||||||
echo "创建目录..."
|
echo "创建目录..."
|
||||||
install -d -m 0750 -o "${SERVICE_USER}" -g "${SERVICE_USER}" "${CONFIG_DIR}" "${DATA_DIR}"
|
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 -o "${SERVICE_USER}" -g "${SERVICE_USER}" "${INSTALL_DIR}"
|
||||||
|
install -d -m 0755 "${SOCKET_DIR}"
|
||||||
|
chown "${SERVICE_USER}:${SERVICE_USER}" "${SOCKET_DIR}"
|
||||||
|
|
||||||
echo "安装程序和模板文件..."
|
echo "安装程序和模板文件..."
|
||||||
install -m 0755 -o root -g root "${SCRIPT_DIR}/${BINARY_NAME}" "${INSTALL_DIR}/${BINARY_NAME}"
|
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 d -exec chmod 0755 {} \;
|
||||||
find "${INSTALL_DIR}/templates" -type f -exec chmod 0644 {} \;
|
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
|
if [[ ! -f "${CONFIG_DIR}/config.yaml" ]]; then
|
||||||
SECRET=$(openssl rand -hex 32)
|
SECRET=$(openssl rand -hex 32)
|
||||||
@@ -73,12 +76,15 @@ User=${SERVICE_USER}
|
|||||||
Group=${SERVICE_USER}
|
Group=${SERVICE_USER}
|
||||||
WorkingDirectory=${INSTALL_DIR}
|
WorkingDirectory=${INSTALL_DIR}
|
||||||
ExecStart=${INSTALL_DIR}/${BINARY_NAME} -config ${CONFIG_DIR}/config.yaml
|
ExecStart=${INSTALL_DIR}/${BINARY_NAME} -config ${CONFIG_DIR}/config.yaml
|
||||||
|
ExecStartPost=/bin/chmod 666 ${SOCKET_DIR}/web.sock
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
RestartSec=5s
|
RestartSec=5s
|
||||||
NoNewPrivileges=true
|
NoNewPrivileges=true
|
||||||
PrivateTmp=true
|
PrivateTmp=true
|
||||||
ProtectSystem=full
|
ProtectSystem=full
|
||||||
ReadWritePaths=${CONFIG_DIR} ${DATA_DIR} ${INSTALL_DIR}
|
ReadWritePaths=${CONFIG_DIR} ${DATA_DIR} ${INSTALL_DIR} ${SOCKET_DIR}
|
||||||
|
RuntimeDirectory=${SERVICE_NAME}
|
||||||
|
RuntimeDirectoryMode=0755
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|||||||
Reference in New Issue
Block a user