mirror of
https://github.com/YunoHost-Apps/crabfit_ynh.git
synced 2024-09-03 18:16:21 +02:00
WIP: adapt other scripts (remote, backup, ...)
This commit is contained in:
parent
247911d4ba
commit
d63e20d294
5 changed files with 85 additions and 67 deletions
|
@ -26,13 +26,6 @@ ynh_print_info --message="Declaring files to be backed up..."
|
|||
|
||||
ynh_backup --src_path="$install_dir"
|
||||
|
||||
#=================================================
|
||||
# BACKUP THE DATA DIR
|
||||
#=================================================
|
||||
|
||||
# Only relevant if there is a "data_dir" resource for this app
|
||||
ynh_backup --src_path="$data_dir" --is_big
|
||||
|
||||
#=================================================
|
||||
# BACKUP THE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
@ -51,25 +44,19 @@ ynh_backup --src_path="/etc/logrotate.d/$app"
|
|||
# BACKUP SYSTEMD
|
||||
#=================================================
|
||||
|
||||
ynh_backup --src_path="/etc/systemd/system/$app.service"
|
||||
ynh_backup --src_path="/etc/systemd/system/$app.target"
|
||||
ynh_backup --src_path="/etc/systemd/system/${app}-front.service"
|
||||
ynh_backup --src_path="/etc/systemd/system/${app}-back.service"
|
||||
|
||||
#=================================================
|
||||
# BACKUP VARIOUS FILES
|
||||
# BACKUP THE POSTGRES DATABASE
|
||||
#=================================================
|
||||
ynh_print_info --message="Backing up the POSTGRES database..."
|
||||
|
||||
ynh_backup --src_path="/etc/cron.d/$app"
|
||||
|
||||
ynh_backup --src_path="/etc/$app/"
|
||||
|
||||
#=================================================
|
||||
# BACKUP THE MYSQL DATABASE
|
||||
#=================================================
|
||||
ynh_print_info --message="Backing up the MySQL database..."
|
||||
|
||||
### (However, things like MySQL dumps *do* take some time to run, though the
|
||||
### (However, things like Postgres dumps *do* take some time to run, though the
|
||||
### copy of the generated dump to the archive still happens later)
|
||||
|
||||
ynh_mysql_dump_db --database="$db_name" > db.sql
|
||||
ynh_psql_dump_db --database="$db_name" > db.sql
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
|
|
|
@ -16,7 +16,8 @@ source /usr/share/yunohost/helpers
|
|||
#=================================================
|
||||
ynh_script_progression --message="Stopping a systemd service..." --weight=1
|
||||
|
||||
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
|
||||
ynh_systemd_action --service_name="${app}-front" --action="stop" --log_path="/var/log/$app/${app}-front.log"
|
||||
ynh_systemd_action --service_name="${app}-back" --action="stop" --log_path="/var/log/$app/${app}-back.log"
|
||||
|
||||
#=================================================
|
||||
# MODIFY URL IN NGINX CONF
|
||||
|
@ -38,7 +39,8 @@ ynh_change_url_nginx_config
|
|||
#=================================================
|
||||
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
||||
|
||||
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
|
||||
ynh_systemd_action --service_name="${app}-front" --action="start" --log_path="/var/log/$app/${app}-front.log"
|
||||
ynh_systemd_action --service_name="${app}-back" --action="start" --log_path="/var/log/$app/${app}-back.log"
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
|
|
|
@ -19,23 +19,17 @@ ynh_script_progression --message="Removing system configurations related to $app
|
|||
# This should be a symetric version of what happens in the install script
|
||||
|
||||
# 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
|
||||
fi
|
||||
ynh_script_progression --message="Removing $app service integration..." --weight=1
|
||||
yunohost service remove "${app}-back"
|
||||
yunohost service remove "${app}-front"
|
||||
|
||||
ynh_remove_systemd_config
|
||||
ynh_remove_systemd_config --service="${app}-back"
|
||||
ynh_remove_systemd_config --service="${app}-front"
|
||||
ynh_secure_remove --file="/etc/systemd/system/$app.target"
|
||||
|
||||
ynh_remove_nginx_config
|
||||
ynh_remove_logrotate
|
||||
|
||||
# Remove other various files specific to the app... such as :
|
||||
|
||||
ynh_secure_remove --file="/etc/cron.d/$app"
|
||||
|
||||
ynh_secure_remove --file="/etc/$app"
|
||||
|
||||
ynh_secure_remove --file="/var/log/$app"
|
||||
|
||||
#=================================================
|
||||
|
|
|
@ -23,21 +23,11 @@ ynh_restore_file --origin_path="$install_dir"
|
|||
chown -R $app:www-data "$install_dir"
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE DATA DIRECTORY
|
||||
# RESTORE THE POSTGRESQL DATABASE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Restoring the data directory..." --weight=1
|
||||
ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1
|
||||
|
||||
ynh_restore_file --origin_path="$data_dir" --not_mandatory
|
||||
|
||||
# (Same as for install dir)
|
||||
chown -R $app:www-data "$data_dir"
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE MYSQL DATABASE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Restoring the MySQL database..." --weight=1
|
||||
|
||||
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
|
||||
ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
|
||||
|
||||
#=================================================
|
||||
# RESTORE SYSTEM CONFIGURATIONS
|
||||
|
@ -48,18 +38,17 @@ ynh_script_progression --message="Restoring system configurations related to $ap
|
|||
|
||||
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
|
||||
ynh_restore_file --origin_path="/etc/systemd/system/$app.target"
|
||||
ynh_restore_file --origin_path="/etc/systemd/system/${app}-front.service"
|
||||
ynh_restore_file --origin_path="/etc/systemd/system/${app}-back.service"
|
||||
systemctl enable ${app}-front.service --quiet
|
||||
systemctl enable ${app}-back.service --quiet
|
||||
|
||||
yunohost service add $app --description="A short description of the app" --log="/var/log/$app/$app.log"
|
||||
yunohost service add "${app}-front" --description="Crabfit NodeJS Frontend" --log="/var/log/$app/${app}-front.log"
|
||||
yunohost service add "${app}-back" --description="Crabfit Rust Backend" --log="/var/log/$app/${app}-back.log"
|
||||
|
||||
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
|
||||
|
||||
# Other various files...
|
||||
|
||||
ynh_restore_file --origin_path="/etc/cron.d/$app"
|
||||
ynh_restore_file --origin_path="/etc/$app/"
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
|
@ -67,7 +56,8 @@ ynh_restore_file --origin_path="/etc/$app/"
|
|||
#=================================================
|
||||
ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1
|
||||
|
||||
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
|
||||
ynh_systemd_action --service_name="${app}-front" --action="start" --log_path="/var/log/$app/${app}-front.log"
|
||||
ynh_systemd_action --service_name="${app}-back" --action="start" --log_path="/var/log/$app/${app}-back.log"
|
||||
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
|
||||
|
|
|
@ -60,7 +60,8 @@ 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="/var/log/$app/$app.log"
|
||||
ynh_systemd_action --service_name="${app}-front" --action="stop" --log_path="/var/log/$app/${app}-front"
|
||||
ynh_systemd_action --service_name="${app}-back" --action="stop" --log_path="/var/log/$app/${app}-back"
|
||||
|
||||
#=================================================
|
||||
# "REBUILD" THE APP (DEPLOY NEW SOURCES, RERUN NPM BUILD...)
|
||||
|
@ -88,13 +89,18 @@ ynh_script_progression --message="Upgrading system configurations related to $ap
|
|||
|
||||
# This should be a literal copypasta of what happened in the install's "System configuration" section
|
||||
|
||||
# Create a dedicated NGINX config using the conf/nginx.conf template
|
||||
ynh_add_nginx_config
|
||||
|
||||
ynh_add_systemd_config
|
||||
# Create a dedicated systemd config
|
||||
ynh_add_config --template="../conf/crabfit.target" --destination="/etc/systemd/system/$app.target"
|
||||
ynh_add_systemd_config --service="${app}-front" --template="crabfit-front.service"
|
||||
ynh_add_systemd_config --service="${app}-back" --template="crabfit-back.service"
|
||||
|
||||
yunohost service add $app --description="A short description of the app" --log="/var/log/$app/$app.log"
|
||||
yunohost service add "${app}-front" --description="Crabfit NodeJS Frontend" --log="/var/log/$app/${app}-front.log"
|
||||
yunohost service add "${app}-back" --description="Crabfit Rust Backend" --log="/var/log/$app/${app}-back.log"
|
||||
|
||||
ynh_use_logrotate --non-append
|
||||
ynh_use_logrotate
|
||||
|
||||
#=================================================
|
||||
# RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS...)
|
||||
|
@ -108,13 +114,15 @@ ynh_script_progression --message="Updating a configuration file..." --weight=1
|
|||
### The file will automatically be backed-up if it's found to be manually modified (because
|
||||
### ynh_add_config keeps track of the file's checksum)
|
||||
|
||||
ynh_add_config --template="some_config_file" --destination="$install_dir/some_config_file"
|
||||
# Replace the default .env.local with our own
|
||||
rm $install_dir/frontend/.env.local
|
||||
ynh_add_config --template="../conf/front.env" --destination="$install_dir/frontend/.env.local"
|
||||
chmod 400 "$install_dir/frontend/.env.local"
|
||||
chown $app:$app "$install_dir/frontend/.env.local"
|
||||
|
||||
# FIXME: this should be handled by the core in the future
|
||||
# You may need to use chmod 600 instead of 400,
|
||||
# for example if the app is expected to be able to modify its own config
|
||||
chmod 400 "$install_dir/some_config_file"
|
||||
chown $app:$app "$install_dir/some_config_file"
|
||||
ynh_add_config --template="../conf/back.env" --destination="$install_dir/api/.env"
|
||||
chmod 400 "$install_dir/api/.env"
|
||||
chown $app:$app "$install_dir/api/.env"
|
||||
|
||||
### For more complex cases where you want to replace stuff using regexes,
|
||||
### you shoud rely on ynh_replace_string (which is basically a wrapper for sed)
|
||||
|
@ -123,12 +131,49 @@ chown $app:$app "$install_dir/some_config_file"
|
|||
### ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$install_dir/some_config_file"
|
||||
### ynh_store_file_checksum --file="$install_dir/some_config_file"
|
||||
|
||||
#=================================================
|
||||
# BUILD BACKEND
|
||||
#=================================================
|
||||
ynh_script_progression --message="Building crabfit backend..." --weight=1
|
||||
|
||||
# The cargo version packaged with debian (currently 11) is too old and results in errors..
|
||||
# Thus the latest version is manually installed alongside the application for the moment
|
||||
pushd $install_dir/api
|
||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup.sh
|
||||
ynh_exec_warn_less ynh_exec_as "$app" \
|
||||
RUSTUP_HOME=$install_dir/api/.rustup \
|
||||
CARGO_HOME=$install_dir/api/.cargo \
|
||||
sh rustup.sh -y -q --no-modify-path --default-toolchain=stable
|
||||
export PATH="$PATH:$install_dir/.cargo/bin"
|
||||
ynh_exec_warn_less ynh_exec_as "$app" \
|
||||
RUSTUP_HOME=$install_dir/api/.rustup \
|
||||
CARGO_HOME=$install_dir/api/.cargo \
|
||||
$install_dir/api/.cargo/bin/cargo build --release #--features sql-adaptor
|
||||
|
||||
# Remove build files and rustup
|
||||
# cp -af "$install_dir/api/target/release/crabfit-api" "$install_dir/api/api"
|
||||
# ynh_secure_remove --file="$final_path/build"
|
||||
ynh_secure_remove --file="$install_dir/api/.cargo"
|
||||
ynh_secure_remove --file="$install_dir/api/.rustup"
|
||||
popd
|
||||
|
||||
#=================================================
|
||||
# BUILD FRONTEND
|
||||
#=================================================
|
||||
ynh_script_progression --message="Building crabfit frontend..." --weight=1
|
||||
pushd $install_dir/frontend
|
||||
ynh_use_nodejs
|
||||
ynh_exec_warn_less ynh_exec_as "$app" env "$ynh_node_load_PATH" $nodejs_path/yarn install --production --frozen-lockfile
|
||||
ynh_exec_warn_less ynh_exec_as "$app" env "$ynh_node_load_PATH" $ynh_npm run build
|
||||
popd
|
||||
|
||||
#=================================================
|
||||
# START SYSTEMD SERVICE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
||||
|
||||
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
|
||||
ynh_systemd_action --service_name="${app}-front" --action="start" --log_path="/var/log/$app/${app}-front.log"
|
||||
ynh_systemd_action --service_name="${app}-back" --action="start" --log_path="/var/log/$app/${app}-back.log"
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
|
|
Loading…
Reference in a new issue