mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Cleanup PID checking logic and write PID logic.
This commit is contained in:
parent
4ca8f184e6
commit
7992882fa3
@ -122,30 +122,25 @@ def check_pid(pid_file):
|
|||||||
pid = int(open(pid_file, 'r').readline())
|
pid = int(open(pid_file, 'r').readline())
|
||||||
except IOError:
|
except IOError:
|
||||||
# PID File does not exist
|
# PID File does not exist
|
||||||
pass
|
return
|
||||||
else:
|
|
||||||
try:
|
try:
|
||||||
os.kill(pid, 0)
|
os.kill(pid, 0)
|
||||||
except OSError:
|
except OSError:
|
||||||
# PID does not exist
|
# PID does not exist
|
||||||
pass
|
return
|
||||||
else:
|
print('Fatal Error: HomeAssistant is already running.')
|
||||||
# PID already exists
|
sys.exit(1)
|
||||||
print('Fatal Error: HomeAssistant is already running.')
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
def write_pid(pid_file):
|
def write_pid(pid_file):
|
||||||
""" Create PID File """
|
""" Create PID File """
|
||||||
# store pid
|
pid = os.getpid()
|
||||||
if pid_file:
|
try:
|
||||||
# write pid file
|
open(pid_file, 'w').write(str(pid))
|
||||||
pid = os.getpid()
|
except IOError:
|
||||||
try:
|
print('Fatal Error: Unable to write pid file {}'.format(pid_file))
|
||||||
open(pid_file, 'w').write(str(pid))
|
sys.exit(1)
|
||||||
except IOError:
|
|
||||||
print('Fatal Error: Unable to write pid file {}'.format(pid_file))
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@ -162,7 +157,8 @@ def main():
|
|||||||
check_pid(args.pid_file)
|
check_pid(args.pid_file)
|
||||||
if args.daemon:
|
if args.daemon:
|
||||||
daemonize()
|
daemonize()
|
||||||
write_pid(args.pid_file)
|
if args.pid_file:
|
||||||
|
write_pid(args.pid_file)
|
||||||
|
|
||||||
if args.demo_mode:
|
if args.demo_mode:
|
||||||
hass = bootstrap.from_config_dict({
|
hass = bootstrap.from_config_dict({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user