Some more logging fixes in linspectord.py.
This commit is contained in:
parent
ddc20342d6
commit
220079e64b
2 changed files with 13 additions and 15 deletions
|
|
@ -37,7 +37,7 @@ logger = logging.getLogger('linspector')
|
||||||
|
|
||||||
# i currently only increase the 3rd number because the goal is that 0.20.* will become the first
|
# i currently only increase the 3rd number because the goal is that 0.20.* will become the first
|
||||||
# stable version.
|
# stable version.
|
||||||
__version__ = '0.19.35.dev1'
|
__version__ = '0.19.36.dev1'
|
||||||
__author__ = 'Johannes Findeisen <you@hanez.org>'
|
__author__ = 'Johannes Findeisen <you@hanez.org>'
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -166,7 +166,7 @@ def main():
|
||||||
if args.daemon:
|
if args.daemon:
|
||||||
try:
|
try:
|
||||||
from linspector.core.linspectord import Linspectord
|
from linspector.core.linspectord import Linspectord
|
||||||
linspectord = Linspectord(configuration, environment, linspector)
|
linspectord = Linspectord(configuration, environment, linspector, log)
|
||||||
# do handling of restart, start and stop commands but for now "start" is enough... ;)
|
# do handling of restart, start and stop commands but for now "start" is enough... ;)
|
||||||
if args.kill:
|
if args.kill:
|
||||||
log('info', '[linspector] stopping daemon.')
|
log('info', '[linspector] stopping daemon.')
|
||||||
|
|
|
||||||
|
|
@ -9,20 +9,18 @@ import signal
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from linspector.core.helpers import log
|
|
||||||
|
|
||||||
|
|
||||||
# TODO: there is a bug when stopping the daemon. the pid_file is not being deleted. NEEDS A FIX!
|
# TODO: there is a bug when stopping the daemon. the pid_file is not being deleted. NEEDS A FIX!
|
||||||
class Linspectord:
|
class Linspectord:
|
||||||
|
def __init__(self, configuration, environment, linspector, log):
|
||||||
def __init__(self, configuration, environment, linspector):
|
|
||||||
self.__configuration = configuration
|
self.__configuration = configuration
|
||||||
self.__environment = environment
|
self.__environment = environment
|
||||||
self.__linspector = linspector
|
self.__linspector = linspector
|
||||||
|
self.__log = log
|
||||||
try:
|
try:
|
||||||
self.__pid_file = configuration.get_option('linspector', 'pid_file')
|
self.__pid_file = configuration.get_option('linspector', 'pid_file')
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
log('critical', __name__, str('daemonize error (no pid_file set): {0}'.format(err)))
|
log('critical', 'daemonize error (no pid_file set): {0}'.str(format(err)))
|
||||||
|
|
||||||
def daemonize(self):
|
def daemonize(self):
|
||||||
# daemonize the class using the UNIX double fork mechanism.
|
# daemonize the class using the UNIX double fork mechanism.
|
||||||
|
|
@ -34,7 +32,7 @@ class Linspectord:
|
||||||
# exit first parent.
|
# exit first parent.
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
except OSError as err:
|
except OSError as err:
|
||||||
log('critical', __name__, str('fork #1 failed: {0}'.format(err)))
|
self.__log('critical', 'fork #1 failed: {0}'.str(format(err)))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# decouple from parent environment.
|
# decouple from parent environment.
|
||||||
|
|
@ -49,7 +47,7 @@ class Linspectord:
|
||||||
# Exit from second parent.
|
# Exit from second parent.
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
except OSError as err:
|
except OSError as err:
|
||||||
log('critical', __name__, str('fork #2 failed: {0}'.format(err)))
|
self.__log('critical', 'fork #2 failed: {0}'.str(format(err)))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# redirect standard file descriptors.
|
# redirect standard file descriptors.
|
||||||
|
|
@ -75,7 +73,7 @@ class Linspectord:
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
# start the daemon. check for a pidfile to see if the daemon already runs before.
|
# start the daemon. check for a pidfile to see if the daemon already runs before.
|
||||||
log('info', __name__, 'starting daemon using pid_file: ' + self.__pid_file)
|
self.__log('info', 'starting daemon using pid_file: ' + str(self.__pid_file))
|
||||||
try:
|
try:
|
||||||
with open(self.__pid_file, 'r') as pf:
|
with open(self.__pid_file, 'r') as pf:
|
||||||
pid = int(pf.read().strip())
|
pid = int(pf.read().strip())
|
||||||
|
|
@ -84,7 +82,7 @@ class Linspectord:
|
||||||
|
|
||||||
if pid:
|
if pid:
|
||||||
message = 'pid_file {0} already exist. daemon already running?'
|
message = 'pid_file {0} already exist. daemon already running?'
|
||||||
log('critical', __name__, str(message.format(self.__pid_file)))
|
self.__log('critical', str(message.format(self.__pid_file)))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# start the daemon.
|
# start the daemon.
|
||||||
|
|
@ -93,7 +91,7 @@ class Linspectord:
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
# stop the daemon.
|
# stop the daemon.
|
||||||
log('info', __name__, 'stopping daemon using pid_file: ' + self.__pid_file)
|
self.__log('info', 'stopping daemon using pid_file: ' + str(self.__pid_file))
|
||||||
# get the pid from the pid file.
|
# get the pid from the pid file.
|
||||||
try:
|
try:
|
||||||
with open(self.__pid_file, 'r') as pf:
|
with open(self.__pid_file, 'r') as pf:
|
||||||
|
|
@ -103,7 +101,7 @@ class Linspectord:
|
||||||
|
|
||||||
if not pid:
|
if not pid:
|
||||||
message = 'pid_file {0} does not exist. daemon not running?'
|
message = 'pid_file {0} does not exist. daemon not running?'
|
||||||
log('error', __name__, str(message.format(self.__pid_file)))
|
self.__log('error', str(message.format(self.__pid_file)))
|
||||||
return # not an error in a restart
|
return # not an error in a restart
|
||||||
|
|
||||||
# try killing the daemon process.
|
# try killing the daemon process.
|
||||||
|
|
@ -117,12 +115,12 @@ class Linspectord:
|
||||||
if os.path.exists(self.__pid_file):
|
if os.path.exists(self.__pid_file):
|
||||||
os.remove(self.__pid_file)
|
os.remove(self.__pid_file)
|
||||||
else:
|
else:
|
||||||
log('critical', __name__, str(err.args))
|
self.__log('critical', str(err.args))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def restart(self):
|
def restart(self):
|
||||||
# restart the daemon.
|
# restart the daemon.
|
||||||
log('info', __name__, 'restarting daemon using pid_file: ' + self.__pid_file)
|
self.__log('info', 'restarting daemon using pid_file: ' + str(self.__pid_file))
|
||||||
self.stop()
|
self.stop()
|
||||||
self.start()
|
self.start()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue