Пытался так:
Dockerfile
FROM python:3.7-slim
COPY . .
RUN python -m pip install -r requirements.txt
CMD python daemin.py start && python main.py
В контейнере пишет, что запущен, но ничего не происходит.
daemon.py
import os
import time
import sys
import atexit
import signal
from pathlib import Path
class Daemon:
"""A generic daemon class.
Usage: subclass the daemon class and override the run() method.
"""
....
class MyDaemon(Daemon):
def __init__(self, audio_directory, pidfile, every_n_minutes: int = 8):
super().__init__(pidfile)
self.audio_directory = audio_directory
self.secs = every_n_minutes * 60
def run(self):
while True:
wav_clean_deamon(self.audio_directory)
time.sleep(self.secs)
if __name__ == "__main__":
daemon = MyDaemon(
audio_directory=str(Path(".").resolve() / "temp"),
pidfile="/tmp/mydaemon.pid",
every_n_minutes=1)
if len(sys.argv) == 2:
if "start" == sys.argv[1]:
daemon.start()
elif "stop" == sys.argv[1]:
daemon.stop()
elif "restart" == sys.argv[1]:
daemon.restart()
else:
print("Unknown command")
sys.exit(2)
sys.exit(0)
else:
print("usage: %s start|stop|restart" % sys.argv[0])
sys.exit(2)
В main.py запускается сервис grpc
if __name__ == "__main__":
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
address = f"localhost:8181"
server.add_insecure_port(address)
server.start()
server.wait_for_termination()