113 lines
4.2 KiB
Python
Executable file
113 lines
4.2 KiB
Python
Executable file
#!/usr/bin/python3 -d
|
|
"""
|
|
This file is part of Linspector (https://linspector.org/)
|
|
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
|
See LICENSE.txt (MIT license).
|
|
"""
|
|
# TODO: VERY IMPORTANT! IMPLEMENT ERROR HANDLING ALL THE WAY...!!!
|
|
# Only exit execution on critical core errors. Do not exit when monitors are failing on
|
|
# configuration and execution, but log these errors.
|
|
import argparse
|
|
import sys
|
|
|
|
from linspector.core.configuration import Configuration
|
|
from linspector.core.environment import Environment
|
|
from linspector.core.linspector import Linspector
|
|
from linspector.core.logger import Log
|
|
from linspector.core.monitors import Monitors
|
|
|
|
# i currently only increase the 3rd number because the goal is that 0.19.* will become the first
|
|
# stable version.
|
|
__version__ = '0.19.64.dev1'
|
|
__author__ = 'Johannes Findeisen <you@hanez.org>'
|
|
|
|
|
|
def parse_args():
|
|
parser = argparse.ArgumentParser(
|
|
description='linspector is a infrastructure and system monitoring daemon and toolchain.',
|
|
epilog='author: ' + __author__,
|
|
prog='linspector')
|
|
|
|
parser.add_argument('configuration_path', metavar='CONFIGURATION_PATH',
|
|
help='the configuration path to use')
|
|
|
|
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('-s', '--stdout', default=False, dest='stdout', action='store_true',
|
|
help='log to stdout')
|
|
|
|
parser.add_argument('-V', '--verbose', default=False, dest='verbose', action='store_true',
|
|
help='log in debug mode')
|
|
|
|
parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + str(__version__))
|
|
|
|
return parser.parse_args()
|
|
|
|
|
|
def main():
|
|
args = parse_args()
|
|
monitors = None
|
|
notifications = {}
|
|
plugins = {}
|
|
# the scheduler is a dict to make it possible in the future to run more than one scheduler in
|
|
# one linspector instance. need to think about it a little more...
|
|
scheduler = {}
|
|
services = {}
|
|
tasks = {}
|
|
|
|
try:
|
|
configuration = Configuration(args.configuration_path)
|
|
except Exception as err:
|
|
print('[linspector] configuration error: {0}'.format(err))
|
|
sys.exit(1)
|
|
|
|
log = Log(configuration, args.stdout, args.verbose)
|
|
environment = Environment(log)
|
|
|
|
try:
|
|
monitors = Monitors(configuration, environment, log, notifications, services, tasks)
|
|
except Exception as err:
|
|
log.warning('[linspector] monitor initialization error: {0}'.format(err))
|
|
|
|
try:
|
|
linspector = Linspector(configuration, environment, log, monitors, plugins, scheduler)
|
|
# linspector.print_debug()
|
|
except Exception as err:
|
|
log.critical('[linspector] core initialization error: {0}'.format(err))
|
|
sys.exit(1)
|
|
|
|
# daemon initialization
|
|
if args.daemon:
|
|
try:
|
|
from linspector.core.linspectord import Linspectord
|
|
linspectord = Linspectord(configuration, environment, linspector, log)
|
|
# do handling of restart, start and stop commands but for now "start" is enough... ;)
|
|
if args.kill:
|
|
log.info('[linspector] stopping daemon.')
|
|
linspectord.stop()
|
|
elif args.restart:
|
|
log.info('[linspector] restarting daemon.')
|
|
linspectord.restart()
|
|
else:
|
|
log.info('[linspector] starting daemon.')
|
|
linspectord.start()
|
|
except Exception as err:
|
|
log.critical('[linspector] daemon error: {0}'.format(err))
|
|
sys.exit(1)
|
|
else:
|
|
try:
|
|
while True:
|
|
pass
|
|
except KeyboardInterrupt:
|
|
log.info('[linspector] program terminated by user!')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|