36 lines
791 B
Bash
36 lines
791 B
Bash
#!/bin/bash
|
|
|
|
# 判断 app 用户是否存在
|
|
if id "appruner" >/dev/null 2>&1; then
|
|
echo "User appruner exists."
|
|
else
|
|
# 创建 app 用户
|
|
echo "Creating user appruner..."
|
|
useradd -m -s /bin/bash appruner
|
|
fi
|
|
|
|
app_name=gin-article
|
|
|
|
# 获取当前目录的绝对路径
|
|
app_path=$(cd "$(dirname "$0")"; pwd)
|
|
|
|
# 执行 git pull 命令
|
|
cd ${app_path} && git pull
|
|
|
|
# 执行 go build 命令
|
|
cd ${app_path} && go build -o app
|
|
|
|
cp app.service.example ${app_name}.service
|
|
|
|
# 替换 app.service 文件中的 APP_PATH
|
|
sed -i "s|APP_PATH|${app_path}|g" ${app_name}.service
|
|
|
|
mv ${app_name}.service /etc/systemd/system/${app_name}.service
|
|
|
|
# 重新加载 systemd 配置文件
|
|
systemctl daemon-reload
|
|
|
|
systemctl stop ${app_name}.service
|
|
|
|
# 启动应用程序服务
|
|
systemctl start ${app_name}.service |