Added pidfile option to the main
This commit is contained in:
parent
44d24b42d1
commit
fb75dc323e
1 changed files with 17 additions and 2 deletions
|
@ -7,6 +7,7 @@ Platypush
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
@ -41,21 +42,31 @@ class Daemon:
|
||||||
# - plugins will post the responses they process
|
# - plugins will post the responses they process
|
||||||
bus = None
|
bus = None
|
||||||
|
|
||||||
|
pidfile = None
|
||||||
|
|
||||||
# backend_name => backend_obj map
|
# backend_name => backend_obj map
|
||||||
backends = None
|
backends = None
|
||||||
|
|
||||||
# number of executions retries before a request fails
|
# number of executions retries before a request fails
|
||||||
n_tries = 2
|
n_tries = 2
|
||||||
|
|
||||||
def __init__(self, config_file=None, requests_to_process=None):
|
def __init__(self, config_file=None, pidfile=None, requests_to_process=None):
|
||||||
"""
|
"""
|
||||||
Constructor
|
Constructor
|
||||||
Params:
|
Params:
|
||||||
config_file -- Configuration file override (default: None)
|
config_file -- Configuration file override (default: None)
|
||||||
|
pidfile -- File where platypush will store its PID upon launch,
|
||||||
|
useful if you're planning to integrate the application
|
||||||
|
within a service or a launcher script (default: None)
|
||||||
requests_to_process -- Exit after processing the specified number
|
requests_to_process -- Exit after processing the specified number
|
||||||
of requests (default: None, loop forever)
|
of requests (default: None, loop forever)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if pidfile:
|
||||||
|
self.pidfile = pidfile
|
||||||
|
with open(self.pidfile, 'w') as f:
|
||||||
|
f.write(os.getpid())
|
||||||
|
|
||||||
self.config_file = config_file
|
self.config_file = config_file
|
||||||
self.event_processor = EventProcessor()
|
self.event_processor = EventProcessor()
|
||||||
self.requests_to_process = requests_to_process
|
self.requests_to_process = requests_to_process
|
||||||
|
@ -74,9 +85,13 @@ class Daemon:
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('--config', '-c', dest='config', required=False,
|
parser.add_argument('--config', '-c', dest='config', required=False,
|
||||||
default=None, help=cls.config_file.__doc__)
|
default=None, help=cls.config_file.__doc__)
|
||||||
|
parser.add_argument('--pidfile', '-P', dest='pidfile', required=False,
|
||||||
|
default=None, help="File where platypush will " +
|
||||||
|
"store its PID, useful if you're planning to " +
|
||||||
|
"integrate it in a service")
|
||||||
|
|
||||||
opts, args = parser.parse_known_args(args)
|
opts, args = parser.parse_known_args(args)
|
||||||
return cls(config_file=opts.config)
|
return cls(config_file=opts.config, pidfile=opts.pidfile)
|
||||||
|
|
||||||
def on_message(self):
|
def on_message(self):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue