这与这个单独的本质上是相同的问题
我有一个位桶管道文件bitbucket-pipelines.yml
,它在对main
分支进行新的提交时执行文件deploy.sh
。deploy.sh
依次调用pull.sh
,后者执行一组操作:
- 如果存在,则终止现有的
refgator-api.py
进程 - 更改为包含回购的目录
- 从回购中提取
- 更改为包含
refgator-api.py
的目录 - 执行
python3 refgator-api.py
在最后一步,我的比特桶管道将继续执行(消耗我所有的构建分钟数(。
在pull.sh
执行了python3 refgator-api.py
之后,有什么方法可以成功完成比特桶管道吗?
比特币
image: atlassian/default-image:latest
pipelines:
default:
- step:
script:
- cat ./deploy.sh | ssh -tt root@xxx.xxx.xxx.xxx
- echo "Deploy step finished"
deploy.sh
echo "Deploy Script Started"
cd
sh pull.sh
echo "Deploy script finished execution"
pull.sh
## Kills the current process which is restarted later
kill -9 $(pgrep -f refgator-api.py)
## And change to directory containing the repo
cd eg-api
## Pull from the repo
export GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa.pub"
GIT_SSH_COMMAND="ssh -v" git pull git@bitbucket.org:myusername/myrepo.git
## Change to directory containing the python file to execute
cd refgator-api
python3 refgator-api.py &
这里的关键问题是试图启动并运行python脚本refgator-api.py
并关闭会话。
这似乎不可能直接使用shell脚本。但是,可以在远程服务器上使用supervisor
。
在这种情况下,我安装了监控器apt-get install supervisor
,并执行了以下操作:
比特桶管道
image: atlassian/default-image:latest
pipelines:
default:
- step:
script:
- cat ./deploy.sh | ssh -tt root@143.198.164.197
- echo "DEPLOY STEP FINISHED"
部署.sh
printf "=== Deploy Script Started ===n"
printf "Stop all supervisorctl processesn"
supervisorctl stop all
sh refgator-pull.sh
printf "Start all supervisorctl processesn"
supervisorctl start all
exit
Pull.sh
printf "==== Repo Pull ====n"
printf "Attempting pull from repon"
export GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa.pub"
GIT_SSH_COMMAND="ssh " git pull git@bitbucket.org:myusername/myrepo.git
printf "Repo: Local Copy Updatedn"