2015-11-18 17:23:35 +01:00
|
|
|
#!/bin/bash
|
2017-02-04 19:14:21 +01:00
|
|
|
|
2017-10-11 12:13:37 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
2017-02-04 19:20:51 +01:00
|
|
|
source /usr/share/yunohost/helpers
|
2015-11-18 17:23:35 +01:00
|
|
|
|
2017-10-11 12:13:37 +02:00
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
2017-10-10 13:00:33 +02:00
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
2017-10-11 12:13:37 +02:00
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
|
|
|
|
2017-10-10 14:26:45 +02:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2018-01-30 07:42:16 +01:00
|
|
|
domain=$(ynh_app_setting_get $app domain)
|
2020-02-08 23:33:19 +01:00
|
|
|
path_url=$(ynh_app_setting_get $app path) # used during nginx configuration
|
2018-01-30 07:42:16 +01:00
|
|
|
is_public=$(ynh_app_setting_get $app is_public)
|
|
|
|
port=$(ynh_app_setting_get $app port)
|
2018-01-30 07:49:02 +01:00
|
|
|
mattermost_user="$app"
|
2015-11-18 17:23:35 +01:00
|
|
|
|
2016-04-17 18:35:42 +02:00
|
|
|
root_path="$(pwd)/.."
|
2017-10-12 12:47:51 +02:00
|
|
|
final_path="/var/www/$app"
|
|
|
|
data_path="/home/yunohost.app/$app"
|
2017-10-17 06:49:29 +02:00
|
|
|
logs_path="/var/log/$app"
|
2016-04-17 18:35:42 +02:00
|
|
|
|
2017-10-11 12:13:37 +02:00
|
|
|
#=================================================
|
2017-10-11 12:20:00 +02:00
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Backup the current version of the app
|
2018-02-05 06:06:50 +01:00
|
|
|
# (NB: `tee` uses process substitution rather than a pipe,
|
|
|
|
# to avoid spawning a subshell that would not save global
|
|
|
|
# variables defined by `ynh_backup_before_upgrade`.)
|
|
|
|
ynh_backup_before_upgrade > >(tee "upgrade.log")
|
|
|
|
# Ensure the backup can be restored
|
|
|
|
if grep -q "mattermost: Warning$" "upgrade.log"; then
|
|
|
|
can_restore_backup=false
|
|
|
|
else
|
|
|
|
can_restore_backup=true
|
|
|
|
fi
|
2017-10-12 12:47:51 +02:00
|
|
|
|
|
|
|
# If the upgrade fails…
|
2017-10-11 12:20:00 +02:00
|
|
|
ynh_clean_setup () {
|
2018-02-05 06:06:50 +01:00
|
|
|
if [ "$can_restore_backup" = true ]; then
|
|
|
|
# Stop attempting to restart the app
|
2020-02-09 00:27:51 +01:00
|
|
|
if $(systemctl -q is-active "$app"); then
|
|
|
|
systemctl stop "$app"
|
2018-02-05 06:06:50 +01:00
|
|
|
fi
|
|
|
|
# Restore the backup
|
|
|
|
ynh_restore_upgradebackup
|
2020-02-08 23:33:19 +01:00
|
|
|
|
2018-02-05 06:06:50 +01:00
|
|
|
else
|
|
|
|
# Backup restoration is not available:
|
|
|
|
# let's try at least to restart the server.
|
2020-02-09 00:27:51 +01:00
|
|
|
systemctl start "$app"
|
2017-10-12 12:47:51 +02:00
|
|
|
fi
|
2015-11-18 17:23:35 +01:00
|
|
|
}
|
2017-10-11 12:20:00 +02:00
|
|
|
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
2015-11-18 17:23:35 +01:00
|
|
|
|
2017-10-11 12:13:37 +02:00
|
|
|
#=================================================
|
|
|
|
# STOP SERVER
|
|
|
|
#=================================================
|
|
|
|
|
2017-10-12 12:47:51 +02:00
|
|
|
# Stop the server (if the app is already using systemd)
|
2020-02-09 00:27:51 +01:00
|
|
|
if $(systemctl -q is-active "$app"); then
|
|
|
|
systemctl stop "$app"
|
2017-10-12 12:47:51 +02:00
|
|
|
fi
|
|
|
|
|
2018-01-29 13:40:03 +01:00
|
|
|
# Legacy, for previous versions of this app which used supervisor
|
2017-10-12 12:47:51 +02:00
|
|
|
if [ -f "/etc/supervisor/conf.d/${app}.conf" ]; then
|
2020-02-09 00:27:51 +01:00
|
|
|
supervisorctl stop "$app"
|
|
|
|
rm -f "/etc/supervisor/conf.d/${app}.conf"
|
2017-10-12 12:47:51 +02:00
|
|
|
fi
|
2017-09-12 11:59:47 +02:00
|
|
|
|
2017-10-11 12:13:37 +02:00
|
|
|
#=================================================
|
|
|
|
# BACKUP CONFIGURATION FILE
|
|
|
|
#=================================================
|
|
|
|
|
2016-04-17 18:35:42 +02:00
|
|
|
config_file="$final_path/config/config.json"
|
|
|
|
backup_config_file="/tmp/config.json"
|
|
|
|
|
2020-02-09 00:27:51 +01:00
|
|
|
cp -f "$config_file" "$backup_config_file"
|
2015-11-18 17:23:35 +01:00
|
|
|
|
2018-01-29 08:19:04 +01:00
|
|
|
#=================================================
|
|
|
|
# MIGRATE SETTINGS FROM PREVIOUS VERSIONS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Convert is_public from "Yes"/"No" to 1 / 0
|
|
|
|
if [[ $is_public == "Yes" ]]; then
|
|
|
|
is_public=1
|
|
|
|
elif [[ $is_public == "No" ]]; then
|
|
|
|
is_public=0
|
|
|
|
fi
|
|
|
|
ynh_app_setting_set "$app" is_public "$is_public"
|
|
|
|
|
2018-01-29 13:40:03 +01:00
|
|
|
# Save the port used if not present
|
|
|
|
if ! [[ "$port" ]]; then
|
|
|
|
port=8065
|
|
|
|
ynh_app_setting_set "$app" port "$port"
|
|
|
|
fi
|
|
|
|
|
2017-10-11 12:13:37 +02:00
|
|
|
#=================================================
|
2017-10-23 08:51:53 +02:00
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
2017-10-11 12:13:37 +02:00
|
|
|
#=================================================
|
|
|
|
|
2017-10-23 08:51:53 +02:00
|
|
|
ynh_app_setting_set "$app" final_path "$final_path"
|
|
|
|
ynh_setup_source "$final_path"
|
2015-11-18 17:23:35 +01:00
|
|
|
|
2017-10-11 12:13:37 +02:00
|
|
|
#=================================================
|
|
|
|
# RESTORE CONFIGURATION FILE
|
|
|
|
#=================================================
|
|
|
|
|
2020-02-09 00:27:51 +01:00
|
|
|
cp -f "$backup_config_file" "$config_file"
|
2015-11-18 17:23:35 +01:00
|
|
|
|
2017-10-12 12:47:51 +02:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SYSTEMD CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
2018-02-16 05:13:55 +01:00
|
|
|
ynh_add_systemd_config
|
2017-10-12 12:47:51 +02:00
|
|
|
|
2017-10-12 14:51:54 +02:00
|
|
|
#=================================================
|
|
|
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
|
|
|
#=================================================
|
|
|
|
|
2020-02-09 00:27:51 +01:00
|
|
|
yunohost service add "$app" --log "$logs_path/mattermost.log"
|
2017-10-12 14:51:54 +02:00
|
|
|
|
2017-10-11 12:13:37 +02:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
|
2017-10-10 13:34:43 +02:00
|
|
|
# Fix log FileLocation path (changed in Mattermost 3.8, makes Mattermost >= 4.2 crash)
|
|
|
|
# https://docs.mattermost.com/administration/changelog.html#release-v3-8-3
|
2020-02-09 00:27:51 +01:00
|
|
|
sed -i "s|\"FileLocation\": \"/var/log/mattermost.log\"|\"FileLocation\": \"/var/log\"|g" "$config_file"
|
2017-10-10 13:34:43 +02:00
|
|
|
|
2017-10-17 06:49:29 +02:00
|
|
|
# Move log files to a directory (rather than directly in /var/log)
|
|
|
|
# See https://github.com/YunoHost-Apps/mattermost_ynh/issues/61
|
2020-02-09 00:27:51 +01:00
|
|
|
mkdir -p "$logs_path"
|
|
|
|
sed -i "s|\"FileLocation\": \"/var/log\"|\"FileLocation\": \"$logs_path\"|g" "$config_file"
|
2017-10-17 06:49:29 +02:00
|
|
|
if [ -f "/var/log/${app}.log" ]; then
|
2020-02-09 00:27:51 +01:00
|
|
|
mv "/var/log/${app}.log" "$logs_path/"
|
2017-10-17 06:49:29 +02:00
|
|
|
fi
|
|
|
|
|
2017-10-11 12:13:37 +02:00
|
|
|
#=================================================
|
|
|
|
# RESTORE FILE PERMISSIONS
|
|
|
|
#=================================================
|
|
|
|
|
2020-02-09 00:27:51 +01:00
|
|
|
chown -R "$mattermost_user:www-data" "$final_path"
|
|
|
|
chown -R "$mattermost_user:www-data" "$data_path"
|
|
|
|
chown -R "$mattermost_user:adm" "$logs_path"
|
2015-11-18 17:23:35 +01:00
|
|
|
|
2017-10-11 12:13:37 +02:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
|
|
|
|
2020-02-09 00:27:51 +01:00
|
|
|
service nginx reload
|
2017-10-11 12:13:37 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SERVER
|
|
|
|
#=================================================
|
2017-07-21 22:08:33 +02:00
|
|
|
|
2020-02-09 00:27:51 +01:00
|
|
|
systemctl start "$app"
|