mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Daemon handling cleanup.
More cleanly handling whether a PID file should be checked. Fatal Error on PID file IOError. Pylint fix to bootstrap.
This commit is contained in:
parent
1add38a195
commit
5b06e8d25e
@ -118,7 +118,6 @@ def daemonize():
|
|||||||
def check_pid(pid_file):
|
def check_pid(pid_file):
|
||||||
""" Check that HA is not already running """
|
""" Check that HA is not already running """
|
||||||
# check pid file
|
# check pid file
|
||||||
if pid_file:
|
|
||||||
try:
|
try:
|
||||||
pid = int(open(pid_file, 'r').readline())
|
pid = int(open(pid_file, 'r').readline())
|
||||||
except IOError:
|
except IOError:
|
||||||
@ -142,7 +141,8 @@ def write_pid(pid_file):
|
|||||||
try:
|
try:
|
||||||
open(pid_file, 'w').write(str(pid))
|
open(pid_file, 'w').write(str(pid))
|
||||||
except IOError:
|
except IOError:
|
||||||
pass
|
print('Fatal Error: Unable to write pid file {}'.format(pid_file))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@ -155,6 +155,7 @@ def main():
|
|||||||
ensure_config_path(config_dir)
|
ensure_config_path(config_dir)
|
||||||
|
|
||||||
# daemon functions
|
# daemon functions
|
||||||
|
if args.pid_file:
|
||||||
check_pid(args.pid_file)
|
check_pid(args.pid_file)
|
||||||
if args.daemon:
|
if args.daemon:
|
||||||
daemonize()
|
daemonize()
|
||||||
|
@ -149,7 +149,7 @@ def mount_local_lib_path(config_dir):
|
|||||||
sys.path.insert(0, os.path.join(config_dir, 'lib'))
|
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,
|
def from_config_dict(config, hass=None, config_dir=None, enable_log=True,
|
||||||
verbose=False, daemon=False):
|
verbose=False, daemon=False):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user