mirror of
https://github.com/YunoHost-Apps/wordpress_ynh.git
synced 2024-09-03 20:36:10 +02:00
New reset actions
This commit is contained in:
parent
7a0b62eddb
commit
10a1fe6bf9
5 changed files with 240 additions and 2 deletions
30
actions.toml
30
actions.toml
|
@ -9,3 +9,33 @@ description = "Change the public access of the app."
|
||||||
type = "boolean"
|
type = "boolean"
|
||||||
ask = "Is it a public app ?"
|
ask = "Is it a public app ?"
|
||||||
default = true
|
default = true
|
||||||
|
|
||||||
|
|
||||||
|
[reset_default_nginx]
|
||||||
|
name = "Reset the nginx config for this app."
|
||||||
|
command = "/bin/bash scripts/actions/reset_default_system nginx"
|
||||||
|
# user = "root" # optional
|
||||||
|
# cwd = "/" # optional
|
||||||
|
# accepted_return_codes = [0, 1, 2, 3] # optional
|
||||||
|
accepted_return_codes = [0]
|
||||||
|
description = "Reset the nginx config for this app."
|
||||||
|
|
||||||
|
|
||||||
|
[reset_default_phpfpm]
|
||||||
|
name = "Reset the php-fpm config for this app."
|
||||||
|
command = "/bin/bash scripts/actions/reset_default_system phpfpm"
|
||||||
|
# user = "root" # optional
|
||||||
|
# cwd = "/" # optional
|
||||||
|
# accepted_return_codes = [0, 1, 2, 3] # optional
|
||||||
|
accepted_return_codes = [0]
|
||||||
|
description = "Reset the php-fpm config for this app."
|
||||||
|
|
||||||
|
|
||||||
|
[reset_default_app]
|
||||||
|
name = "Reset the app with a default configuration."
|
||||||
|
command = "/bin/bash scripts/actions/reset_default_app"
|
||||||
|
# user = "root" # optional
|
||||||
|
# cwd = "/" # optional
|
||||||
|
# accepted_return_codes = [0, 1, 2, 3] # optional
|
||||||
|
accepted_return_codes = [0]
|
||||||
|
description = "Reset the app to its default configuration to try to fix potential issues.<br>This action won't remove any data added to the app.<br>However, if you have modified any configuration, it will be overwritten."
|
||||||
|
|
128
scripts/actions/reset_default_app
Executable file
128
scripts/actions/reset_default_app
Executable file
|
@ -0,0 +1,128 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC STARTING
|
||||||
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
source scripts/_common.sh
|
||||||
|
source /usr/share/yunohost/helpers
|
||||||
|
source scripts/_ynh_add_fpm_config
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# MANAGE SCRIPT FAILURE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Exit if an error occurs during the execution of the script
|
||||||
|
ynh_abort_if_errors
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RETRIEVE ARGUMENTS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID}
|
||||||
|
|
||||||
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||||
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
||||||
|
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
|
||||||
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SPECIFIC ACTION
|
||||||
|
#=================================================
|
||||||
|
# ACTIVATE MAINTENANCE MODE
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Activating maintenance mode..."
|
||||||
|
|
||||||
|
ynh_maintenance_mode_ON
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# NGINX CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=1
|
||||||
|
|
||||||
|
# Create a dedicated nginx config
|
||||||
|
yunohost app action run $app reset_default_nginx
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# CREATE DEDICATED USER
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Making sure dedicated system user exists..."
|
||||||
|
|
||||||
|
# Create a dedicated user (if not existing)
|
||||||
|
ynh_system_user_create --username=$app
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# PHP-FPM CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_script_progression --message="Upgrading php-fpm configuration..." --weight=2
|
||||||
|
|
||||||
|
# Create a dedicated php-fpm config
|
||||||
|
yunohost app action run $app reset_default_phpfpm
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# CREATE A CRON TASK FOR AUTOMATIC UPDATE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
echo "# Reach everyday wp-cron.php?doing_wp_cron to trig the internal wordpress cron.
|
||||||
|
0 3 * * * root wget -q -O - https://$domain$path_url/wp-cron.php?doing_wp_cron >/dev/null 2>&1" > /etc/cron.d/$app
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SECURE FILES AND DIRECTORIES
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Set permissions to app files
|
||||||
|
# Files have to be own by the user of wordpress. To allow upgrade from the app.
|
||||||
|
chown -R $app: $final_path
|
||||||
|
# Except the file config wp-config.php
|
||||||
|
chown root: $final_path/wp-config.php
|
||||||
|
|
||||||
|
# Reset permissions
|
||||||
|
find $final_path/ -type f -print0 | xargs -0 chmod 0644
|
||||||
|
find $final_path/ -type d -print0 | xargs -0 chmod 0755
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# UPGRADE FAIL2BAN
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Reconfiguring fail2ban..." --weight=5
|
||||||
|
|
||||||
|
# Create a dedicated fail2ban config
|
||||||
|
ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="PHP message: Leed: wrong login for .* client: <HOST>" --max_retry=5
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SETUP SSOWAT
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Upgrading SSOwat configuration..." --weight=1
|
||||||
|
|
||||||
|
# Remove skipped_uris if it's still present
|
||||||
|
ynh_app_setting_delete --app=$app --key=skipped_uris
|
||||||
|
if [ $is_public -eq 0 ]; then
|
||||||
|
# Remove the public access
|
||||||
|
ynh_app_setting_delete --app=$app --key=unprotected_uris
|
||||||
|
else
|
||||||
|
# Or replace skipped_uris by unprotected_uris
|
||||||
|
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
|
||||||
|
fi
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RELOAD NGINX
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Reloading nginx web server..."
|
||||||
|
|
||||||
|
ynh_systemd_action --service_name=nginx --action=reload
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# DEACTIVE MAINTENANCE MODE
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Disabling maintenance mode..."
|
||||||
|
|
||||||
|
ynh_maintenance_mode_OFF
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# END OF SCRIPT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_script_progression --message="Execution completed" --last
|
80
scripts/actions/reset_default_system
Executable file
80
scripts/actions/reset_default_system
Executable file
|
@ -0,0 +1,80 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC STARTING
|
||||||
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
source scripts/_common.sh
|
||||||
|
source /usr/share/yunohost/helpers
|
||||||
|
source scripts/_ynh_add_fpm_config
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# MANAGE SCRIPT FAILURE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Exit if an error occurs during the execution of the script
|
||||||
|
ynh_abort_if_errors
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RETRIEVE ARGUMENTS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID}
|
||||||
|
|
||||||
|
type=$1
|
||||||
|
|
||||||
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||||
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
||||||
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||||
|
|
||||||
|
multisite=$(ynh_app_setting_get --app=$app --key=multisite)
|
||||||
|
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SPECIFIC ACTION
|
||||||
|
#=================================================
|
||||||
|
# RESET THE CONFIG FILE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
if [ $type == nginx ]; then
|
||||||
|
name=Nginx
|
||||||
|
elif [ $type == phpfpm ]; then
|
||||||
|
name=PHP-FPM
|
||||||
|
else
|
||||||
|
ynh_die --message="The type $type is not recognized"
|
||||||
|
fi
|
||||||
|
|
||||||
|
ynh_script_progression --message="Resetting the specific configuration of $name for the app $app..." --weight=3
|
||||||
|
|
||||||
|
if [ $type == nginx ]
|
||||||
|
then
|
||||||
|
(cd scripts; ynh_add_nginx_config)
|
||||||
|
|
||||||
|
if [ $multisite -eq 1 ]
|
||||||
|
then
|
||||||
|
ynh_replace_string --match_string="#--MULTISITE--" --replace_string="" --target_file=/etc/nginx/conf.d/$domain.d/$app.conf
|
||||||
|
|
||||||
|
ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
|
|
||||||
|
ynh_systemd_action --service_name=nginx --action=reload
|
||||||
|
fi
|
||||||
|
|
||||||
|
elif [ $type == phpfpm ]
|
||||||
|
then
|
||||||
|
# If the app is private, set the usage to low, otherwise to high.
|
||||||
|
if [ $is_public -eq 0 ]
|
||||||
|
then
|
||||||
|
usage=low
|
||||||
|
else
|
||||||
|
usage=high
|
||||||
|
fi
|
||||||
|
(cd scripts; ynh_add_fpm_config --usage=$usage --footprint=medium)
|
||||||
|
fi
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# END OF SCRIPT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_script_progression --message="Execution completed" --last
|
|
@ -77,4 +77,4 @@ ynh_backup "/etc/cron.d/$app"
|
||||||
# END OF SCRIPT
|
# 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_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --last
|
||||||
|
|
|
@ -33,7 +33,7 @@ admin_wordpress=$(ynh_app_setting_get --app=$app --key=admin)
|
||||||
#=================================================
|
#=================================================
|
||||||
# CHECK IF THE APP CAN BE RESTORED
|
# CHECK IF THE APP CAN BE RESTORED
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Validating restoration parameters..." --time --weight=1
|
ynh_script_progression --message="Validating restoration parameters..."
|
||||||
|
|
||||||
ynh_webpath_available --domain=$domain --path_url=$path_url \
|
ynh_webpath_available --domain=$domain --path_url=$path_url \
|
||||||
|| ynh_die --message="Path not available: ${domain}${path_url}"
|
|| ynh_die --message="Path not available: ${domain}${path_url}"
|
||||||
|
|
Loading…
Add table
Reference in a new issue