|
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | import signal |
3 | 3 |
|
4 | | -from daemon import runner |
| 4 | +import daemon |
| 5 | +from daemon.pidfile import PIDLockFile |
5 | 6 |
|
6 | 7 | from amplify.agent.common.context import context |
7 | 8 |
|
8 | 9 | __author__ = "Mike Belov" |
9 | 10 | __copyright__ = "Copyright (C) Nginx, Inc. All rights reserved." |
10 | 11 | __license__ = "" |
11 | | -__maintainer__ = "Mike Belov" |
12 | | -__email__ = "dedm@nginx.com" |
| 12 | +__maintainer__ = "Andrei Belov" |
| 13 | +__email__ = "a.belov@f5.com" |
13 | 14 |
|
14 | 15 |
|
15 | | -class Runner(runner.DaemonRunner): |
| 16 | +class Runner: |
16 | 17 | def __init__(self, app): |
17 | | - super(Runner, self).__init__(app) |
18 | | - |
19 | 18 | def cleanup(signum, frame): |
20 | 19 | app.stop() |
21 | 20 |
|
| 21 | + self.daemon_context = daemon.DaemonContext() |
| 22 | + |
22 | 23 | self.app = app |
23 | 24 | self.daemon_context.detach_process = True |
| 25 | + self.daemon_context.pidfile = PIDLockFile('/var/run/amplify-agent/amplify-agent.pid') |
24 | 26 | self.daemon_context.files_preserve = context.get_file_handlers() |
25 | 27 | self.daemon_context.signal_map = { |
26 | 28 | signal.SIGTERM: cleanup |
27 | 29 | } |
| 30 | + self._open_streams_from_app_stream_paths(app) |
28 | 31 |
|
29 | 32 | def _open_streams_from_app_stream_paths(self, app): |
30 | 33 | self.daemon_context.stdin = open(app.stdin_path, 'rt') |
31 | 34 | self.daemon_context.stdout = open(app.stdout_path, 'w+t') |
32 | 35 | self.daemon_context.stderr = open(app.stderr_path, 'w+t') |
| 36 | + |
| 37 | + def do_action(self): |
| 38 | + """ |
| 39 | + Stub function to mock old DaemonRunner behavior |
| 40 | + """ |
| 41 | + with self.daemon_context: |
| 42 | + self.app.run() |
0 commit comments