Skip to content

Commit d6aa13b

Browse files
daemon update
1 parent c21b674 commit d6aa13b

2 files changed

Lines changed: 19 additions & 25 deletions

File tree

app.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async def lifespan(app: FastAPI):
4242
app.mount("/static", StaticFiles(directory="/home/jetson/Desktop/H3RU/static"), name="static")
4343

4444
# Log Dosyası Ayarları
45-
logging.basicConfig(filename='access_log.txt', level=logging.INFO, format='%(asctime)s - %(message)s')
45+
logging.basicConfig(filename='/home/jetson/Desktop/H3RU/access_log.txt', level=logging.INFO, format='%(asctime)s - %(message)s')
4646

4747
# Sound directory for doorbell sounds
4848
SOUNDS_DIR = os.path.join("/home/jetson/Desktop/H3RU/static", "sounds")
@@ -251,14 +251,15 @@ async def voice_websocket_endpoint(websocket: WebSocket):
251251
def main():
252252
loop = asyncio.get_event_loop()
253253
loop.create_task(read_from_arduino())
254+
254255
if __name__ == "__main__":
255256
import uvicorn
256257
uvicorn.run(
257258
"app:app",
258259
host="0.0.0.0",
259260
port=8001,
260-
ssl_certfile="cert.pem",
261-
ssl_keyfile="key.pem",
261+
ssl_certfile="/home/jetson/Desktop/H3RU/cert.pem", # Update with the correct path
262+
ssl_keyfile="/home/jetson/Desktop/H3RU/key.pem", # Update with the correct path
262263
ws='auto',
263264
http='auto'
264265
)

daemon.py

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
1-
import os
2-
import time
31
import subprocess
4-
5-
def is_process_running(process_name):
6-
"""Belirtilen process'in çalışıp çalışmadığını kontrol eder."""
7-
try:
8-
subprocess.check_output(["pgrep", "-f", process_name])
9-
return True
10-
except subprocess.CalledProcessError:
11-
return False
2+
import time
3+
import psutil
124

135
def start_application():
14-
"""Uygulamayı başlatır."""
15-
subprocess.Popen(["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8001"])
6+
"""Start the application."""
7+
subprocess.Popen(["/bin/bash", "-c", "cd /home/jetson/Desktop/H3RU/ && Xvfb :99 -screen 0 1024x768x16 & export DISPLAY=:99 && sudo python3 /home/jetson/Desktop/H3RU/app.py"])
168

17-
def main():
18-
process_name = "uvicorn"
19-
while True:
20-
if not is_process_running(process_name):
21-
print("Uygulama çalışmıyor, başlatılıyor...")
22-
start_application()
23-
else:
24-
print("Uygulama çalışıyor.")
25-
time.sleep(5)
9+
def is_application_running():
10+
"""Check if the application is running."""
11+
for proc in psutil.process_iter(['pid', 'name', 'cmdline']):
12+
if 'python3' in proc.info['cmdline'] and 'app.py' in proc.info['cmdline']:
13+
return True
14+
return False
2615

2716
if __name__ == "__main__":
28-
main()
17+
start_application()
18+
while True:
19+
time.sleep(600) # Sleep for 10 minutes
20+
if not is_application_running():
21+
start_application()

0 commit comments

Comments
 (0)