From aa287f0a408afbea176206173ed9019d5e9a8984 Mon Sep 17 00:00:00 2001 From: antoine Date: Fri, 12 Jun 2020 21:21:09 +0200 Subject: [PATCH] update scripts --- conf/nginx.conf | 2 +- conf/php-fpm.conf | 2 +- scripts/_common.sh | 2 +- scripts/backup | 48 ++++++++++++++++++++-------------------------- scripts/install | 37 +++++++++++++++++++++-------------- scripts/remove | 4 ++-- scripts/restore | 11 +++++++---- scripts/upgrade | 5 ++++- 8 files changed, 60 insertions(+), 51 deletions(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index f2277ea..37de41d 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -18,7 +18,7 @@ location __PATH__/ { try_files $uri $uri/ index.php; location ~ [^/]\.php(/|$) { fastcgi_split_path_info ^(.+?\.php)(/.*)$; - fastcgi_pass unix:/var/run/php/php7.0-fpm-__NAME__.sock; + fastcgi_pass unix:/var/run/php/php__PHPVERSION__-fpm-__NAME__.sock; fastcgi_index index.php; include fastcgi_params; diff --git a/conf/php-fpm.conf b/conf/php-fpm.conf index ab5dca9..ab1a471 100644 --- a/conf/php-fpm.conf +++ b/conf/php-fpm.conf @@ -33,7 +33,7 @@ group = __USER__ ; (IPv6 and IPv4-mapped) on a specific port; ; '/path/to/unix/socket' - to listen on a unix socket. ; Note: This value is mandatory. -listen = /var/run/php/php7.0-fpm-__NAMETOCHANGE__.sock +listen = /var/run/php/php__PHPVERSION__-fpm-__NAMETOCHANGE__.sock ; Set listen(2) backlog. ; Default Value: 511 (-1 on FreeBSD and OpenBSD) diff --git a/scripts/_common.sh b/scripts/_common.sh index 8bb05b4..7e55ac0 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -5,7 +5,7 @@ #================================================= # dependencies used by the app -pkg_dependencies="deb1 deb2" +pkg_dependencies="deb1 deb2 php$YNH_DEFAULT_PHP_VERSION-deb1 php$YNH_DEFAULT_PHP_VERSION-deb2" #================================================= # PERSONAL HELPERS diff --git a/scripts/backup b/scripts/backup index 711894f..d0e7833 100755 --- a/scripts/backup +++ b/scripts/backup @@ -24,55 +24,46 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --time --weight=1 +ynh_print_info --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME final_path=$(ynh_app_setting_get --app=$app --key=final_path) domain=$(ynh_app_setting_get --app=$app --key=domain) db_name=$(ynh_app_setting_get --app=$app --key=db_name) +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= -# STANDARD BACKUP STEPS +# DECLARE DATA AND CONF FILES TO BACKUP #================================================= -# STOP SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Stopping a systemd service..." --time --weight=1 +ynh_print_info --message="Declaring files to be backed up..." -#ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" +### N.B. : the following 'ynh_backup' calls are only a *declaration* of what needs +### to be backuped and not an actual copy of any file. The actual backup that +### creates and fill the archive with the files happens in the core after this +### script is called. Hence ynh_backups calls takes basically 0 seconds to run. #================================================= # BACKUP THE APP MAIN DIR #================================================= -ynh_script_progression --message="Backing up the main app directory..." --time --weight=1 ynh_backup --src_path="$final_path" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Backing up nginx web server configuration..." --time --weight=1 ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # BACKUP THE PHP-FPM CONFIGURATION #================================================= -ynh_script_progression --message="Backing up php-fpm configuration..." --time --weight=1 -ynh_backup --src_path="/etc/php/7.0/fpm/pool.d/$app.conf" - -#================================================= -# BACKUP THE MYSQL DATABASE -#================================================= -ynh_script_progression --message="Backing up the MySQL database..." --time --weight=1 - -ynh_mysql_dump_db --database="$db_name" > db.sql +ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" #================================================= # BACKUP FAIL2BAN CONFIGURATION #================================================= -ynh_script_progression --message="Backing up fail2ban configuration..." --time --weight=1 #ynh_backup --src_path="/etc/fail2ban/jail.d/$app.conf" #ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf" @@ -82,32 +73,35 @@ ynh_script_progression --message="Backing up fail2ban configuration..." --time - #================================================= # BACKUP LOGROTATE #================================================= -ynh_script_progression --message="Backing up logrotate configuration..." --time --weight=1 #ynh_backup --src_path="/etc/logrotate.d/$app" #================================================= # BACKUP SYSTEMD #================================================= -ynh_script_progression --message="Backing up systemd configuration..." --time --weight=1 #ynh_backup --src_path="/etc/systemd/system/$app.service" #================================================= -# BACKUP A CRON FILE +# BACKUP VARIOUS FILES #================================================= #ynh_backup --src_path="/etc/cron.d/$app" -#================================================= -# START SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Starting a systemd service..." --time --weight=1 +#ynh_backup --src_path="/etc/$app/" -#ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +#================================================= +# 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 +### copy of the generated dump to the archive still happens later) + +ynh_mysql_dump_db --database="$db_name" > db.sql #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --time --last +ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/install b/scripts/install index 14bc4a2..1b26082 100755 --- a/scripts/install +++ b/scripts/install @@ -231,7 +231,12 @@ ynh_systemd_action --service_name=nginx --action=reload # Installation with curl ynh_script_progression --message="Finalizing installation..." --time --weight=1 #ynh_local_curl "/INSTALL_PATH" "key1=value1" "key2=value2" "key3=value3" -#ynh_local_curl "/install.php" + +ynh_replace_string --match_string="votre_nom_de_bdd" --replace_string=$db_name --target_file="$final_path/conf/config.php" +ynh_replace_string --match_string="votre_utilisateur_de_bdd" --replace_string=$db_user --target_file="$final_path/conf/config.php" +ynh_replace_string --match_string="votre_mdp_de_bdd" --replace_string=$db_pwd --target_file="$final_path/conf/config.php" + +ynh_local_curl "/install.php" # Remove the public access if [ $is_public -eq 0 ] @@ -247,11 +252,6 @@ fi ### (It's compatible with sed regular expressions syntax) #ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$final_path/CONFIG_FILE" -ynh_replace_string --match_string="votre_nom_de_bdd" --replace_string=$db_name --target_file="$final_path/conf/config.php" -ynh_replace_string --match_string="votre_utilisateur_de_bdd" --replace_string=$db_user --target_file="$final_path/conf/config.php" -ynh_replace_string --match_string="votre_mdp_de_bdd" --replace_string=$db_pwd --target_file="$final_path/conf/config.php" - -ynh_local_curl "/install.php" #================================================= # STORE THE CONFIG FILE CHECKSUM @@ -309,17 +309,26 @@ ynh_script_progression --message="Configuring log rotation..." --time --weight=1 ### If you're not using these lines: ### - You can remove these files in conf/. ### - Remove the section "REMOVE SERVICE FROM ADMIN PANEL" in the remove script -### - As well as the section "ADVERTISE SERVICE IN ADMIN PANEL" in the restore script +### - As well as the section "INTEGRATE SERVICE IN YUNOHOST" in the restore script #yunohost service add $app --description "A short description of the app" --log "/var/log/$app/$app.log" -### With YunoHost 3.8 you will then be able to: -### - specify a list of ports that needs to be publicly exposed (c.f. --needs_exposed_ports) -### which will then be checked by YunoHost's diagnosis system -### - specify a custom command to check the status of the service (c.f. --test_status) -### though it's only needed for weird cases where 'systemctl status' doesn't do a good job -### - specify a custom command to check / validate the configuration of the service (c.f. --test_conf) -### for example, the command to check the configuration of nginx is "nginx -t" +### Additional options starting with 3.8: +### +### --needs_exposed_ports "$port" a list of ports that needs to be publicly exposed +### which will then be checked by YunoHost's diagnosis system +### (N.B. DO NOT USE THIS is the port is only internal !!!) +### +### --test_status "some command" a custom command to check the status of the service +### (only relevant if 'systemctl status' doesn't do a good job) +### +### --test_conf "some command" some command similar to "nginx -t" that validates the conf of the service +### +### Re-calling 'yunohost service add' during the upgrade script is the right way +### to proceed if you later realize that you need to enable some flags that +### weren't enabled on old installs (be careful it'll override the existing +### service though so you should re-provide all relevant flags when doing so) +### #================================================= # START SYSTEMD SERVICE diff --git a/scripts/remove b/scripts/remove index e0cd1dd..0e5b7a5 100755 --- a/scripts/remove +++ b/scripts/remove @@ -97,7 +97,7 @@ ynh_remove_logrotate if yunohost firewall list | grep -q "\- $port$" then - ynh_script_progression --message="Closing port $port..." + ynh_script_progression --message="Closing port $port..." --time --weight=1 ynh_exec_warn_less yunohost firewall disallow TCP $port fi @@ -112,7 +112,7 @@ ynh_script_progression --message="Removing fail2ban configuration..." --time --w #================================================= # SPECIFIC REMOVE #================================================= -# REMOVE THE CRON FILE +# REMOVE VARIOUS FILES #================================================= # Remove a cron file diff --git a/scripts/restore b/scripts/restore index 4e3b215..af86347 100755 --- a/scripts/restore +++ b/scripts/restore @@ -24,7 +24,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading settings..." --time --weight=1 +ynh_script_progression --message="Loading installation settings..." --time --weight=1 app=$YNH_APP_INSTANCE_NAME @@ -33,6 +33,7 @@ path_url=$(ynh_app_setting_get --app=$app --key=path) final_path=$(ynh_app_setting_get --app=$app --key=final_path) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -78,7 +79,7 @@ chown -R root: $final_path # RESTORE THE PHP-FPM CONFIGURATION #================================================= -ynh_restore_file --origin_path="/etc/php/7.0/fpm/pool.d/$app.conf" +ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" #================================================= # RESTORE FAIL2BAN CONFIGURATION @@ -130,11 +131,13 @@ ynh_script_progression --message="Starting a systemd service..." --time --weight #ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" #================================================= -# RESTORE THE CRON FILE +# RESTORE VARIOUS FILES #================================================= #ynh_restore_file --origin_path="/etc/cron.d/$app" +#ynh_restore_file --origin_path="/etc/$app/" + #================================================= # RESTORE THE LOGROTATE CONFIGURATION #================================================= @@ -148,7 +151,7 @@ ynh_script_progression --message="Starting a systemd service..." --time --weight #================================================= ynh_script_progression --message="Reloading nginx web server and php-fpm..." --time --weight=1 -ynh_systemd_action --service_name=php7.0-fpm --action=reload +ynh_systemd_action --service_name=php$phpversion-fpm --action=reload ynh_systemd_action --service_name=nginx --action=reload #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 5e86bbc..54bdd7d 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -160,12 +160,15 @@ ynh_replace_string --match_string="votre_mdp_de_bdd" --replace_string=$db_pwd -- #================================================= -# STORE THE CONFIG FILE CHECKSUM +# MODIFY A CONFIG FILE #================================================= ### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. ### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it. #ynh_backup_if_checksum_is_different --file="$final_path/CONFIG_FILE" + +#ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$final_path/CONFIG_FILE" + # Recalculate and store the checksum of the file for the next upgrade. #ynh_store_file_checksum --file="$final_path/CONFIG_FILE"