mirror of
https://github.com/YunoHost-Apps/mattermost_ynh.git
synced 2024-09-03 19:36:29 +02:00
140 lines
4.2 KiB
Bash
140 lines
4.2 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# MANAGE SCRIPT FAILURE
|
|
#=================================================
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
domain=$(ynh_app_setting_get mattermost domain)
|
|
is_public=$(ynh_app_setting_get mattermost is_public)
|
|
|
|
root_path="$(pwd)/.."
|
|
final_path="/var/www/$app"
|
|
data_path="/home/yunohost.app/$app"
|
|
logs_path="/var/log/$app"
|
|
|
|
#=================================================
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
#=================================================
|
|
|
|
# Backup the current version of the app
|
|
ynh_backup_before_upgrade
|
|
|
|
# If the upgrade fails…
|
|
ynh_clean_setup () {
|
|
# Stop attempting to restart the app
|
|
if $(sudo systemctl -q is-active "$app"); then
|
|
sudo systemctl stop "$app"
|
|
fi
|
|
# Restore the backup
|
|
ynh_restore_upgradebackup
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# STOP SERVER
|
|
#=================================================
|
|
|
|
# Stop the server (if the app is already using systemd)
|
|
if $(sudo systemctl -q is-active "$app"); then
|
|
sudo systemctl stop "$app"
|
|
fi
|
|
|
|
# Legacy, for older versions of this app which used supervisor
|
|
if [ -f "/etc/supervisor/conf.d/${app}.conf" ]; then
|
|
sudo supervisorctl stop "$app"
|
|
sudo rm -f "/etc/supervisor/conf.d/${app}.conf"
|
|
fi
|
|
|
|
#=================================================
|
|
# BACKUP CONFIGURATION FILE
|
|
#=================================================
|
|
|
|
config_file="$final_path/config/config.json"
|
|
backup_config_file="/tmp/config.json"
|
|
|
|
sudo cp -f "$config_file" "$backup_config_file"
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
|
|
ynh_app_setting_set "$app" final_path "$final_path"
|
|
ynh_setup_source "$final_path"
|
|
|
|
#=================================================
|
|
# RESTORE CONFIGURATION FILE
|
|
#=================================================
|
|
|
|
sudo cp -f "$backup_config_file" "$config_file"
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
|
|
ynh_add_nginx_config
|
|
|
|
#=================================================
|
|
# SYSTEMD CONFIGURATION
|
|
#=================================================
|
|
|
|
ynh_add_systemd_config
|
|
|
|
#=================================================
|
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
|
#=================================================
|
|
|
|
sudo yunohost service add "$app" --log "$logs_path/mattermost.log"
|
|
|
|
#=================================================
|
|
# SPECIFIC UPGRADE STEPS
|
|
#=================================================
|
|
|
|
# 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
|
|
sudo sed -i "s|\"FileLocation\": \"/var/log/mattermost.log\"|\"FileLocation\": \"/var/log\"|g" "$config_file"
|
|
|
|
# Move log files to a directory (rather than directly in /var/log)
|
|
# See https://github.com/YunoHost-Apps/mattermost_ynh/issues/61
|
|
sudo mkdir -p "$logs_path"
|
|
sudo sed -i "s|\"FileLocation\": \"/var/log\"|\"FileLocation\": \"$logs_path\"|g" "$config_file"
|
|
if [ -f "/var/log/${app}.log" ]; then
|
|
sudo mv "/var/log/${app}.log" "$logs_path/"
|
|
fi
|
|
|
|
#=================================================
|
|
# RESTORE FILE PERMISSIONS
|
|
#=================================================
|
|
|
|
sudo chown -R mattermost:www-data "$final_path"
|
|
sudo chown -R mattermost:www-data "$data_path"
|
|
sudo chown -R mattermost:adm "$logs_path"
|
|
|
|
#=================================================
|
|
# RELOAD NGINX
|
|
#=================================================
|
|
|
|
sudo service nginx reload
|
|
|
|
#=================================================
|
|
# START SERVER
|
|
#=================================================
|
|
|
|
sudo systemctl start "$app"
|