1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/mattermost_ynh.git synced 2024-09-03 19:36:29 +02:00

scripts: support multi-instance install

This commit is contained in:
Pierre de La Morinerie 2018-01-30 06:42:16 +00:00
parent 0918978e92
commit 256cafcb07
6 changed files with 30 additions and 26 deletions

View file

@ -13,7 +13,7 @@
setup_public=1 setup_public=1
upgrade=1 upgrade=1
backup_restore=1 backup_restore=1
multi_instance=0 multi_instance=1
port_already_use=1 (8085) port_already_use=1 (8085)
# Checks not supported yet # Checks not supported yet
change_url=0 change_url=0

View file

@ -13,7 +13,7 @@
"name": "pmorinerie", "name": "pmorinerie",
"email": "kemenaran@gmail.com" "email": "kemenaran@gmail.com"
}, },
"multi_instance": false, "multi_instance": true,
"services": [ "services": [
"nginx" "nginx"
], ],

View file

@ -91,19 +91,20 @@ logs_path="/var/log/$app"
# CREATE A MYSQL DATABASE # CREATE A MYSQL DATABASE
#================================================= #=================================================
db_name="mattermost" db_name="$app"
db_user="mmuser" db_user="mmuser"
db_password=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p') db_password=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p')
ynh_mysql_create_db $db_name $db_user $db_password ynh_mysql_create_db "$db_name" "$db_user" "$db_password"
ynh_app_setting_set mattermost mysqlpwd "$db_password" ynh_app_setting_set "$app" mysqlpwd "$db_password"
#================================================= #=================================================
# CREATE USER FOR EMAIL NOTIFICATIONS # CREATE USER FOR EMAIL NOTIFICATIONS
#================================================= #=================================================
smtp_user="$app"
smtp_password=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p') smtp_password=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p')
sudo useradd -M --shell /bin/false -p $(openssl passwd -1 "$smtp_password") "mattermost" sudo useradd -M --shell /bin/false -p $(openssl passwd -1 "$smtp_password") "$smtp_user"
ynh_app_setting_set mattermost smtppwd "$smtp_password" ynh_app_setting_set "$app" smtppwd "$smtp_password"
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
@ -131,7 +132,7 @@ sudo sed -i "s|\"Directory\": \"./data/\"|\"Directory\": \"${data_path}/\"|g"
sudo sed -i "s|\"SendEmailNotifications\": false|\"SendEmailNotifications\": true|g" $final_path/config/config.json sudo sed -i "s|\"SendEmailNotifications\": false|\"SendEmailNotifications\": true|g" $final_path/config/config.json
sudo sed -i "s|\"FeedbackName\": \"\"|\"FeedbackName\": \"Mattermost notification\"|g" $final_path/config/config.json sudo sed -i "s|\"FeedbackName\": \"\"|\"FeedbackName\": \"Mattermost notification\"|g" $final_path/config/config.json
sudo sed -i "s|\"FeedbackEmail\": \"\"|\"FeedbackEmail\": \"no-reply@${domain}\"|g" $final_path/config/config.json sudo sed -i "s|\"FeedbackEmail\": \"\"|\"FeedbackEmail\": \"no-reply@${domain}\"|g" $final_path/config/config.json
sudo sed -i "s|\"SMTPUsername\": \"\"|\"SMTPUsername\": \"mattermost\"|g" $final_path/config/config.json sudo sed -i "s|\"SMTPUsername\": \"\"|\"SMTPUsername\": \"${smtp_user}\"|g" $final_path/config/config.json
sudo sed -i "s|\"SMTPPassword\": \"\"|\"SMTPPassword\": \"${smtp_password}\"|g" $final_path/config/config.json sudo sed -i "s|\"SMTPPassword\": \"\"|\"SMTPPassword\": \"${smtp_password}\"|g" $final_path/config/config.json
sudo sed -i "s|\"SMTPServer\": \"\"|\"SMTPServer\": \"localhost\"|g" $final_path/config/config.json sudo sed -i "s|\"SMTPServer\": \"\"|\"SMTPServer\": \"localhost\"|g" $final_path/config/config.json
sudo sed -i "s|\"SMTPPort\": \"\"|\"SMTPPort\": \"25\"|g" $final_path/config/config.json sudo sed -i "s|\"SMTPPort\": \"\"|\"SMTPPort\": \"25\"|g" $final_path/config/config.json
@ -149,9 +150,9 @@ ynh_app_setting_set "$app" analytics "$analytics"
# SECURE FILES AND DIRECTORIES # SECURE FILES AND DIRECTORIES
#================================================= #=================================================
sudo chown -R mattermost:www-data "$final_path" sudo chown -R "$smtp_user:www-data" "$final_path"
sudo chown -R mattermost:www-data "$data_path" sudo chown -R "$smtp_user:www-data" "$data_path"
sudo chown -R mattermost:adm "$logs_path" sudo chown -R "$smtp_user:adm" "$logs_path"
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
@ -192,4 +193,4 @@ sudo systemctl reload nginx
# START SERVER # START SERVER
#================================================= #=================================================
sudo systemctl start mattermost sudo systemctl start "$app"

