1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/homeassistant_ynh.git synced 2024-09-03 19:26:16 +02:00
This commit is contained in:
ewilly 2021-11-23 22:27:54 +01:00
parent cf2d515740
commit 3dc7210af0
4 changed files with 17 additions and 11 deletions

View file

@ -6,9 +6,7 @@ After=network.target
Type=simple
User=__APP__
WorkingDirectory=__PATH__
ExecStart=/opt/yunohost/__APP__/bin/hass --config "__PATH__" --verbose
StandardOutput=append:/var/log/__APP__/__APP__.log
StandardError=inherit
ExecStart=/opt/yunohost/__APP__/bin/hass --config "__PATH__" --log-file "/var/log/__APP__/__APP__.log" --verbose
# Sandboxing options to harden security
# Depending on specificities of your service/app, you may need to tweak these

View file

@ -17,6 +17,7 @@ is_public=$YNH_APP_ARG_IS_PUBLIC
# definie useful vars
final_path="/opt/yunohost/$app"
data_path="/home/yunohost.app/$app"
log_file="$data_path/.$app/home-assistant.log"
path_url="/"
# check domain/path availability
@ -46,6 +47,11 @@ ynh_add_config --template="../conf/sudoers" --destination="/etc/sudoers.d/$app"
myynh_create_dir "$final_path"
chown $app: "$final_path"
# create a directory with its log file
myynh_create_dir "/var/log/$app"
touch "/var/log/$app/$app.log"
chown $app: "/var/log/$app/$app.log"
# create a directory for the datas of Home Assistant
myynh_create_dir "$data_path/.$app"
myynh_create_dir "$data_path/.cache"
@ -72,11 +78,11 @@ ynh_replace_string --match_string="__PATH__" --replace_string="$data_path/.$app"
ynh_add_systemd_config --service="$app"
## add service in admin panel
yunohost service add "$app" --log "$data_path/.$app/home-assistant.log" --description "Home Assistant server" --needs_exposed_ports $port
yunohost service add "$app" --log "$log_file" --description "Home Assistant server" --needs_exposed_ports $port
# start systemd service
ynh_script_progression --message="Starting the Home Assistant server..."
ynh_systemd_action --service_name="$app" --action=start --line_match="Home Assistant initialized" --log_path="systemd" --timeout=3600
ynh_systemd_action --service_name="$app" --action=start --line_match="Home Assistant initialized" --log_path="/var/log/$app" --timeout=3600
# remove --verbose from service
ynh_replace_string --match_string=" --verbose" --replace_string="" --target_file="/etc/systemd/system/$app.service"
@ -85,7 +91,7 @@ systemctl daemon-reload
ynh_systemd_action --service_name="$app" --action=restart
# enable logrotate
ynh_use_logrotate --logfile="$data_path/.$app/home-assistant.log"
ynh_use_logrotate --logfile="$log_file"
# create a dedicated nginx config
ynh_script_progression --message="Configuring nginx web server..."

View file

@ -23,6 +23,7 @@ python=$(ynh_app_setting_get --app="$app" --key=python)
# definie useful vars
final_path="/opt/yunohost/$app"
data_path="/home/yunohost.app/$app"
log_file="$data_path/.$app/home-assistant.log"
path_url="/"
# check domain/path availability
@ -58,12 +59,12 @@ ynh_script_progression --message="Restoring the dedicated service..."
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
# add service in admin panel
yunohost service add "$app" --log "$data_path/.$app/home-assistant.log" --description "Home Assistant server" --needs_exposed_ports $port
yunohost service add "$app" --log "$log_file" --description "Home Assistant server" --needs_exposed_ports $port
# restart the app
ynh_script_progression --message="Starting the Home Assistant server..."
sed --in-place "/ExecStart/s/$/ --verbose/" "/etc/systemd/system/$app.service"
ynh_systemd_action --service_name="$app" --action=start --line_match="Home Assistant initialized" --log_path="systemd" --timeout=900
ynh_systemd_action --service_name="$app" --action=start --line_match="Home Assistant initialized" --log_path="/var/log/$app" --timeout=900
# remove --verbose from service and restart
#ynh_replace_string --match_string=" --verbose" --replace_string="" --target_file="/etc/systemd/system/$app.service"

View file

@ -17,6 +17,7 @@ port=$(ynh_app_setting_get --app="$app" --key=port)
# definie useful vars
final_path="/opt/yunohost/$app"
data_path="/home/yunohost.app/$app"
log_file="$data_path/.$app/home-assistant.log"
# use prior backup and restore on error only if backup feature exists on installed instance
ynh_script_progression --message="Creating backup in case of failure..."
@ -45,7 +46,7 @@ myynh_install_dependencies --python="$PY_REQUIRED_VERSION"
# stop systemd service
ynh_script_progression --message="Stoping service..."
ynh_systemd_action --service_name="$app" --action=stop --line_match="Stopped Home Assistant" --log_path="systemd" --timeout=300
ynh_systemd_action --service_name="$app" --action=stop --line_match="Stopped Home Assistant" --log_path="/var/log" --timeout=300
# installation in a virtual environment
ynh_script_progression --message="Installing Home Assistant in a virtual environment..."
@ -63,7 +64,7 @@ ynh_replace_string --match_string="__PATH__" --replace_string="$data_path/.$app"
ynh_add_systemd_config --service="$app"
# add service in admin panel
yunohost service add "$app" --log "$data_path/.$app/home-assistant.log" --description "Home Assistant server" --needs_exposed_ports $port
yunohost service add "$app" --log "$log_file" --description "Home Assistant server" --needs_exposed_ports $port
# start systemd service
ynh_script_progression --message="Starting the Home Assistant server..."
@ -77,7 +78,7 @@ systemctl daemon-reload
ynh_systemd_action --service_name="$app" --action=restart
# enable logrotate
ynh_use_logrotate --logfile="$data_path/.$app/home-assistant.log" --nonappend
ynh_use_logrotate --logfile="$log_file" --nonappend
# create a dedicated nginx config
ynh_script_progression --message="Configuring nginx web server..."