1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/piped_ynh.git synced 2024-09-03 20:05:54 +02:00

Fix backup, restore and upgrade?

This commit is contained in:
orhtej2 2024-01-28 20:02:27 +01:00
parent b35d4c5242
commit 8b9a0c82a5
4 changed files with 132 additions and 19 deletions

View file

@ -28,6 +28,26 @@ ynh_backup --src_path="$install_dir"
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# BACKUP LOGROTATE CONFIGURATION
#=================================================
ynh_backup --src_path="/etc/logrotate.d/$app"
#=================================================
# BACKUP SYSTEMD CONFIGURATION
#=================================================
ynh_backup --src_path="/etc/systemd/system/$app-api.service"
ynh_backup --src_path="/etc/systemd/system/$app-proxy.service"
#=================================================
# BACKUP THE POSTGRESQL DATABASE
#=================================================
ynh_print_info --message="Backing up the PostgreSQL database..."
ynh_psql_dump_db --database="$db_name" > db.sql
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================

View file

@ -57,9 +57,7 @@ chown -R $app:www-data "$install_dir/dist"
chmod -R 755 "$install_dir/dist" chmod -R 755 "$install_dir/dist"
ynh_secure_remove --file="$install_dir/build" ynh_secure_remove --file="$install_dir/build"
ynh_secure_remove --file="$install_dir/.npm"
ynh_secure_remove --file="$install_dir/.local" ynh_secure_remove --file="$install_dir/.local"
ynh_secure_remove --file="$install_dir/.node"
ynh_secure_remove --file="$install_dir/.cache" ynh_secure_remove --file="$install_dir/.cache"
ynh_script_progression --message="Building API..." --weight=5 ynh_script_progression --message="Building API..." --weight=5
@ -73,6 +71,8 @@ mv $install_dir/build_api/build/libs/piped-1.0-all.jar $install_dir/piped.jar
ynh_add_config --template="config.properties" --destination="$install_dir/config.properties" ynh_add_config --template="config.properties" --destination="$install_dir/config.properties"
chown $app:$app "$install_dir/config.properties" chown $app:$app "$install_dir/config.properties"
chmod 600 "$install_dir/config.properties" chmod 600 "$install_dir/config.properties"
ynh_secure_remove --file="$install_dir/.gradle"
ynh_secure_remove --file="$install_dir/build_api"
ynh_script_progression --message="Building Proxy..." --weight=5 ynh_script_progression --message="Building Proxy..." --weight=5
@ -82,6 +82,8 @@ popd
mv $install_dir/build_proxy/target/release/piped-proxy $install_dir mv $install_dir/build_proxy/target/release/piped-proxy $install_dir
ynh_secure_remove --file="$install_dir/.rustup" ynh_secure_remove --file="$install_dir/.rustup"
ynh_secure_remove --file="$install_dir/.cargo"
ynh_secure_remove --file="$install_dir/build_proxy"
#================================================= #=================================================
# SYSTEM CONFIGURATION # SYSTEM CONFIGURATION

View file

@ -18,22 +18,48 @@ ynh_script_progression --message="Restoring the app main directory..." --weight=
ynh_restore_file --origin_path="$install_dir" ynh_restore_file --origin_path="$install_dir"
chown -R $app:www-data "$install_dir" chown -R $app:www-data "$install_dir"
chown $app:$app "$install_dir/config.properties"
chmod 600 "$install_dir/config.properties"
#================================================= #=================================================
# RESTORE THE MYSQL DATABASE # RESTORE THE POSTGRESQL DATABASE
#================================================= #=================================================
ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=3
ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name
#================================================= #=================================================
# RESTORE SYSTEM CONFIGURATIONS # RESTORE SYSTEM CONFIGURATIONS
#================================================= #=================================================
ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1
# This should be a symetric version of what happens in the install script
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_restore_file --origin_path="/etc/systemd/system/$app-api.service"
systemctl enable $app-api.service --quiet
ynh_restore_file --origin_path="/etc/systemd/system/$app-proxy.service"
systemctl enable $app-proxy.service --quiet
#================================================= #=================================================
# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE # RESTORE THE LOGROTATE CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1
mkdir -p /var/log/$app
chown -R $app:root /var/log/$app
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add "$app-api" --description="Piped backend API service" --log="/var/log/$app/$app-api.log"
yunohost service add "$app-proxy" --description="Piped HTTP proxy service" --log="/var/log/$app/$app-proxy.log"
#=================================================
# RELOAD NGINX THE APP SERVICE
#================================================= #=================================================
ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1 ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1

View file

