添加示例

This commit is contained in:
LollipopKit 2022-06-01 17:42:46 +08:00
parent df28bcc831
commit d47e03e6e5
4 changed files with 75 additions and 2 deletions

View File

@ -6,8 +6,7 @@
- 部署机器上项目文件夹名与Git项目名一致
- 部署过程需要有相应权限不可sudo
- 部署时需要在commit message中包含`[DEPLOY]`字符标记(标记可以通过`-s`参数自定义)
- 每个仓库需要先推送一次脚本后,下次才能部署
- 需要手动切换到对应的git分支
- 可能需要手动切换到对应的git分支
## 运行
```sh

5
example/README.md Normal file
View File

@ -0,0 +1,5 @@
## systemd.service
需要放在`~/.config/systemd/user`目录下
## deploy.py
需要放在git项目目录下也可以是其他脚本(.sh等),这里只是示例

55
example/deploy.py Normal file
View File

@ -0,0 +1,55 @@
import os
APP_NAME = 'free_novel_web_go'
SYSTEMD_NAME = 'freenovel.service'
def pull():
print('[pulling...]')
code = os.system('git fetch --all')
if code != 0:
return False
code = os.system('git reset --hard origin/api')
if code != 0:
return False
code = os.system('git pull')
return code == 0
def kill():
print('getting pid...')
result = os.popen(f"top -cbn1 | grep '{APP_NAME}'")
if result:
lines = result.readlines()
if len(lines) != 2:
# Skip, because there is no process
print(f'{APP_NAME} is not running')
return True
first_line = lines[0]
splited = first_line.split(' ')
pid = splited[0]
if not pid:
pid = splited[1]
print(f'killing pid {pid} ...')
exitcode = os.system('kill ' + pid)
return exitcode == 0
def build():
print('[building...]')
code = os.system('go build')
return code == 0
def start():
print('[restarting...]')
code = os.system(f'systemctl --user start {SYSTEMD_NAME}')
return code == 0
if __name__ == '__main__':
if pull():
if build():
if kill():
if start():
print(f'upgrade {APP_NAME} success')

14
example/systemd.service Normal file
View File

@ -0,0 +1,14 @@
[Unit]
Description=XXX Service
After=network.target
[Service]
Type=simple
User=lolli
Restart=on-failure
RestartSec=5s
ExecStart=/home/lolli/pro/xxx/xxx
WorkingDirectory=/home/lolli/pro/xxx
[Install]
WantedBy=multi-user.target