123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- #!/usr/bin/env python3.9
- # -*- coding: utf-8 -*-
- import os
- import subprocess
- import sys
- # 配置
- GIT_URL = "http://43.137.10.199:3000/HFLN/LAS.git"
- LOCAL_PATH = "/platform/LAS/"
- GIT_USER = "nifangxu"
- GIT_PASS = "123456"
- def run_cmd(cmd, cwd=None):
- """执行命令行并实时输出"""
- print(f"[CMD] {cmd}")
- process = subprocess.Popen(cmd, cwd=cwd, shell=True,
- stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT,
- text=True)
- for line in process.stdout:
- print(line, end="")
- process.wait()
- if process.returncode != 0:
- sys.exit(process.returncode)
- def update_repo():
- """拉取或更新代码"""
- if not os.path.exists(LOCAL_PATH):
- print("本地仓库不存在,开始克隆...")
- auth_url = GIT_URL.replace("http://", f"http://{GIT_USER}:{GIT_PASS}@")
- run_cmd(f"git clone {auth_url} {LOCAL_PATH}")
- else:
- print("本地仓库已存在,开始更新...")
- run_cmd("git reset --hard", cwd=LOCAL_PATH)
- run_cmd("git pull", cwd=LOCAL_PATH)
- # 设置权限
- print("设置文件权限...")
- run_cmd("dos2unix *", cwd=LOCAL_PATH)
- run_cmd("chmod +x *.py", cwd=LOCAL_PATH)
- def check_repo():
- """检查仓库目录是否存在"""
- if not os.path.exists(LOCAL_PATH):
- print("❌ 本地代码目录不存在,请先执行: python3 LAS-deploy.py update")
- sys.exit(1)
- def start_service():
- check_repo()
- print("启动 LAS 服务...")
- run_cmd("./start.py", cwd=LOCAL_PATH)
- def stop_service():
- check_repo()
- print("停止 LAS 服务...")
- run_cmd("./stop.py", cwd=LOCAL_PATH)
- def restart_service():
- check_repo()
- print("重启 LAS 服务...")
- run_cmd("./stop.py || true", cwd=LOCAL_PATH)
- run_cmd("./start.py", cwd=LOCAL_PATH)
- def status_service():
- check_repo()
- print("查看 LAS 服务状态...")
- run_cmd("./status.py", cwd=LOCAL_PATH)
- def main():
- if len(sys.argv) < 2:
- print("用法: python3 LAS-deploy.py [update|start|stop|restart|status]")
- sys.exit(1)
- action = sys.argv[1].lower()
- if action == "update":
- update_repo()
- elif action == "start":
- start_service()
- elif action == "stop":
- stop_service()
- elif action == "restart":
- restart_service()
- elif action == "status":
- status_service()
- else:
- print(f"未知参数: {action}")
- print("可用参数: update | start | stop | restart | status")
- sys.exit(1)
- print(f"✅ 操作完成: {action}")
- if __name__ == "__main__":
- main()
|