@ -22,7 +22,8 @@ upgrade_type=$(ynh_check_app_version_changed)
#================================================= #=================================================
ynh_script_progression --message="Stopping a systemd service..." ynh_script_progression --message="Stopping a systemd service..."
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name=$app-api --action="stop" --log_path="/var/log/$app/$app-api.log" --line_match="Shutdown completed"
ynh_systemd_action --service_name=$app-proxy --action="stop"
#================================================= #=================================================
# "REBUILD" THE APP (DEPLOY NEW SOURCES, RERUN NPM BUILD...) # "REBUILD" THE APP (DEPLOY NEW SOURCES, RERUN NPM BUILD...)
@ -32,14 +33,74 @@ ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app
if [ "$upgrade_type" == "UPGRADE_APP" ] if [ "$upgrade_type" == "UPGRADE_APP" ]
then then
ynh_script_progression --message="Upgrading source files..." ynh_script_progression --message="Installing dependencies..." --weight=3
# Download, check integrity, uncompress and patch the source from app.src ynh_install_nodejs --nodejs_version=$NODEJS_VERSION
ynh_setup_source --dest_dir="$install_dir" ynh_use_nodejs
ynh_setup_source --dest_dir="$install_dir/jdk" --source_id="jdk" --full_replace=1
ynh_exec_warn_less ynh_exec_as $app RUSTUP_HOME="$install_dir"/.rustup CARGO_HOME="$install_dir"/.cargo bash -c 'curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -q -y'
export PATH="$install_dir/jdk/bin:$install_dir/.cargo/bin:$PATH"
ynh_script_progression --message="Setting up source files..."
ynh_setup_source --dest_dir="$install_dir/build"
ynh_setup_source --dest_dir="$install_dir/build_api" --source_id="api"
ynh_setup_source --dest_dir="$install_dir/build_proxy" --source_id="proxy"
chown -R $app:www-data "$install_dir"
chmod -R 755 "$install_dir"
ynh_script_progression --message="Building UI..." --weight=5
pushd $install_dir/build
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH corepack enable
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH corepack prepare pnpm@latest --activate
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH pnpm install
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH NODE_ENV=production pnpm build
ynh_exec_warn_less ynh_exec_as $app ./localizefonts.sh
popd
ynh_secure_remove --file="$install_dir/dist"
mv $install_dir/build/dist $install_dir
pushd $install_dir/dist
sed -i s/pipedapi.kavin.rocks/"$domain\\/api"/g assets/*
popd
chown -R $app:www-data "$install_dir/dist"
chmod -R 755 "$install_dir/dist"
ynh_secure_remove --file="$install_dir/build"
ynh_secure_remove --file="$install_dir/.local"
ynh_secure_remove --file="$install_dir/.cache"
ynh_script_progression --message="Building API..." --weight=5
pushd $install_dir/build_api
ynh_exec_warn_less ynh_exec_as $app JAVA_HOME=$install_dir/jdk ./gradlew shadowJar
ynh_exec_warn_less ynh_exec_as $app JAVA_HOME=$install_dir/jdk ./gradlew --stop
popd
ynh_secure_remove --file="$install_dir/piped.jar"
mv $install_dir/build_api/build/libs/piped-1.0-all.jar $install_dir/piped.jar
ynh_secure_remove --file="$install_dir/build_api"
ynh_secure_remove --file="$install_dir/.gradle"
ynh_script_progression --message="Building Proxy..." --weight=5
pushd $install_dir/build_proxy
ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH cargo build --release
popd
ynh_secure_remove --file="$install_dir/piped-proxy"
mv $install_dir/build_proxy/target/release/piped-proxy $install_dir
ynh_secure_remove --file="$install_dir/.rustup"
ynh_secure_remove --file="$install_dir/.cargo"
ynh_secure_remove --file="$install_dir/build_proxy"
fi fi
chown -R $app:www-data "$install_dir"
#================================================= #=================================================
# REAPPLY SYSTEM CONFIGURATIONS # REAPPLY SYSTEM CONFIGURATIONS
#================================================= #=================================================
@ -47,9 +108,11 @@ ynh_script_progression --message="Upgrading system configurations related to $ap
ynh_add_nginx_config ynh_add_nginx_config
ynh_add_systemd_config ynh_add_systemd_config --template="api.service" --service="$app-api"
yunohost service add "$app-api" --description="Piped backend API service" --log="/var/log/$app/$app-api.log"
yunohost service add $app --log="/var/log/$app/$app.log" ynh_add_systemd_config --template="proxy.service" --service="$app-proxy"
yunohost service add "$app-proxy" --description="Piped HTTP proxy service" --log="/var/log/$app/$app-proxy.log"
#================================================= #=================================================
# RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS...) # RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS...)
@ -58,17 +121,19 @@ yunohost service add $app --log="/var/log/$app/$app.log"
#================================================= #=================================================
ynh_script_progression --message="Updating a configuration file..." ynh_script_progression --message="Updating a configuration file..."
ynh_add_config --template="" --destination="$install_dir/" ynh_add_config --template="config.properties" --destination="$install_dir/config.properties"
chown $app:$app "$install_dir/config.properties"
chmod 400 "$install_dir/some_config_file" chmod 600 "$install_dir/config.properties"
chown $app:$app "$install_dir/some_config_file"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." ynh_script_progression --message="Starting a systemd service..."
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" # Start a systemd service
ynh_systemd_action --service_name=$app-api --action="start" --log_path="/var/log/$app/$app-api.log" --line_match="HTTP Server is listening on"
ynh_systemd_action --service_name=$app-proxy --action="start" --log_path="/var/log/$app/$app-proxy.log" --line_match="Running server!"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT