1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/homeassistant_ynh.git synced 2024-09-03 19:26:16 +02:00

Update systemd service

This commit is contained in:
ewilly 2021-11-21 21:25:39 +01:00
parent 7190b587b0
commit 3f1bc519bd
6 changed files with 24 additions and 27 deletions

View file

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

View file

@ -27,7 +27,7 @@ ynh_backup --src_path="$final_path"
ynh_backup --src_path="$data_path"
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup --src_path="/etc/sudoers.d/$app"
ynh_backup --src_path="/etc/systemd/system/$app@$app.service"
ynh_backup --src_path="/etc/systemd/system/$app.service"
ynh_backup --src_path="/etc/logrotate.d/$app"
ynh_print_info --message="Backup of $app completed"

View file

@ -69,20 +69,20 @@ chmod -R +x "$data_path/.$app/bin/"
# setup up systemd service
ynh_script_progression --message="Adding the dedicated service..."
ynh_replace_string --match_string="__PATH__" --replace_string="$data_path/.$app" --target_file="../conf/systemd.service"
ynh_add_systemd_config --service="$app@$app"
ynh_add_systemd_config --service="$app"
## add service in admin panel
yunohost service add "$app@$app" --log "$data_path/.$app/home-assistant.log" --description "Home Assistant server" --needs_exposed_ports $port
yunohost service add "$app" --log "$data_path/.$app/home-assistant.log" --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@$app" --action=start --line_match="Home Assistant initialized" --log_path="/var/log/$app.log" --timeout=3600
ynh_systemd_action --service_name="$app" --action=start --line_match="Home Assistant initialized" --log_path="systemd" --timeout=3600
# remove --verbose from service
ynh_replace_string --match_string=" --verbose" --replace_string="" --target_file="/etc/systemd/system/$app@$app.service"
ynh_store_file_checksum --file="/etc/systemd/system/$app@$app.service"
ynh_replace_string --match_string=" --verbose" --replace_string="" --target_file="/etc/systemd/system/$app.service"
ynh_store_file_checksum --file="/etc/systemd/system/$app.service"
systemctl daemon-reload
ynh_systemd_action --service_name="$app@$app" --action=restart
ynh_systemd_action --service_name="$app" --action=restart
# enable logrotate
ynh_use_logrotate --logfile="$data_path/.$app/home-assistant.log"

View file

@ -15,14 +15,14 @@ final_path="/opt/yunohost/$app"
data_path="/home/yunohost.app/$app"
# Remove a service from the admin panel, added by `yunohost service add`
if ynh_exec_warn_less yunohost service status "$app@$app" >/dev/null ; then
if ynh_exec_warn_less yunohost service status "$app" >/dev/null ; then
ynh_script_progression --message="Removing $app service integration..."
yunohost service remove "$app@$app"
yunohost service remove "$app"
fi
# remove systemd service
ynh_script_progression --message="Stopping and removing the systemd service..."
ynh_remove_systemd_config --service="$app@$app"
ynh_remove_systemd_config --service="$app"
# remove the app-specific logrotate config
ynh_script_progression --message="Removing logrotate configuration..."

View file

@ -55,21 +55,21 @@ myynh_install_dependencies --python="$python"
# restore the systemd service
ynh_script_progression --message="Restoring the dedicated service..."
ynh_restore_file --origin_path="/etc/systemd/system/$app@$app.service"
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
# add service in admin panel
yunohost service add "$app@$app" --log "$data_path/.$app/home-assistant.log" --description "Home Assistant server" --needs_exposed_ports $port
yunohost service add "$app" --log "$data_path/.$app/home-assistant.log" --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@$app.service"
ynh_systemd_action --service_name="$app@$app" --action=start --line_match="Home Assistant initialized" --log_path="/var/log/$app.log" --timeout=900
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
# remove --verbose from service and restart
ynh_replace_string --match_string=" --verbose" --replace_string="" --target_file="/etc/systemd/system/$app@$app.service"
ynh_store_file_checksum --file="/etc/systemd/system/$app@$app.service"
ynh_replace_string --match_string=" --verbose" --replace_string="" --target_file="/etc/systemd/system/$app.service"
ynh_store_file_checksum --file="/etc/systemd/system/$app.service"
systemctl daemon-reload
ynh_systemd_action --service_name="$app@$app" --action=restart
ynh_systemd_action --service_name="$app" --action=restart
# restore logrotate
ynh_script_progression --message="Restoring logrotate..."
@ -79,6 +79,5 @@ ynh_restore_file --origin_path="/etc/logrotate.d/$app"
ynh_script_progression --message="Restoring nginx web server..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_systemd_action --service_name=nginx --action=reload
ynh_exec_fully_quiet sleep 60s #Only necessary for CI test otherwise curl failed to nginx page
ynh_script_progression --message="Recovery of $app completed" --last

View file

@ -45,7 +45,7 @@ myynh_install_dependencies --python="$PY_REQUIRED_VERSION"
# stop systemd service
ynh_script_progression --message="Stoping service..."
ynh_systemd_action --service_name="$app@$app" --action=stop --line_match="Stopped Home Assistant" --log_path="/var/log/$app.log" --timeout=300
ynh_systemd_action --service_name="$app" --action=stop --line_match="Stopped Home Assistant" --log_path="systemd" --timeout=300
# installation in a virtual environment
ynh_script_progression --message="Installing Home Assistant in a virtual environment..."
@ -60,21 +60,21 @@ chmod -R +x "$data_path/.$app/bin/"
# setup up systemd service
ynh_script_progression --message="Adding the dedicated service..."
ynh_replace_string --match_string="__PATH__" --replace_string="$data_path/.$app" --target_file="../conf/systemd.service"
ynh_add_systemd_config --service="$app@$app"
ynh_add_systemd_config --service="$app"
# add service in admin panel
yunohost service add "$app@$app" --log "$data_path/.$app/home-assistant.log" --description "Home Assistant server" --needs_exposed_ports $port
yunohost service add "$app" --log "$data_path/.$app/home-assistant.log" --description "Home Assistant server" --needs_exposed_ports $port
# start systemd service
ynh_script_progression --message="Starting the Home Assistant server..."
systemctl daemon-reload
ynh_systemd_action --service_name="$app@$app" --action=start --line_match="Home Assistant initialized" --log_path="/var/log/$app.log" --timeout=3600
ynh_systemd_action --service_name="$app" --action=start --line_match="Home Assistant initialized" --log_path="systemd" --timeout=3600
# remove --verbose from service
ynh_replace_string --match_string=" --verbose" --replace_string="" --target_file="/etc/systemd/system/$app@$app.service"
ynh_store_file_checksum --file="/etc/systemd/system/$app@$app.service"
ynh_replace_string --match_string=" --verbose" --replace_string="" --target_file="/etc/systemd/system/$app.service"
ynh_store_file_checksum --file="/etc/systemd/system/$app.service"
systemctl daemon-reload
ynh_systemd_action --service_name="$app@$app" --action=restart
ynh_systemd_action --service_name="$app" --action=restart
# enable logrotate
ynh_use_logrotate --logfile="$data_path/.$app/home-assistant.log" --nonappend