Simplified the daemon code and added stop and restart parameters to the linpector program.
This commit is contained in:
parent
0e8118a2c0
commit
b104698a90
2 changed files with 25 additions and 10 deletions
|
|
@ -46,10 +46,16 @@ def parse_args():
|
|||
parser.add_argument('configuration_path', metavar='CONFIGURATION_PATH',
|
||||
help='the configuration path to use')
|
||||
|
||||
mode = parser.add_mutually_exclusive_group()
|
||||
#mode = parser.add_mutually_exclusive_group()
|
||||
|
||||
mode.add_argument('-d', '--daemon', default=False, dest='daemon', action='store_true',
|
||||
help='run linspector as native daemon (default: false)')
|
||||
parser.add_argument('-d', '--daemon', default=False, dest='daemon', action='store_true',
|
||||
help='run linspector as native daemon (default: false)')
|
||||
|
||||
parser.add_argument('-k', '--kill', default=False, dest='kill', action='store_true',
|
||||
help='kill the daemon if it is running (default: false)')
|
||||
|
||||
parser.add_argument('-r', '--restart', default=False, dest='restart', action='store_true',
|
||||
help='restart the daemon if it is running(default: false)')
|
||||
|
||||
parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + str(__version__))
|
||||
|
||||
|
|
@ -90,7 +96,12 @@ def main():
|
|||
from linspector.core.linspectord import Linspectord
|
||||
linspectord = Linspectord(configuration, environment, linspector)
|
||||
# do handling of restart, start and stop commands but for now "start" is enough... ;)
|
||||
linspectord.start()
|
||||
if args.kill:
|
||||
linspectord.stop()
|
||||
elif args.restart:
|
||||
linspectord.restart()
|
||||
else:
|
||||
linspectord.start()
|
||||
except Exception as err:
|
||||
logger.error('[linspector] daemon initialization error: {0}'.format(err))
|
||||
sys.exit(1)
|
||||
|
|
|
|||
|
|
@ -15,11 +15,15 @@ logger = getLogger('linspector')
|
|||
|
||||
|
||||
class Linspectord:
|
||||
def __init__(self, pid_file, configuration, environment, linspector):
|
||||
self.__pid_file = pid_file
|
||||
|
||||
def __init__(self, configuration, environment, linspector):
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__linspector = linspector
|
||||
try:
|
||||
self.__pid_file = configuration.get_option('linspector', 'pid_file')
|
||||
except Exception as err:
|
||||
logger.error(str('daemonize error (no pid_file set): {0}'.format(err)))
|
||||
|
||||
def daemonize(self):
|
||||
# daemonize the class using the UNIX double fork mechanism.
|
||||
|
|
@ -123,7 +127,7 @@ class Linspectord:
|
|||
self.stop()
|
||||
self.start()
|
||||
|
||||
def run(self):
|
||||
"""
|
||||
a good place to execute stuff after the process has been daemonized by start() or restart().
|
||||
"""
|
||||
@staticmethod
|
||||
def run():
|
||||
while True:
|
||||
pass
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue