mirror of
https://github.com/YunoHost-Apps/discourse_ynh.git
synced 2024-09-03 18:26:18 +02:00
Use yh_maintenance_mode helpers
This commit is contained in:
parent
b07d0e459e
commit
f4b443a72e
2 changed files with 89 additions and 0 deletions
|
@ -574,3 +574,80 @@ ynh_clean_check_starting () {
|
||||||
kill -s 15 $pid_tail 2>&1
|
kill -s 15 $pid_tail 2>&1
|
||||||
ynh_secure_remove "$templog" 2>&1
|
ynh_secure_remove "$templog" 2>&1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ynh_maintenance_mode_ON () {
|
||||||
|
# Load value of $path_url and $domain from the config if their not set
|
||||||
|
if [ -z $path_url ]; then
|
||||||
|
path_url=$(ynh_app_setting_get $app path)
|
||||||
|
fi
|
||||||
|
if [ -z $domain ]; then
|
||||||
|
domain=$(ynh_app_setting_get $app domain)
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create an html to serve as maintenance notice
|
||||||
|
echo "<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="refresh" content="3">
|
||||||
|
<title>Your app $app is currently under maintenance!</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
width: 70em;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Your app $app is currently under maintenance!</h1>
|
||||||
|
<p>This app has been put under maintenance by your administrator at $(date)</p>
|
||||||
|
<p>Please wait until the maintenance operation is done. This page will be reloaded as soon as your app will be back.</p>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>" > "/var/www/html/maintenance.$app.html"
|
||||||
|
|
||||||
|
# Create a new nginx config file to redirect all access to the app to the maintenance notice instead.
|
||||||
|
echo "# All request to the app will be redirected to ${path_url}_maintenance and fall on the maintenance notice
|
||||||
|
rewrite ^${path_url}/(.*)$ ${path_url}_maintenance/? redirect;
|
||||||
|
# Use another location, to not be in conflict with the original config file
|
||||||
|
location ${path_url}_maintenance/ {
|
||||||
|
alias /var/www/html/ ;
|
||||||
|
|
||||||
|
try_files maintenance.$app.html =503;
|
||||||
|
|
||||||
|
# Include SSOWAT user panel.
|
||||||
|
include conf.d/yunohost_panel.conf.inc;
|
||||||
|
}" > "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf"
|
||||||
|
|
||||||
|
# The current config file will redirect all requests to the root of the app.
|
||||||
|
# To keep the full path, we can use the following rewrite rule:
|
||||||
|
# rewrite ^${path_url}/(.*)$ ${path_url}_maintenance/\$1? redirect;
|
||||||
|
# The difference will be in the $1 at the end, which keep the following queries.
|
||||||
|
# But, if it works perfectly for a html request, there's an issue with any php files.
|
||||||
|
# This files are treated as simple files, and will be downloaded by the browser.
|
||||||
|
# Would be really be nice to be able to fix that issue. So that, when the page is reloaded after the maintenance, the user will be redirected to the real page he was.
|
||||||
|
|
||||||
|
systemctl reload nginx
|
||||||
|
}
|
||||||
|
|
||||||
|
ynh_maintenance_mode_OFF () {
|
||||||
|
# Load value of $path_url and $domain from the config if their not set
|
||||||
|
if [ -z $path_url ]; then
|
||||||
|
path_url=$(ynh_app_setting_get $app path)
|
||||||
|
fi
|
||||||
|
if [ -z $domain ]; then
|
||||||
|
domain=$(ynh_app_setting_get $app domain)
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Rewrite the nginx config file to redirect from ${path_url}_maintenance to the real url of the app.
|
||||||
|
echo "rewrite ^${path_url}_maintenance/(.*)$ ${path_url}/\$1 redirect;" > "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf"
|
||||||
|
systemctl reload nginx
|
||||||
|
|
||||||
|
# Sleep 4 seconds to let the browser reload the pages and redirect the user to the app.
|
||||||
|
sleep 4
|
||||||
|
|
||||||
|
# Then remove the temporary files used for the maintenance.
|
||||||
|
rm "/var/www/html/maintenance.$app.html"
|
||||||
|
rm "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf"
|
||||||
|
|
||||||
|
systemctl reload nginx
|
||||||
|
}
|
||||||
|
|
|
@ -38,6 +38,12 @@ db_pwd=$(ynh_app_setting_get $app db_pwd)
|
||||||
# Check memory requirements
|
# Check memory requirements
|
||||||
check_memory_requirements_upgrade
|
check_memory_requirements_upgrade
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# ENABLE MAINTENANCE MODE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_maintenance_mode_ON
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# BACKUP BEFORE UPGRADE
|
# BACKUP BEFORE UPGRADE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -217,3 +223,9 @@ else
|
||||||
fi
|
fi
|
||||||
# Wait for discourse to be fully started
|
# Wait for discourse to be fully started
|
||||||
ynh_check_starting "INFO -- : worker=$((unicorn_workers-1)) ready" "$final_path/log/unicorn.stderr.log" "120" "$app"
|
ynh_check_starting "INFO -- : worker=$((unicorn_workers-1)) ready" "$final_path/log/unicorn.stderr.log" "120" "$app"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# DISABLE MAINTENANCE MODE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_maintenance_mode_OFF
|
||||||
|
|
Loading…
Add table
Reference in a new issue