forked from TeamWiseFlow/wiseflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindows_run.py
79 lines (68 loc) · 2.29 KB
/
windows_run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import os
import sys
import subprocess
import socket
import psutil
from pathlib import Path
#檢查指定端口是否被使用
def is_port_in_use(port):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
try:
s.bind(('127.0.0.1', port))
return False
except socket.error:
return True
#檢查指定進程是否在運行
def is_process_running(process_name):
for proc in psutil.process_iter(['name']):
try:
if process_name.lower() in proc.info['name'].lower():
return True
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
pass
return False
#啟動 PocketBase 服務
def start_pocketbase():
try:
# 檢查 PocketBase 是否已在運行
if is_process_running('pocketbase'):
print("PocketBase is already running.")
return True
# 檢查端口是否被佔用
if is_port_in_use(8090):
print("Port 8090 is already in use.")
return False
# 構建 PocketBase 路徑
current_dir = Path(__file__).parent
pb_path = current_dir.parent / 'pb' / 'pocketbase.exe' # Windows 使用 .exe
if not pb_path.exists():
print(f"PocketBase executable not found at: {pb_path}")
return False
# 啟動 PocketBase
print("Starting PocketBase...")
subprocess.Popen([
str(pb_path),
'serve',
'--http=127.0.0.1:8090'
],
creationflags=subprocess.CREATE_NEW_CONSOLE) # Windows 特定標誌
return True
except Exception as e:
print(f"Error starting PocketBase: {e}")
return False
def main():
# 啟動 PocketBase
if start_pocketbase():
# 運行 Python 處理腳本
try:
process_script = Path(__file__).parent / 'run_task.py'
if process_script.exists():
subprocess.run([sys.executable, str(process_script)], check=True)
else:
print(f"Error: run_task.py not found at: {process_script}")
except subprocess.CalledProcessError as e:
print(f"Error running run_task.py: {e}")
else:
print("Failed to start services")
if __name__ == '__main__':
main()