Skip to content

Commit

Permalink
update system service
Browse files Browse the repository at this point in the history
  • Loading branch information
柏霜 committed Dec 5, 2024
1 parent 72b8bab commit 688a986
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions .computenest/ros_templates/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -249,21 +249,22 @@ Resources:
# 本地不存在镜像,且为私有镜像则进行登录registry
if [ "${AcrUsername}" != "" ]; then
echo "login to docker registry"
AcrRepoName=$(echo ${ImagePullPath} | awk -F/ '{print $1}')
docker login $AcrRepoName --username=${AcrUsername} --password=${AcrPassword}
server=$(echo ${ImagePullPath} | awk -F/ '{print $1}')
docker login $server --username=${AcrUsername} --password=${AcrPassword}
fi
fi

# 保存环境变量
mkdir -p /opt/applicationmanager
touch /opt/applicationmanager/app.env
yum install -y jq
echo ${EnvVar} | jq -r '.[] | to_entries | .[] | "\(.key)=\(.value)"' >> /opt/applicationmanager/app.env

# 停止已有的服务
systemctl stop docker-application
systemctl stop aliyun-applicationmanager

# 创建系统服务
cat > /etc/systemd/system/docker-application.service <<EOF
cat > /etc/systemd/system/aliyun-applicationmanager.service <<EOF
[Unit]
Description=Docker application
Requires=docker.service
Expand All @@ -273,16 +274,17 @@ Resources:
Restart=always
RemainAfterExit=yes
WorkingDirectory=/opt/applicationmanager
ExecStartPre=docker stop -t 10 $(/usr/bin/docker ps -q --filter "ancestor=${ImagePullPath}")
ExecStart=docker run --restart unless-stopped --network=host --env-file app.env ${ImagePullPath}
ExecStop=docker stop -t 10 $(/usr/bin/docker ps -q --filter "ancestor=${ImagePullPath}")
ExecStart=docker run --name applicationmanager --rm --network=host --env-file app.env ${ImagePullPath}
ExecStop=docker stop -t 10 applicationmanager
TimeoutStartSec=0

[Install]
WantedBy=multi-user.target
EOF

systemctl start docker-application
systemctl daemon-reload
systemctl enable aliyun-applicationmanager
systemctl start aliyun-applicationmanager
Type: RunShellScript
InstanceIds:
Fn::GetAtt:
Expand Down

0 comments on commit 688a986

Please sign in to comment.