Daemon handling cleanup.

More cleanly handling whether a PID file should be checked.
Fatal Error on PID file IOError.
Pylint fix to bootstrap.
pull/303/head
Ryan Kraus 2015-09-01 02:37:52 -04:00
parent 1add38a195
commit 5b06e8d25e
2 changed files with 14 additions and 13 deletions

View File

@ -118,7 +118,6 @@ def daemonize():
def check_pid(pid_file):
""" Check that HA is not already running """
# check pid file
if pid_file:
try:
pid = int(open(pid_file, 'r').readline())
except IOError:
@ -142,7 +141,8 @@ def write_pid(pid_file):
try:
open(pid_file, 'w').write(str(pid))
except IOError:
pass
print('Fatal Error: Unable to write pid file {}'.format(pid_file))
sys.exit(1)
def main():
@ -155,6 +155,7 @@ def main():
ensure_config_path(config_dir)
# daemon functions
if args.pid_file:
check_pid(args.pid_file)
if args.daemon:
daemonize()

View File

@ -149,7 +149,7 @@ def mount_local_lib_path(config_dir):
sys.path.insert(0, os.path.join(config_dir, 'lib'))
# pylint: disable=too-many-branches, too-many-statements
# pylint: disable=too-many-branches, too-many-statements, too-many-arguments
def from_config_dict(config, hass=None, config_dir=None, enable_log=True,
verbose=False, daemon=False):
"""