This commit is contained in:
2023-08-24 16:58:18 +08:00
parent 786b0c7ce9
commit e609574ed7
+9 -6
View File
@@ -6,7 +6,7 @@ if id "appruner" >/dev/null 2>&1; then
else else
# 创建 app 用户 # 创建 app 用户
echo "Creating user appruner..." echo "Creating user appruner..."
useradd -m -s /bin/bash appruner sudo useradd -m -s /bin/bash appruner
fi fi
@@ -15,21 +15,24 @@ app_path=$(cd "$(dirname "$0")"; pwd)
app_name=$(basename "${app_path}") app_name=$(basename "${app_path}")
# 执行 git pull 命令 # 执行 git pull 命令
# 判断目录是否存在 .git 文件夹
if [ -d "$app_path/.git" ]; then
cd ${app_path} && git pull cd ${app_path} && git pull
fi
# 执行 go build 命令 # 执行 go build 命令
cd ${app_path} && go build -o app cd ${app_path} && go build -o app
cp app.service.example ${app_name}.service sudo cp app.service.example ${app_name}.service
# 替换 app.service 文件中的 APP_PATH # 替换 app.service 文件中的 APP_PATH
sed -i "s|APP_PATH|${app_path}|g" ${app_name}.service sed -i "s|APP_PATH|${app_path}|g" ${app_name}.service
mv ${app_name}.service /etc/systemd/system/${app_name}.service sudo mv ${app_name}.service /etc/systemd/system/${app_name}.service
# 重新加载 systemd 配置文件 # 重新加载 systemd 配置文件
systemctl daemon-reload sudo systemctl daemon-reload
# 重新启动应用程序服务 # 重新启动应用程序服务
systemctl stop ${app_name}.service sudo systemctl stop ${app_name}.service
systemctl start ${app_name}.service sudo systemctl start ${app_name}.service