use daemonize and attach to foreground

This commit is contained in:
Josh Burman 2021-11-01 20:57:20 +00:00
parent 449c33915f
commit 3a95003493
3 changed files with 23 additions and 41 deletions

View File

@ -11,11 +11,11 @@ RUN cd Cbc-2.9.8 && \
make install make install
RUN python -m pip install pydantic RUN python -m pip install pydantic
RUN python -m pip install pySqsListener RUN python -m pip install pySqsListener
RUN python -m pip install daemonize
# Bundle app source # Bundle app source
COPY . /app COPY . /app
WORKDIR /app/app WORKDIR /app/app
# CMD [ "python", "main.py" ] CMD [ "python", "main.py" ]
CMD tail -f /dev/null

View File

@ -11,11 +11,11 @@ RUN cd Cbc-2.9.8 && \
make install make install
RUN python -m pip install pydantic RUN python -m pip install pydantic
RUN python -m pip install pySqsListener RUN python -m pip install pySqsListener
RUN python -m pip install daemonize
# Bundle app source # Bundle app source
COPY . /app COPY . /app
WORKDIR /app/app WORKDIR /app/app
# CMD [ "python", "main.py" ] CMD [ "python", "main.py" ]
CMD tail -f /dev/null

View File

@ -1,14 +1,10 @@
import os import os, sys, json, time
import sys
import json
import time
from services.loft_service import LoftService from services.loft_service import LoftService
from helpers import aws_helper from helpers import aws_helper
from daemonize import Daemonize
from sqs_listener import SqsListener from sqs_listener import SqsListener
from sqs_listener.daemon import Daemon
class ServiceListener(SqsListener): class ServiceListener(SqsListener):
def handle_message(self, body, attributes, messages_attributes): def handle_message(self, body, attributes, messages_attributes):
@ -18,8 +14,7 @@ class ServiceListener(SqsListener):
service.process() service.process()
# log the things # log the things
class ServiceDaemon(Daemon): def main():
def run(self):
print("Starting Solver Service (v0.3.2)...") print("Starting Solver Service (v0.3.2)...")
print("Initializing listener") print("Initializing listener")
listener = ServiceListener( listener = ServiceListener(
@ -31,21 +26,8 @@ class ServiceDaemon(Daemon):
) )
listener.listen() listener.listen()
if __name__ == "__main__": if __name__ == '__main__':
daemon = ServiceDaemon('/var/run/sqs_daemon.pid',stdout='/app/logs/stdout', stderr='/app/logs/stderr', stdin='/app/logs/stdin') myname=os.path.basename(sys.argv[0])
if len(sys.argv) == 2: pidfile='/tmp/%s' % myname # any name
if 'start' == sys.argv[1]: daemon = Daemonize(app=myname,pid=pidfile, action=main, foreground=True)
print("Starting listener daemon")
daemon.start() daemon.start()
elif 'stop' == sys.argv[1]:
print("Attempting to stop the daemon")
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)