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

Apply template, move logs dir, fix install_dir

This commit is contained in:
Salamandar 2024-02-05 17:47:43 +01:00
parent 197c6682bc
commit 93cce95b00
6 changed files with 90 additions and 99 deletions

View file

@ -8,7 +8,7 @@ Group=__APP__
UMask=0002
Type=simple
ExecStart=/usr/bin/mono --debug /usr/lib/sonarr/bin/Sonarr.exe -nobrowser -data=/var/lib/__APP__
ExecStart=/usr/bin/mono --debug /usr/lib/sonarr/bin/Sonarr.exe -nobrowser -data=/__INSTALL_DIR__
TimeoutStopSec=20
KillMode=process
Restart=on-failure

View file

@ -22,24 +22,20 @@ ynh_print_info --message="Declaring files to be backed up..."
ynh_backup --src_path="$install_dir"
#=================================================
# BACKUP THE NGINX CONFIGURATION
# SYSTEM CONFIGURATION
#=================================================
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP LOGROTATE
#=================================================
ynh_backup --src_path="/etc/logrotate.d/$app"
ynh_backup --src_path="/etc/systemd/system/$app.service"
#=================================================
# BACKUP SYSTEMD
# BACKUP VARIOUS FILES
#=================================================
ynh_backup --src_path="/etc/systemd/system/$app.service"
ynh_backup --src_path="/var/log/$app/"
#=================================================
# END OF SCRIPT

View file

@ -1,14 +1,49 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# INITIALIZE AND STORE SETTINGS
#=================================================
# Generate API key for configuration later
api_key=$(ynh_string_random --length=32)
ynh_app_setting_set --app=$app --key=api_key --value=$api_key
ynh_app_setting_set --app=$app --key="api_key" --value="$api_key"
# Stop the service automatically created upon installation of the package
ynh_systemd_action --service_name=sonarr --action="stop"
ynh_systemd_action --service_name="sonarr" --action="stop"
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring Radarr..." --weight=2
# Create $install_dir and its logs subdirectory
mkdir -p "/var/log/$app"
ln -s "/var/log/$app" "$install_dir/logs"
ynh_add_config --template="config.xml" --destination="$install_dir/config.xml"
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R "$app:$app" "$install_dir"
#=================================================
# YUNOHOST MULTIMEDIA INTEGRATION
#=================================================
ynh_script_progression --message="Adding multimedia directories..." --weight=2
# Build YunoHost multimedia directories
ynh_multimedia_build_main_dir
# Enable writing into these directories
ynh_multimedia_addaccess "$app"
#=================================================
# NGINX CONFIGURATION
@ -20,47 +55,10 @@ ynh_add_nginx_config
# Create a dedicated systemd config, it will override the one in /lib/systemd/system/sonarr.service
ynh_add_systemd_config
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring Radarr..." --weight=2
# Create $install_dir and its logs subdirectory
mkdir -p "$install_dir/logs"
chmod 750 "$install_dir"
ynh_add_config --template="config.xml" --destination="$install_dir/config.xml"
chmod -R o-rwx "$install_dir"
chown -R $app:$app "$install_dir"
#=================================================
# YUNOHOST MULTIMEDIA INTEGRATION
#=================================================
ynh_script_progression --message="Adding multimedia directories..." --weight=2
# Build YunoHost multimedia directories
ynh_multimedia_build_main_dir
# Enable writing into these directories
ynh_multimedia_addaccess $app
#=================================================
# GENERIC FINALIZATIONs
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Configuring log rotation..."
yunohost service add "$app" --description="Sonarr daemon" --log="/var/log/$app/sonarr.txt"
# Use logrotate to manage application logfile(s)
ynh_use_logrotate --logfile="$install_dir/logs/"
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --description="Sonarr daemon" --log="$install_dir/logs/sonarr.txt"
ynh_use_logrotate --logfile="/var/log/$app/"
#=================================================
# START SYSTEMD SERVICE
@ -68,7 +66,7 @@ yunohost service add $app --description="Sonarr daemon" --log="$install_dir/logs
ynh_script_progression --message="Starting a systemd service..." --weight=2
# Start a systemd service
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Starting Web Server" --timeout=30
ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" --line_match="Starting Web Server" --timeout=30
# If a first Sonarr app was running before installing this one,
# it may have been stopped by the installation of the dependencies.
@ -77,10 +75,6 @@ if ! systemctl -q is-active sonarr; then
ynh_exec_fully_quiet ynh_systemd_action --service_name=sonarr --action="restart" --log_path="systemd" --line_match="Starting Web Server" --timeout=30
fi
ynh_exec_warn cat "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_exec_warn cat "$install_dir/config.xml"
#=================================================
# END OF SCRIPT
#=================================================

View file

@ -10,16 +10,13 @@ source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# STANDARD REMOVE
#=================================================
# REMOVE SERVICE INTEGRATION IN YUNOHOST
# REMOVE SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Removing system configurations related to $app..." --weight=1
# Remove the service from the list of services known by YunoHost (added from `yunohost service add`)
if ynh_exec_warn_less yunohost service status $app >/dev/null
then
ynh_script_progression --message="Removing $app service integration..." --weight=1
yunohost service remove $app
if ynh_exec_warn_less yunohost service status "$app" >/dev/null; then
yunohost service remove "$app"
fi
# Remove the dedicated systemd config
@ -31,6 +28,8 @@ ynh_remove_nginx_config
# Remove the app-specific logrotate config
ynh_remove_logrotate
ynh_secure_remove --file="/var/log/$app"
#=================================================
# END OF SCRIPT
#=================================================

View file

@ -18,7 +18,7 @@ ynh_script_progression --message="Restoring the app main directory..." --weight=
ynh_restore_file --origin_path="$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:$app "$install_dir"
chown -R "$app:$app" "$install_dir"
#=================================================
# YUNOHOST MULTIMEDIA INTEGRATION
@ -28,44 +28,42 @@ ynh_script_progression --message="Adding multimedia directories..." --weight=2
# Build YunoHost multimedia directories
ynh_multimedia_build_main_dir
# Enable writing into these directories
ynh_multimedia_addaccess $app
ynh_multimedia_addaccess "$app"
#=================================================
# SPECIFIC RESTORATION
# RESTORE SYSTEM CONFIGURATIONS
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling dependencies..." --weight=4
ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service --quiet
systemctl enable "$app.service" --quiet
yunohost service add "$app" --description="Sonarr daemon" --log="/var/log/$app/sonarr.txt"
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
yunohost service add $app --description="Sonarr daemon" --log="$install_dir/logs/sonarr.txt"
#=================================================
# START SYSTEMD SERVICE
# RESTORE VARIOUS FILES
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=2
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Starting Web Server" --timeout=30
# If a first Sonarr app was running before installing this one,
# it may have been stopped by the installation of the dependencies.
# Let's restart it.
if ! systemctl is-active $app.service; then
ynh_exec_fully_quiet ynh_systemd_action --service_name=sonarr --action="start" --log_path="systemd" --line_match="Starting Web Server" --timeout=30
fi
ynh_restore_file --origin_path="/var/log/$app/"
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX
# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1
ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" --line_match="Starting Web Server" --timeout=30
# If a first Sonarr app was running before installing this one,
# it may have been stopped by the installation of the dependencies.
# Let's restart it.
if ! systemctl is-active "$app.service"; then
ynh_exec_fully_quiet ynh_systemd_action --service_name=sonarr --action="start" --log_path="systemd" --line_match="Starting Web Server" --timeout=30
fi
ynh_systemd_action --service_name=nginx --action=reload

View file

@ -9,12 +9,6 @@
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
@ -22,10 +16,21 @@ upgrade_type=$(ynh_check_app_version_changed)
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd"
ynh_systemd_action --service_name="$app" --action="stop" --log_path="systemd"
#=================================================
# NGINX CONFIGURATION
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
if [ -d "$install_dir/logs" ]; then
rm -rf "/var/log/$app"
mv "$install_dir/logs" "/var/log/$app"
ln -s "/var/log/$app" "$install_dir/logs"
fi
#=================================================
# REAPPLY SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
@ -34,24 +39,23 @@ ynh_add_nginx_config
# Create a dedicated systemd config
ynh_add_systemd_config
yunohost service add "$app" --description="Sonarr daemon" --log="/var/log/$app/sonarr.txt"
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append --logfile="$install_dir/logs"
yunohost service add $app --description="Sonarr daemon" --log="$install_dir/logs/sonarr.txt"
ynh_use_logrotate --non-append --logfile="/var/log/$app/"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=2
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Starting Web Server" --timeout=30
ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" --line_match="Starting Web Server" --timeout=30
# If a first Sonarr app was running before installing this one,
# it may have been stopped by the installation of the dependencies.
# Let's restart it.
if [[ $(systemctl list-units -all | grep 'sonarr.service' | grep 'inactive') ]]; then
ynh_exec_fully_quiet ynh_systemd_action --service_name=sonarr --action="start" --log_path="systemd" --line_match="Starting Web Server" --timeout=30
# Let's restart it. (hence why we use sonarr and not $app..)
if ! systemctl -q is-active sonarr; then
ynh_exec_fully_quiet ynh_systemd_action --service_name=sonarr --action="restart" --log_path="systemd" --line_match="Starting Web Server" --timeout=30
fi
#=================================================