View file

@ -14,9 +14,10 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get mattermost domain) domain=$(ynh_app_setting_get $app domain)
db_name="mattermost" db_name="$app"
db_user="mmuser" db_user="mmuser"
smtp_user="$app"
final_path="/var/www/$app" final_path="/var/www/$app"
data_path="/home/yunohost.app/$app" data_path="/home/yunohost.app/$app"
logs_path="/var/log/$app" logs_path="/var/log/$app"
@ -76,4 +77,4 @@ sudo rm -rf "$logs_path"
# REMOVE DEDICATED USER # REMOVE DEDICATED USER
#================================================= #=================================================
ynh_system_user_delete "$app" ynh_system_user_delete "$smtp_user"

View file

@ -27,6 +27,7 @@ data_path="/home/yunohost.app/$app"
logs_path="/var/log/$app" logs_path="/var/log/$app"
db_name="$app" db_name="$app"
db_user="mmuser" db_user="mmuser"
smtp_user="$app"
#================================================= #=================================================
# CHECK IF THE APP CAN BE RESTORED # CHECK IF THE APP CAN BE RESTORED
@ -62,8 +63,8 @@ ynh_restore_file "$data_path"
#================================================= #=================================================
db_pwd=$(ynh_app_setting_get $app mysqlpwd) db_pwd=$(ynh_app_setting_get $app mysqlpwd)
ynh_mysql_setup_db $db_user $db_name $db_pwd ynh_mysql_setup_db "$db_user" "$db_name" "$db_pwd"
ynh_mysql_connect_as $db_user $db_pwd $db_name < ./db.sql ynh_mysql_connect_as "$db_user" "$db_pwd" "$db_name" < ./db.sql
#================================================= #=================================================
# RECREATE THE DEDICATED USER # RECREATE THE DEDICATED USER
@ -81,13 +82,13 @@ fi
#================================================= #=================================================
# Restore permissions on app files # Restore permissions on app files
sudo chown -R mattermost:www-data "$final_path" sudo chown -R "$smtp_user:www-data" "$final_path"
mkdir -p "$data_path" mkdir -p "$data_path"
sudo chown -R mattermost:www-data "$data_path" sudo chown -R "$smtp_user:www-data" "$data_path"
mkdir -p "$logs_path" mkdir -p "$logs_path"
sudo chown -R mattermost:adm "$logs_path" sudo chown -R "$smtp_user:adm" "$logs_path"
#================================================= #=================================================
# RESTORE SSOWAT # RESTORE SSOWAT

View file

@ -21,9 +21,10 @@ ynh_abort_if_errors
#================================================= #=================================================
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get mattermost domain) domain=$(ynh_app_setting_get $app domain)
is_public=$(ynh_app_setting_get mattermost is_public) is_public=$(ynh_app_setting_get $app is_public)
port=$(ynh_app_setting_get mattermost port) port=$(ynh_app_setting_get $app port)
smtp_user="$app"
root_path="$(pwd)/.." root_path="$(pwd)/.."
final_path="/var/www/$app" final_path="/var/www/$app"
@ -143,9 +144,9 @@ fi
# RESTORE FILE PERMISSIONS # RESTORE FILE PERMISSIONS
#================================================= #=================================================
sudo chown -R mattermost:www-data "$final_path" sudo chown -R "$smtp_user:www-data" "$final_path"
sudo chown -R mattermost:www-data "$data_path" sudo chown -R "$smtp_user:www-data" "$data_path"
sudo chown -R mattermost:adm "$logs_path" sudo chown -R "$smtp_user:adm" "$logs_path"
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX