2017-04-30 05:04:49 +00:00
|
|
|
"""Start Home Assistant."""
|
2015-01-21 06:14:10 +00:00
|
|
|
from __future__ import print_function
|
2014-11-03 01:27:32 +00:00
|
|
|
|
2016-02-19 05:27:50 +00:00
|
|
|
import argparse
|
|
|
|
import os
|
2016-05-20 06:20:59 +00:00
|
|
|
import platform
|
|
|
|
import subprocess
|
2014-11-03 01:27:32 +00:00
|
|
|
import sys
|
2016-01-27 03:39:59 +00:00
|
|
|
import threading
|
2018-07-18 08:46:14 +00:00
|
|
|
from typing import List, Dict, Any # noqa pylint: disable=unused-import
|
2018-05-12 21:44:53 +00:00
|
|
|
|
2016-07-21 05:38:52 +00:00
|
|
|
|
2017-06-02 06:23:39 +00:00
|
|
|
from homeassistant import monkey_patch
|
2016-02-19 05:27:50 +00:00
|
|
|
from homeassistant.const import (
|
2016-02-28 04:41:03 +00:00
|
|
|
__version__,
|
|
|
|
EVENT_HOMEASSISTANT_START,
|
|
|
|
REQUIRED_PYTHON_VER,
|
|
|
|
RESTART_EXIT_CODE,
|
|
|
|
)
|
2015-08-30 00:06:54 +00:00
|
|
|
|
2015-05-01 05:44:24 +00:00
|
|
|
|
2018-07-23 08:24:39 +00:00
|
|
|
def attempt_use_uvloop() -> None:
|
2017-04-06 06:23:02 +00:00
|
|
|
"""Attempt to use uvloop."""
|
|
|
|
import asyncio
|
|
|
|
|
|
|
|
try:
|
|
|
|
import uvloop
|
|
|
|
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
|
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2016-07-21 05:38:52 +00:00
|
|
|
def validate_python() -> None:
|
2017-06-08 13:53:12 +00:00
|
|
|
"""Validate that the right Python version is running."""
|
2018-02-23 07:22:27 +00:00
|
|
|
if sys.version_info[:3] < REQUIRED_PYTHON_VER:
|
2016-09-13 02:16:14 +00:00
|
|
|
print("Home Assistant requires at least Python {}.{}.{}".format(
|
|
|
|
*REQUIRED_PYTHON_VER))
|
2015-08-31 15:53:59 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
2016-07-21 05:38:52 +00:00
|
|
|
def ensure_config_path(config_dir: str) -> None:
|
2016-03-07 23:06:04 +00:00
|
|
|
"""Validate the configuration directory."""
|
2016-03-27 15:44:15 +00:00
|
|
|
import homeassistant.config as config_util
|
2016-04-12 03:07:50 +00:00
|
|
|
lib_dir = os.path.join(config_dir, 'deps')
|
2015-08-30 00:06:54 +00:00
|
|
|
|
2015-01-09 02:45:27 +00:00
|
|
|
# Test if configuration directory exists
|
2014-11-23 20:57:29 +00:00
|
|
|
if not os.path.isdir(config_dir):
|
2015-08-30 03:31:33 +00:00
|
|
|
if config_dir != config_util.get_default_config_dir():
|
2015-08-30 02:19:52 +00:00
|
|
|
print(('Fatal Error: Specified configuration directory does '
|
|
|
|
'not exist {} ').format(config_dir))
|
2015-08-30 03:31:33 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
try:
|
|
|
|
os.mkdir(config_dir)
|
|
|
|
except OSError:
|
|
|
|
print(('Fatal Error: Unable to create default configuration '
|
|
|
|
'directory {} ').format(config_dir))
|
|
|
|
sys.exit(1)
|
2015-08-30 00:06:54 +00:00
|
|
|
|
|
|
|
# Test if library directory exists
|
|
|
|
if not os.path.isdir(lib_dir):
|
|
|
|
try:
|
|
|
|
os.mkdir(lib_dir)
|
|
|
|
except OSError:
|
|
|
|
print(('Fatal Error: Unable to create library '
|
|
|
|
'directory {} ').format(lib_dir))
|
2015-08-30 03:31:33 +00:00
|
|
|
sys.exit(1)
|
2015-04-26 17:05:01 +00:00
|
|
|
|
2015-08-30 06:02:07 +00:00
|
|
|
|
2016-07-21 05:38:52 +00:00
|
|
|
def ensure_config_file(config_dir: str) -> str:
|
2016-03-07 23:06:04 +00:00
|
|
|
"""Ensure configuration file exists."""
|
2016-03-27 15:44:15 +00:00
|
|
|
import homeassistant.config as config_util
|
2015-04-26 17:05:01 +00:00
|
|
|
config_path = config_util.ensure_config_exists(config_dir)
|
|
|
|
|
|
|
|
if config_path is None:
|
|
|
|
print('Error getting configuration path')
|
2015-08-30 03:31:33 +00:00
|
|
|
sys.exit(1)
|
2014-11-08 19:01:47 +00:00
|
|
|
|
2015-01-09 02:45:27 +00:00
|
|
|
return config_path
|
|
|
|
|
|
|
|
|
2016-07-21 05:38:52 +00:00
|
|
|
def get_arguments() -> argparse.Namespace:
|
2016-03-07 23:06:04 +00:00
|
|
|
"""Get parsed passed in arguments."""
|
2016-03-27 15:44:15 +00:00
|
|
|
import homeassistant.config as config_util
|
2015-08-30 06:02:07 +00:00
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description="Home Assistant: Observe, Control, Automate.")
|
2015-08-30 07:59:27 +00:00
|
|
|
parser.add_argument('--version', action='version', version=__version__)
|
2015-01-09 02:45:27 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'-c', '--config',
|
|
|
|
metavar='path_to_config_dir',
|
2015-08-30 01:11:24 +00:00
|
|
|
default=config_util.get_default_config_dir(),
|
2015-01-09 02:45:27 +00:00
|
|
|
help="Directory that contains the Home Assistant configuration")
|
2015-01-18 06:23:07 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'--demo-mode',
|
|
|
|
action='store_true',
|
|
|
|
help='Start Home Assistant in demo mode')
|
2016-02-06 14:48:36 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'--debug',
|
|
|
|
action='store_true',
|
2016-05-20 06:20:59 +00:00
|
|
|
help='Start Home Assistant in debug mode')
|
2015-01-18 05:13:02 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'--open-ui',
|
|
|
|
action='store_true',
|
|
|
|
help='Open the webinterface in a browser')
|
2015-09-04 21:50:57 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'--skip-pip',
|
|
|
|
action='store_true',
|
|
|
|
help='Skips pip install of required packages on startup')
|
2015-09-01 06:12:00 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'-v', '--verbose',
|
|
|
|
action='store_true',
|
|
|
|
help="Enable verbose logging to file.")
|
|
|
|
parser.add_argument(
|
|
|
|
'--pid-file',
|
|
|
|
metavar='path_to_pid_file',
|
|
|
|
default=None,
|
|
|
|
help='Path to PID file useful for running as daemon')
|
2015-09-04 22:22:42 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'--log-rotate-days',
|
|
|
|
type=int,
|
|
|
|
default=None,
|
|
|
|
help='Enables daily log rotation and keeps up to the specified days')
|
2017-09-14 04:22:42 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'--log-file',
|
|
|
|
type=str,
|
|
|
|
default=None,
|
|
|
|
help='Log file to write to. If not set, CONFIG/home-assistant.log '
|
|
|
|
'is used')
|
2018-04-18 14:18:44 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'--log-no-color',
|
|
|
|
action='store_true',
|
|
|
|
help="Disable color logs")
|
2016-05-20 06:20:59 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'--runner',
|
|
|
|
action='store_true',
|
|
|
|
help='On restart exit with code {}'.format(RESTART_EXIT_CODE))
|
2016-07-03 18:38:14 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'--script',
|
|
|
|
nargs=argparse.REMAINDER,
|
|
|
|
help='Run one of the embedded scripts')
|
2016-05-20 06:20:59 +00:00
|
|
|
if os.name == "posix":
|
2015-09-01 06:12:00 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'--daemon',
|
|
|
|
action='store_true',
|
|
|
|
help='Run Home Assistant as daemon')
|
|
|
|
|
|
|
|
arguments = parser.parse_args()
|
2016-05-20 06:20:59 +00:00
|
|
|
if os.name != "posix" or arguments.debug or arguments.runner:
|
2016-07-21 05:38:52 +00:00
|
|
|
setattr(arguments, 'daemon', False)
|
2016-05-20 06:20:59 +00:00
|
|
|
|
2015-09-01 06:12:00 +00:00
|
|
|
return arguments
|
|
|
|
|
|
|
|
|
2016-07-21 05:38:52 +00:00
|
|
|
def daemonize() -> None:
|
2016-03-07 23:06:04 +00:00
|
|
|
"""Move current process to daemon process."""
|
|
|
|
# Create first fork
|
2015-09-01 06:12:00 +00:00
|
|
|
pid = os.fork()
|
|
|
|
if pid > 0:
|
|
|
|
sys.exit(0)
|
|
|
|
|
2016-03-07 23:06:04 +00:00
|
|
|
# Decouple fork
|
2015-09-01 06:12:00 +00:00
|
|
|
os.setsid()
|
|
|
|
|
2016-03-07 23:06:04 +00:00
|
|
|
# Create second fork
|
2015-09-01 06:12:00 +00:00
|
|
|
pid = os.fork()
|
|
|
|
if pid > 0:
|
|
|
|
sys.exit(0)
|
|
|
|
|
2016-05-20 06:20:07 +00:00
|
|
|
# redirect standard file descriptors to devnull
|
2016-05-20 14:03:08 +00:00
|
|
|
infd = open(os.devnull, 'r')
|
|
|
|
outfd = open(os.devnull, 'a+')
|
2016-05-20 06:20:07 +00:00
|
|
|
sys.stdout.flush()
|
|
|
|
sys.stderr.flush()
|
2016-05-20 14:03:08 +00:00
|
|
|
os.dup2(infd.fileno(), sys.stdin.fileno())
|
|
|
|
os.dup2(outfd.fileno(), sys.stdout.fileno())
|
|
|
|
os.dup2(outfd.fileno(), sys.stderr.fileno())
|
2016-05-20 06:20:07 +00:00
|
|
|
|
2015-09-01 06:12:00 +00:00
|
|
|
|
2016-07-21 05:38:52 +00:00
|
|
|
def check_pid(pid_file: str) -> None:
|
2017-06-08 13:53:12 +00:00
|
|
|
"""Check that Home Assistant is not already running."""
|
2016-03-07 23:06:04 +00:00
|
|
|
# Check pid file
|
2015-09-01 06:37:52 +00:00
|
|
|
try:
|
2018-01-31 10:30:48 +00:00
|
|
|
with open(pid_file, 'r') as file:
|
|
|
|
pid = int(file.readline())
|
2015-09-01 06:37:52 +00:00
|
|
|
except IOError:
|
2015-09-01 07:22:43 +00:00
|
|
|
# PID File does not exist
|
2015-09-01 07:29:07 +00:00
|
|
|
return
|
|
|
|
|
2016-05-20 18:45:16 +00:00
|
|
|
# If we just restarted, we just found our own pidfile.
|
|
|
|
if pid == os.getpid():
|
|
|
|
return
|
|
|
|
|
2015-09-01 07:29:07 +00:00
|
|
|
try:
|
|
|
|
os.kill(pid, 0)
|
|
|
|
except OSError:
|
|
|
|
# PID does not exist
|
|
|
|
return
|
|
|
|
print('Fatal Error: HomeAssistant is already running.')
|
|
|
|
sys.exit(1)
|
2015-09-01 06:12:00 +00:00
|
|
|
|
|
|
|
|
2016-07-21 05:38:52 +00:00
|
|
|
def write_pid(pid_file: str) -> None:
|
2016-03-07 23:06:04 +00:00
|
|
|
"""Create a PID File."""
|
2015-09-01 07:29:07 +00:00
|
|
|
pid = os.getpid()
|
|
|
|
try:
|
2018-01-31 10:30:48 +00:00
|
|
|
with open(pid_file, 'w') as file:
|
|
|
|
file.write(str(pid))
|
2015-09-01 07:29:07 +00:00
|
|
|
except IOError:
|
|
|
|
print('Fatal Error: Unable to write pid file {}'.format(pid_file))
|
|
|
|
sys.exit(1)
|
2015-01-09 02:45:27 +00:00
|
|
|
|
2015-09-15 06:17:01 +00:00
|
|
|
|
2016-07-21 05:38:52 +00:00
|
|
|
def closefds_osx(min_fd: int, max_fd: int) -> None:
|
2016-05-20 06:20:59 +00:00
|
|
|
"""Make sure file descriptors get closed when we restart.
|
2016-03-07 23:06:04 +00:00
|
|
|
|
2016-05-20 06:20:59 +00:00
|
|
|
We cannot call close on guarded fds, and we cannot easily test which fds
|
|
|
|
are guarded. But we can set the close-on-exec flag on everything we want to
|
|
|
|
get rid of.
|
2016-02-06 14:48:36 +00:00
|
|
|
"""
|
2016-05-20 06:20:59 +00:00
|
|
|
from fcntl import fcntl, F_GETFD, F_SETFD, FD_CLOEXEC
|
|
|
|
|
|
|
|
for _fd in range(min_fd, max_fd):
|
|
|
|
try:
|
|
|
|
val = fcntl(_fd, F_GETFD)
|
|
|
|
if not val & FD_CLOEXEC:
|
|
|
|
fcntl(_fd, F_SETFD, val | FD_CLOEXEC)
|
|
|
|
except IOError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2016-07-21 05:38:52 +00:00
|
|
|
def cmdline() -> List[str]:
|
2016-05-20 06:20:59 +00:00
|
|
|
"""Collect path and arguments to re-execute the current hass instance."""
|
2017-12-10 00:58:52 +00:00
|
|
|
if os.path.basename(sys.argv[0]) == '__main__.py':
|
2016-05-20 18:45:16 +00:00
|
|
|
modulepath = os.path.dirname(sys.argv[0])
|
|
|
|
os.environ['PYTHONPATH'] = os.path.dirname(modulepath)
|
2017-03-18 00:07:36 +00:00
|
|
|
return [sys.executable] + [arg for arg in sys.argv if
|
|
|
|
arg != '--daemon']
|
2017-07-06 03:02:16 +00:00
|
|
|
|
|
|
|
return [arg for arg in sys.argv if arg != '--daemon']
|
2016-05-20 06:20:59 +00:00
|
|
|
|
|
|
|
|
2016-07-21 05:38:52 +00:00
|
|
|
def setup_and_run_hass(config_dir: str,
|
2018-07-13 10:24:51 +00:00
|
|
|
args: argparse.Namespace) -> int:
|
2017-04-30 05:04:49 +00:00
|
|
|
"""Set up HASS and run."""
|
2016-03-27 15:44:15 +00:00
|
|
|
from homeassistant import bootstrap
|
|
|
|
|
2016-05-20 06:20:59 +00:00
|
|
|
# Run a simple daemon runner process on Windows to handle restarts
|
|
|
|
if os.name == 'nt' and '--runner' not in sys.argv:
|
2016-07-21 05:38:52 +00:00
|
|
|
nt_args = cmdline() + ['--runner']
|
2016-05-20 06:20:59 +00:00
|
|
|
while True:
|
|
|
|
try:
|
2016-07-21 05:38:52 +00:00
|
|
|
subprocess.check_call(nt_args)
|
2016-05-20 06:20:59 +00:00
|
|
|
sys.exit(0)
|
|
|
|
except subprocess.CalledProcessError as exc:
|
|
|
|
if exc.returncode != RESTART_EXIT_CODE:
|
|
|
|
sys.exit(exc.returncode)
|
|
|
|
|
2016-01-27 03:39:59 +00:00
|
|
|
if args.demo_mode:
|
|
|
|
config = {
|
|
|
|
'frontend': {},
|
|
|
|
'demo': {}
|
2018-05-12 21:44:53 +00:00
|
|
|
} # type: Dict[str, Any]
|
2016-01-27 03:39:59 +00:00
|
|
|
hass = bootstrap.from_config_dict(
|
2016-05-20 06:20:07 +00:00
|
|
|
config, config_dir=config_dir, verbose=args.verbose,
|
2017-09-14 04:22:42 +00:00
|
|
|
skip_pip=args.skip_pip, log_rotate_days=args.log_rotate_days,
|
2018-04-18 14:18:44 +00:00
|
|
|
log_file=args.log_file, log_no_color=args.log_no_color)
|
2016-01-27 03:39:59 +00:00
|
|
|
else:
|
|
|
|
config_file = ensure_config_file(config_dir)
|
|
|
|
print('Config directory:', config_dir)
|
|
|
|
hass = bootstrap.from_config_file(
|
2016-05-20 06:20:07 +00:00
|
|
|
config_file, verbose=args.verbose, skip_pip=args.skip_pip,
|
2018-04-18 14:18:44 +00:00
|
|
|
log_rotate_days=args.log_rotate_days, log_file=args.log_file,
|
|
|
|
log_no_color=args.log_no_color)
|
2016-01-27 03:39:59 +00:00
|
|
|
|
2016-03-28 01:48:51 +00:00
|
|
|
if hass is None:
|
2018-07-13 10:24:51 +00:00
|
|
|
return -1
|
2016-03-28 01:48:51 +00:00
|
|
|
|
2016-01-27 03:39:59 +00:00
|
|
|
if args.open_ui:
|
2017-06-02 06:23:39 +00:00
|
|
|
# Imported here to avoid importing asyncio before monkey patch
|
2018-03-11 17:01:12 +00:00
|
|
|
from homeassistant.util.async_ import run_callback_threadsafe
|
2017-06-02 06:23:39 +00:00
|
|
|
|
2018-07-23 08:24:39 +00:00
|
|
|
def open_browser(_: Any) -> None:
|
|
|
|
"""Open the web interface in a browser."""
|
2018-07-17 22:28:44 +00:00
|
|
|
if hass.config.api is not None: # type: ignore
|
2016-01-27 03:39:59 +00:00
|
|
|
import webbrowser
|
2018-07-17 22:28:44 +00:00
|
|
|
webbrowser.open(hass.config.api.base_url) # type: ignore
|
2016-01-27 03:39:59 +00:00
|
|
|
|
2016-09-13 02:16:14 +00:00
|
|
|
run_callback_threadsafe(
|
|
|
|
hass.loop,
|
|
|
|
hass.bus.async_listen_once,
|
|
|
|
EVENT_HOMEASSISTANT_START, open_browser
|
|
|
|
)
|
2016-01-27 03:39:59 +00:00
|
|
|
|
2017-04-06 06:23:02 +00:00
|
|
|
return hass.start()
|
2016-01-27 03:39:59 +00:00
|
|
|
|
|
|
|
|
2016-07-21 05:38:52 +00:00
|
|
|
def try_to_restart() -> None:
|
2017-06-08 13:53:12 +00:00
|
|
|
"""Attempt to clean up state and start a new Home Assistant instance."""
|
2016-05-20 06:20:59 +00:00
|
|
|
# Things should be mostly shut down already at this point, now just try
|
|
|
|
# to clean up things that may have been left behind.
|
|
|
|
sys.stderr.write('Home Assistant attempting to restart.\n')
|
|
|
|
|
|
|
|
# Count remaining threads, ideally there should only be one non-daemonized
|
|
|
|
# thread left (which is us). Nothing we really do with it, but it might be
|
|
|
|
# useful when debugging shutdown/restart issues.
|
2016-05-22 04:35:33 +00:00
|
|
|
try:
|
2016-08-07 23:26:35 +00:00
|
|
|
nthreads = sum(thread.is_alive() and not thread.daemon
|
2016-05-22 04:35:33 +00:00
|
|
|
for thread in threading.enumerate())
|
|
|
|
if nthreads > 1:
|
|
|
|
sys.stderr.write(
|
|
|
|
"Found {} non-daemonic threads.\n".format(nthreads))
|
|
|
|
|
|
|
|
# Somehow we sometimes seem to trigger an assertion in the python threading
|
|
|
|
# module. It seems we find threads that have no associated OS level thread
|
|
|
|
# which are not marked as stopped at the python level.
|
|
|
|
except AssertionError:
|
|
|
|
sys.stderr.write("Failed to count non-daemonic threads.\n")
|
2016-05-20 06:20:59 +00:00
|
|
|
|
|
|
|
# Try to not leave behind open filedescriptors with the emphasis on try.
|
2016-01-27 03:39:59 +00:00
|
|
|
try:
|
2016-05-20 06:20:59 +00:00
|
|
|
max_fd = os.sysconf("SC_OPEN_MAX")
|
2016-01-27 03:39:59 +00:00
|
|
|
except ValueError:
|
2016-05-20 06:20:59 +00:00
|
|
|
max_fd = 256
|
2016-01-27 03:39:59 +00:00
|
|
|
|
2016-05-20 06:20:59 +00:00
|
|
|
if platform.system() == 'Darwin':
|
|
|
|
closefds_osx(3, max_fd)
|
|
|
|
else:
|
|
|
|
os.closerange(3, max_fd)
|
2016-02-06 14:48:36 +00:00
|
|
|
|
2017-06-08 13:53:12 +00:00
|
|
|
# Now launch into a new instance of Home Assistant. If this fails we
|
2016-05-20 06:20:59 +00:00
|
|
|
# fall through and exit with error 100 (RESTART_EXIT_CODE) in which case
|
|
|
|
# systemd will restart us when RestartForceExitStatus=100 is set in the
|
|
|
|
# systemd.service file.
|
2017-06-08 13:53:12 +00:00
|
|
|
sys.stderr.write("Restarting Home Assistant\n")
|
2016-05-20 06:20:59 +00:00
|
|
|
args = cmdline()
|
|
|
|
os.execv(args[0], args)
|
2016-01-27 03:39:59 +00:00
|
|
|
|
|
|
|
|
2016-07-21 05:38:52 +00:00
|
|
|
def main() -> int:
|
2016-03-07 23:06:04 +00:00
|
|
|
"""Start Home Assistant."""
|
2017-04-06 06:23:02 +00:00
|
|
|
validate_python()
|
|
|
|
|
2018-03-12 23:12:21 +00:00
|
|
|
monkey_patch_needed = sys.version_info[:3] < (3, 6, 3)
|
|
|
|
if monkey_patch_needed and os.environ.get('HASS_NO_MONKEY') != '1':
|
2017-06-17 00:17:18 +00:00
|
|
|
if sys.version_info[:2] >= (3, 6):
|
2017-06-02 06:23:39 +00:00
|
|
|
monkey_patch.disable_c_asyncio()
|
|
|
|
monkey_patch.patch_weakref_tasks()
|
|
|
|
|
2017-04-06 06:23:02 +00:00
|
|
|
attempt_use_uvloop()
|
|
|
|
|
2015-01-21 06:14:10 +00:00
|
|
|
args = get_arguments()
|
|
|
|
|
2016-07-03 18:38:14 +00:00
|
|
|
if args.script is not None:
|
|
|
|
from homeassistant import scripts
|
|
|
|
return scripts.run(args.script)
|
|
|
|
|
2015-01-21 06:14:10 +00:00
|
|
|
config_dir = os.path.join(os.getcwd(), args.config)
|
2015-08-30 06:02:07 +00:00
|
|
|
ensure_config_path(config_dir)
|
2015-01-09 02:45:27 +00:00
|
|
|
|
2016-03-07 23:06:04 +00:00
|
|
|
# Daemon functions
|
2015-09-01 06:37:52 +00:00
|
|
|
if args.pid_file:
|
|
|
|
check_pid(args.pid_file)
|
2015-09-01 06:12:00 +00:00
|
|
|
if args.daemon:
|
|
|
|
daemonize()
|
2015-09-01 07:29:07 +00:00
|
|
|
if args.pid_file:
|
|
|
|
write_pid(args.pid_file)
|
2015-09-01 06:12:00 +00:00
|
|
|
|
2016-05-20 06:20:59 +00:00
|
|
|
exit_code = setup_and_run_hass(config_dir, args)
|
|
|
|
if exit_code == RESTART_EXIT_CODE and not args.runner:
|
|
|
|
try_to_restart()
|
|
|
|
|
2016-02-06 14:48:36 +00:00
|
|
|
return exit_code
|
2015-08-30 03:31:33 +00:00
|
|
|
|
2014-11-03 01:27:32 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2016-02-06 14:48:36 +00:00
|
|
|
sys.exit(main())
|