Spaces:
Paused
Paused
github-actions[bot]
commited on
Commit
·
b4a1e45
1
Parent(s):
e3a0f57
Update from GitHub Actions
Browse files- playbook.yml +22 -12
playbook.yml
CHANGED
|
@@ -1,12 +1,17 @@
|
|
| 1 |
- name: My first play
|
| 2 |
hosts: hostgroup
|
| 3 |
remote_user: root
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
tasks:
|
| 5 |
-
- name:
|
| 6 |
shell: |
|
| 7 |
-
pid=$(ps -ef | grep "uvicorn main:app" | grep -v grep | awk '{print $2}')
|
| 8 |
if [ -n "$pid" ]; then
|
| 9 |
-
echo "Stopping process with PID: $pid"
|
| 10 |
kill -15 $pid
|
| 11 |
sleep 3
|
| 12 |
if ps -p $pid > /dev/null 2>&1; then
|
|
@@ -14,7 +19,7 @@
|
|
| 14 |
kill -9 $pid
|
| 15 |
fi
|
| 16 |
else
|
| 17 |
-
echo "No running process found"
|
| 18 |
fi
|
| 19 |
args:
|
| 20 |
executable: /bin/bash
|
|
@@ -22,32 +27,37 @@
|
|
| 22 |
|
| 23 |
- name: 确认服务已停止
|
| 24 |
wait_for:
|
| 25 |
-
port:
|
| 26 |
state: stopped
|
| 27 |
timeout: 30
|
| 28 |
|
| 29 |
- name: 复制到远程服务器
|
| 30 |
copy:
|
| 31 |
src: archive/release.tar.gz
|
| 32 |
-
dest: /root/deploy/
|
| 33 |
|
| 34 |
- name: 解压文件
|
| 35 |
shell: |
|
| 36 |
-
rm -rf
|
| 37 |
-
mkdir -p
|
| 38 |
-
tar -zxvf /root/deploy/
|
| 39 |
args:
|
| 40 |
executable: /bin/bash
|
| 41 |
|
| 42 |
- name: 构建并运行
|
| 43 |
shell: |
|
| 44 |
-
cd
|
| 45 |
pip install --no-cache-dir -r requirements.txt
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
args:
|
| 48 |
executable: /bin/bash
|
| 49 |
|
| 50 |
- name: 等待服务启动
|
| 51 |
wait_for:
|
| 52 |
-
port:
|
| 53 |
timeout: 30
|
|
|
|
| 1 |
- name: My first play
|
| 2 |
hosts: hostgroup
|
| 3 |
remote_user: root
|
| 4 |
+
vars:
|
| 5 |
+
app_name: scraper-proxy
|
| 6 |
+
app_port: 7860
|
| 7 |
+
deploy_path: /root/workspace/scraper-proxy
|
| 8 |
+
|
| 9 |
tasks:
|
| 10 |
+
- name: 停止特定应用服务
|
| 11 |
shell: |
|
| 12 |
+
pid=$(ps -ef | grep "uvicorn main:app" | grep "{{ app_port }}" | grep -v grep | awk '{print $2}')
|
| 13 |
if [ -n "$pid" ]; then
|
| 14 |
+
echo "Stopping {{ app_name }} process with PID: $pid"
|
| 15 |
kill -15 $pid
|
| 16 |
sleep 3
|
| 17 |
if ps -p $pid > /dev/null 2>&1; then
|
|
|
|
| 19 |
kill -9 $pid
|
| 20 |
fi
|
| 21 |
else
|
| 22 |
+
echo "No running {{ app_name }} process found"
|
| 23 |
fi
|
| 24 |
args:
|
| 25 |
executable: /bin/bash
|
|
|
|
| 27 |
|
| 28 |
- name: 确认服务已停止
|
| 29 |
wait_for:
|
| 30 |
+
port: "{{ app_port }}"
|
| 31 |
state: stopped
|
| 32 |
timeout: 30
|
| 33 |
|
| 34 |
- name: 复制到远程服务器
|
| 35 |
copy:
|
| 36 |
src: archive/release.tar.gz
|
| 37 |
+
dest: /root/deploy/{{ app_name }}.tar.gz
|
| 38 |
|
| 39 |
- name: 解压文件
|
| 40 |
shell: |
|
| 41 |
+
rm -rf {{ deploy_path }}
|
| 42 |
+
mkdir -p {{ deploy_path }}
|
| 43 |
+
tar -zxvf /root/deploy/{{ app_name }}.tar.gz -C {{ deploy_path }}
|
| 44 |
args:
|
| 45 |
executable: /bin/bash
|
| 46 |
|
| 47 |
- name: 构建并运行
|
| 48 |
shell: |
|
| 49 |
+
cd {{ deploy_path }}
|
| 50 |
pip install --no-cache-dir -r requirements.txt
|
| 51 |
+
echo '#!/bin/bash
|
| 52 |
+
cd {{ deploy_path }}
|
| 53 |
+
exec uvicorn main:app --host 0.0.0.0 --port {{ app_port }}
|
| 54 |
+
' > {{ deploy_path }}/start.sh
|
| 55 |
+
chmod +x {{ deploy_path }}/start.sh
|
| 56 |
+
nohup {{ deploy_path }}/start.sh > {{ deploy_path }}/nohup.log 2>&1 &
|
| 57 |
args:
|
| 58 |
executable: /bin/bash
|
| 59 |
|
| 60 |
- name: 等待服务启动
|
| 61 |
wait_for:
|
| 62 |
+
port: "{{ app_port }}"
|
| 63 |
timeout: 30
|