1
mirror of https://github.com/home-assistant/core synced 2024-10-01 05:30:36 +02:00

Cleanup PID checking logic and write PID logic.

This commit is contained in:
Ryan Kraus 2015-09-01 03:29:07 -04:00
parent 4ca8f184e6
commit 7992882fa3

View File

@ -122,30 +122,25 @@ def check_pid(pid_file):
pid = int(open(pid_file, 'r').readline())
except IOError:
# PID File does not exist
pass
else:
try:
os.kill(pid, 0)
except OSError:
# PID does not exist
pass
else:
# PID already exists
print('Fatal Error: HomeAssistant is already running.')
sys.exit(1)
return
try:
os.kill(pid, 0)
except OSError:
# PID does not exist
return
print('Fatal Error: HomeAssistant is already running.')
sys.exit(1)
def write_pid(pid_file):
""" Create PID File """
# store pid
if pid_file:
# write pid file
pid = os.getpid()
try:
open(pid_file, 'w').write(str(pid))
except IOError:
print('Fatal Error: Unable to write pid file {}'.format(pid_file))
sys.exit(1)
pid = os.getpid()
try:
open(pid_file, 'w').write(str(pid))
except IOError:
print('Fatal Error: Unable to write pid file {}'.format(pid_file))
sys.exit(1)
def main():
@ -162,7 +157,8 @@ def main():
check_pid(args.pid_file)
if args.daemon:
daemonize()
write_pid(args.pid_file)
if args.pid_file:
write_pid(args.pid_file)
if args.demo_mode:
hass = bootstrap.from_config_dict({