1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/rocketchat_ynh.git synced 2024-09-03 20:16:25 +02:00
This commit is contained in:
Éric Gaspar 2024-08-29 15:01:46 +02:00
parent b5eb751a7f
commit be565011a2
10 changed files with 131 additions and 186 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
*~
*.sw[op]
.DS_Store

View file

@ -8,8 +8,8 @@ User=__APP__
Group=__APP__ Group=__APP__
Environment="NODE_ENV=production" Environment="NODE_ENV=production"
WorkingDirectory=__INSTALL_DIR__/ WorkingDirectory=__INSTALL_DIR__/
Environment="__YNH_NODE_LOAD_PATH__" Environment="PATH=__PATH_WITH_NODEJS__"
ExecStart=__YNH_NODE__ __INSTALL_DIR__/main.js ExecStart=__NODEJS_DIR__/node __INSTALL_DIR__/main.js
SyslogIdentifier=__APP__ SyslogIdentifier=__APP__
Environment=MONGO_URL=mongodb://localhost:27017/__APP__?replicaSet=rs01 Environment=MONGO_URL=mongodb://localhost:27017/__APP__?replicaSet=rs01
Environment=MONGO_OPLOG_URL=mongodb://localhost:27017/local?replicaSet=rs01 Environment=MONGO_OPLOG_URL=mongodb://localhost:27017/local?replicaSet=rs01

View file

@ -18,7 +18,8 @@ userdoc = "https://docs.rocket.chat/guides/user-guides"
code = "https://github.com/RocketChat/Rocket.Chat" code = "https://github.com/RocketChat/Rocket.Chat"
[integration] [integration]
yunohost = ">= 11.2.27" yunohost = ">= 11.2.18"
helpers_version = "2.1"
architectures = ["amd64"] architectures = ["amd64"]
multi_instance = true multi_instance = true

View file

@ -1,18 +1,9 @@
#!/bin/bash #!/bin/bash
#================================================= #=================================================
# COMMON VARIABLES # COMMON VARIABLES AND CUSTOM HELPERS
#================================================= #=================================================
nodejs_version=14 nodejs_version=14
mongo_version=6.0 mongo_version=6.0
#=================================================
# PERSONAL HELPERS
#=================================================
#=================================================
# EXPERIMENTAL HELPERS
#=================================================

View file

@ -1,45 +1,36 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= ynh_print_info "Declaring files to be backed up..."
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
ynh_print_info --message="Declaring files to be backed up..."
#================================================= #=================================================
# BACKUP THE APP MAIN DIR # BACKUP THE APP MAIN DIR
#================================================= #=================================================
ynh_backup --src_path="$install_dir" ynh_backup "$install_dir"
#================================================= #=================================================
# SYSTEM CONFIGURATION # SYSTEM CONFIGURATION
#================================================= #=================================================
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup --src_path="/etc/logrotate.d/$app" ynh_backup "/etc/logrotate.d/$app"
ynh_backup --src_path="/etc/systemd/system/$app.service" ynh_backup "/etc/systemd/system/$app.service"
#================================================= #=================================================
# BACKUP THE MONGODB DATABASE # BACKUP THE MONGODB DATABASE
#================================================= #=================================================
ynh_print_info --message="Backing up the MongoDB database..." ynh_print_info "Backing up the MongoDB database..."
ynh_mongo_dump_db --database="$db_name" > ./dump.bson ynh_mongo_dump_db > ./dump.bson
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

View file

@ -1,49 +1,39 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#=================================================
# STANDARD MODIFICATIONS
#================================================= #=================================================
# STOP SYSTEMD SERVICE # STOP SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1 ynh_script_progression "Stopping $app's systemd service..."
ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" ynh_systemctl --service=$app --action="stop" --log_path="systemd"
#================================================= #=================================================
# MODIFY URL IN NGINX CONF # MODIFY URL IN NGINX CONF
#================================================= #=================================================
ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1 ynh_script_progression "Updating NGINX web server configuration..."
ynh_change_url_nginx_config ynh_config_change_url_nginx
#================================================= #=================================================
# SPECIFIC MODIFICATIONS # SPECIFIC MODIFICATIONS
#================================================= #=================================================
ynh_script_progression --message="Updating systemd service..." --weight=1 ynh_script_progression "Updating systemd service..."
ynh_replace_string --match_string="Environment=ROOT_URL=https://$old_domain" --replace_string="Environment=ROOT_URL=https://$new_domain" --target_file="/etc/systemd/system/$app.service" ynh_replace --match="Environment=ROOT_URL=https://$old_domain" --replace="Environment=ROOT_URL=https://$new_domain" --file="/etc/systemd/system/$app.service"
systemctl daemon-reload systemctl daemon-reload
#=================================================
# GENERIC FINALISATION
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=16 ynh_script_progression "Starting $app's systemd service..."
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="SERVER RUNNING" ynh_systemctl --service=$app --action="start" --log_path="systemd" --wait_until="SERVER RUNNING"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Change of URL completed for $app" --last ynh_script_progression "Change of URL completed for $app"

View file

@ -1,11 +1,5 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
@ -20,39 +14,39 @@ email=$(ynh_user_get_info --username=$admin --key=mail)
# STORE SETTINGS FROM MANIFEST # STORE SETTINGS FROM MANIFEST
#================================================= #=================================================
ynh_app_setting_set --app=$app --key=password --value="$password" ynh_app_setting_set --key=password --value="$password"
ynh_app_setting_set --app=$app --key=email --value=$email ynh_app_setting_set --key=email --value=$email
#================================================= #=================================================
# INSTALL DEPENDENCIES # INSTALL DEPENDENCIES
#================================================= #=================================================
ynh_script_progression --message="Installing dependencies..." --weight=48 ynh_script_progression "Installing dependencies..."
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version ynh_nodejs_install
ynh_exec_warn_less ynh_install_mongo --mongo_version=$mongo_version ynh_hide_warnings ynh_install_mongo
#================================================= #=================================================
# CREATE A MONGODB DATABASE # CREATE A MONGODB DATABASE
#================================================= #=================================================
ynh_script_progression --message="Creating a MongoDB database..." --weight=5 ynh_script_progression "Creating a MongoDB database..."
db_name=$(ynh_sanitize_dbid --db_name=$app) db_name=$(ynh_sanitize_dbid --db_name=$app)
db_user=$db_name db_user=$db_name
ynh_app_setting_set --app=$app --key=db_name --value=$db_name ynh_app_setting_set --key=db_name --value=$db_name
ynh_mongo_setup_db --db_user=$db_user --db_name=$db_name ynh_mongo_setup_db --db_user=$db_user --db_name=$db_name
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
ynh_script_progression --message="Setting up source files..." --weight=10 ynh_script_progression "Setting up source files..."
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir" ynh_setup_source --dest_dir="$install_dir"
mkdir "/tmp/ufs" mkdir "/tmp/ufs"
chmod -R o-rwx "$install_dir" #REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir"
chown -R $app:$app "$install_dir" #REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:$app "$install_dir"
chown -R $app:$app "/tmp/ufs" chown -R $app:$app "/tmp/ufs"
#================================================= #=================================================
@ -60,52 +54,52 @@ chown -R $app:$app "/tmp/ufs"
#================================================= #=================================================
# CONFIGURE MONGOD # CONFIGURE MONGOD
#================================================= #=================================================
ynh_script_progression --message="Configuring MongoDB..." --weight=10 ynh_script_progression "Configuring MongoDB..."
ynh_replace_string --match_string="# engine:" --replace_string=" engine: wiredTiger" --target_file="/etc/mongod.conf" ynh_replace --match="# engine:" --replace=" engine: wiredTiger" --file="/etc/mongod.conf"
ynh_replace_string --match_string="#replication:" --replace_string="replication:\n replSetName: rs01" --target_file="/etc/mongod.conf" ynh_replace --match="#replication:" --replace="replication:\n replSetName: rs01" --file="/etc/mongod.conf"
ynh_exec_warn_less systemctl enable mongod --quiet ynh_hide_warnings systemctl enable mongod --quiet
ynh_systemd_action --service_name=mongod --action=restart --log_path=/var/log/mongodb/mongod.log --line_match="Waiting for connections" ynh_systemctl --service=mongod --action=restart --log_path=/var/log/mongodb/mongod.log --wait_until="Waiting for connections"
if ynh_exec_warn_less ynh_mongo_exec --command="printjson(rs.status())" | grep -q "no replset config has been received"; then if ynh_hide_warnings ynh_mongo_exec --command="printjson(rs.status())" | grep -q "no replset config has been received"; then
ynh_exec_warn_less ynh_mongo_exec --command="printjson(rs.initiate())" --eval ynh_hide_warnings ynh_mongo_exec --command="printjson(rs.initiate())"
fi fi
#================================================= #=================================================
# SYSTEM CONFIGURATION # SYSTEM CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 ynh_script_progression "Adding system configurations related to $app..."
# Create a dedicated NGINX config # Create a dedicated NGINX config
ynh_add_nginx_config ynh_config_add_nginx
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_add_systemd_config ynh_config_add_systemd
# Use logrotate to manage application logfile(s) # Use logrotate to manage application logfile(s)
ynh_use_logrotate ynh_config_add_logrotate
yunohost service add $app --description="Team collaboration communication platform" --log="/var/log/$app/$app.log" yunohost service add $app --description="Team collaboration communication platform" --log="/var/log/$app/$app.log"
#============================================== #==============================================
# INSTALL ROCKETCHAT # INSTALL ROCKETCHAT
#============================================== #==============================================
ynh_script_progression --message="Building $app... (this will take some time and resources!)" --weight=29 ynh_script_progression "Building $app... (this will take some time and resources!)"
pushd $install_dir/programs/server pushd $install_dir/programs/server
ynh_use_nodejs
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn install --unsafe-perm ynh_hide_warnings ynh_exec_as_app node_load_PATH yarn install --unsafe-perm
popd popd
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=29 ynh_script_progression "Starting $app's systemd service..."
ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="SERVER RUNNING" ynh_systemctl --service=$app --action="start" --log_path=systemd --wait_until="SERVER RUNNING"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Installation of $app completed" --last ynh_script_progression "Installation of $app completed"

View file

@ -1,72 +1,67 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1 ynh_script_progression "Loading installation settings..."
db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_name=$(ynh_app_setting_get --key=db_name)
db_user=$db_name db_user=$db_name
#================================================= #=================================================
# REMOVE SYSTEM CONFIGURATIONS # REMOVE SYSTEM CONFIGURATIONS
#================================================= #=================================================
# REMOVE SYSTEMD SERVICE # REMOVE SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 ynh_script_progression "Removing system configurations related to $app..."
# Remove the service from the list of services known by YunoHost (added from `yunohost service add`) # Remove the service from the list of services known by YunoHost (added from `yunohost service add`)
if ynh_exec_warn_less yunohost service status $app >/dev/null if ynh_hide_warnings yunohost service status $app >/dev/null
then then
ynh_script_progression --message="Removing $app service integration..." --weight=1 ynh_script_progression "Removing $app service integration..."
yunohost service remove $app yunohost service remove $app
fi fi
# Remove the dedicated systemd config # Remove the dedicated systemd config
ynh_remove_systemd_config ynh_config_remove_systemd
# Remove the app-specific logrotate config # Remove the app-specific logrotate config
ynh_remove_logrotate ynh_config_remove_logrotate
if [ -d "/tmp/ufs" ]; then if [ -d "/tmp/ufs" ]; then
ynh_secure_remove --file="/tmp/ufs" ynh_safe_rm "/tmp/ufs"
fi fi
# Remove the dedicated NGINX config # Remove the dedicated NGINX config
ynh_remove_nginx_config ynh_config_remove_nginx
# Remove metapackage and its dependencies # Remove metapackage and its dependencies
ynh_remove_nodejs ynh_nodejs_remove
#================================================= #=================================================
# REMOVE THE MONGODB DATABASE # REMOVE THE MONGODB DATABASE
#================================================= #=================================================
ynh_script_progression --message="Removing the MongoDB database..." --weight=11 ynh_script_progression "Removing the MongoDB database..."
ynh_replace_string --match_string="engine: wiredTiger" --replace_string="# engine:" --target_file="/etc/mongod.conf" ynh_replace --match="engine: wiredTiger" --replace="# engine:" --file="/etc/mongod.conf"
ynh_replace_string --match_string="replication:" --replace_string="#replication:" --target_file="/etc/mongod.conf" ynh_replace --match="replication:" --replace="#replication:" --file="/etc/mongod.conf"
ynh_replace_string --match_string=" replSetName: rs01" --replace_string="" --target_file="/etc/mongod.conf" ynh_replace --match=" replSetName: rs01" --replace="" --file="/etc/mongod.conf"
ynh_systemd_action --service_name=mongod --action=restart --log_path=/var/log/mongodb/mongod.log --line_match="Waiting for connections" ynh_systemctl --service=mongod --action=restart --log_path=/var/log/mongodb/mongod.log --wait_until="Waiting for connections"
# Remove a database if it exists, along with the associated user # Remove a database if it exists, along with the associated user
ynh_mongo_remove_db --db_user=$db_user --db_name=$db_name ynh_mongo_remove_db --db_user=$db_user --db_name=$db_name
# Remove mongod service # Remove mongod service
yunohost service remove mongod yunohost service remove mongod
ynh_secure_remove --file="/var/lib/mongodb" ynh_safe_rm "/var/lib/mongodb"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Removal of $app completed" --last ynh_script_progression "Removal of $app completed"

View file

@ -1,11 +1,5 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
@ -13,54 +7,53 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1 ynh_script_progression "Loading installation settings..."
db_user=$db_name db_user=$db_name
mongo_version=$(ynh_app_setting_get --app=$app --key=mongo_version) mongo_version=$(ynh_app_setting_get --key=mongo_version)
#================================================= #=================================================
# RESTORE THE APP MAIN DIR # RESTORE THE APP MAIN DIR
#================================================= #=================================================
ynh_script_progression --message="Restoring the app main directory..." --weight=1 ynh_script_progression "Restoring the app main directory..."
ynh_restore_file --origin_path="$install_dir" ynh_restore "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:$app "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:$app "$install_dir"
#================================================= #=================================================
# SPECIFIC RESTORATION # SPECIFIC RESTORATION
#================================================= #=================================================
# REINSTALL DEPENDENCIES # REINSTALL DEPENDENCIES
#================================================= #=================================================
ynh_script_progression --message="Reinstalling dependencies..." --weight=40 ynh_script_progression "Reinstalling dependencies..."
# Define and install dependencies # Define and install dependencies
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version ynh_nodejs_install
ynh_exec_warn_less ynh_install_mongo --mongo_version=$mongo_version ynh_hide_warnings ynh_install_mongo
#================================================= #=================================================
# RESTORE THE MONGODB DATABASE # RESTORE THE MONGODB DATABASE
#================================================= #=================================================
ynh_script_progression --message="Restoring the MongoDB database..." --weight=10 ynh_script_progression "Restoring the MongoDB database..."
db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) db_pwd=$(ynh_app_setting_get --key=db_pwd)
ynh_mongo_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd ynh_mongo_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_mongo_restore_db --database="$db_name" < ./dump.bson ynh_mongo_restore_db < ./dump.bson
#================================================= #=================================================
# CONFIGURE MONGOD # CONFIGURE MONGOD
#================================================= #=================================================
ynh_script_progression --message="Configuring mongod..." --weight=7 ynh_script_progression "Configuring mongod..."
ynh_replace_string --match_string="# engine:" --replace_string=" engine: wiredTiger" --target_file="/etc/mongod.conf" ynh_replace --match="# engine:" --replace=" engine: wiredTiger" --file="/etc/mongod.conf"
ynh_replace_string --match_string="#replication:" --replace_string="replication:\n replSetName: rs01" --target_file="/etc/mongod.conf" ynh_replace --match="#replication:" --replace="replication:\n replSetName: rs01" --file="/etc/mongod.conf"
ynh_exec_warn_less systemctl enable mongod --quiet ynh_hide_warnings systemctl enable mongod --quiet
ynh_systemd_action --service_name=mongod --action=restart --log_path=/var/log/mongodb/mongod.log --line_match="Waiting for connections" ynh_systemctl --service=mongod --action=restart --log_path=/var/log/mongodb/mongod.log --wait_until="Waiting for connections"
if ynh_exec_warn_less ynh_mongo_exec --command="printjson(rs.status())" | grep -q "no replset config has been received"; then if ynh_hide_warnings ynh_mongo_exec --command="printjson(rs.status())" | grep -q "no replset config has been received"; then
ynh_exec_warn_less ynh_mongo_exec --command="printjson(rs.initiate())" --eval ynh_hide_warnings ynh_mongo_exec --command="printjson(rs.initiate())"
fi fi
#================================================= #=================================================
@ -68,30 +61,28 @@ fi
#================================================= #=================================================
# RESTORE THE PHP-FPM CONFIGURATION # RESTORE THE PHP-FPM CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 ynh_script_progression "Restoring system configurations related to $app..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_restore_file --origin_path="/etc/systemd/system/$app.service" ynh_restore "/etc/systemd/system/$app.service"
systemctl enable $app.service --quiet systemctl enable $app.service --quiet
ynh_restore_file --origin_path="/etc/logrotate.d/$app" ynh_restore "/etc/logrotate.d/$app"
yunohost service add $app --description="Team collaboration communication platform" --log="/var/log/$app/$app.log" yunohost service add $app --description="Team collaboration communication platform" --log="/var/log/$app/$app.log"
#=================================================
# GENERIC FINALIZATION
#================================================= #=================================================
# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE # RELOAD NGINX AND PHP-FPM OR THE APP SERVICE
#================================================= #=================================================
ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1 ynh_script_progression "Reloading NGINX web server and $app's service..."
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="SERVER RUNNING" ynh_systemctl --service=$app --action="start" --log_path="systemd" --wait_until="SERVER RUNNING"
ynh_systemd_action --service_name=nginx --action=reload ynh_systemctl --service=nginx --action=reload
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Restoration completed for $app" --last ynh_script_progression "Restoration completed for $app"

View file

@ -1,115 +1,104 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1 ynh_script_progression "Loading installation settings..."
db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_name=$(ynh_app_setting_get --key=db_name)
password=$(ynh_app_setting_get --app=$app --key=password) password=$(ynh_app_setting_get --key=password)
email=$(ynh_app_setting_get --app=$app --key=email) email=$(ynh_app_setting_get --key=email)
mongo_version=$(ynh_app_setting_get --app=$app --key=mongo_version) mongo_version=$(ynh_app_setting_get --key=mongo_version)
#=================================================
# STANDARD UPGRADE STEPS
#================================================= #=================================================
# STOP SYSTEMD SERVICE # STOP SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1 ynh_script_progression "Stopping $app's systemd service..."
ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" ynh_systemctl --service=$app --action="stop" --log_path="systemd"
#================================================= #=================================================
# ENSURE DOWNWARD COMPATIBILITY # ENSURE DOWNWARD COMPATIBILITY
#================================================= #=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 ynh_script_progression "Ensuring downward compatibility..."
# If mongo_version doesn't exist, create it # If mongo_version doesn't exist, create it
if [ -z "$mongo_version" ]; then if [ -z "$mongo_version" ]; then
mongo_version="$(mongod --version | grep -oP 'db version v\K.{0,3}')" mongo_version="$(mongod --version | grep -oP 'db version v\K.{0,3}')"
ynh_app_setting_set --app=$app --key=mongo_version --value=$mongo_version ynh_app_setting_set --key=mongo_version --value=$mongo_version
fi fi
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
ynh_script_progression --message="Upgrading source files..." --weight=22 ynh_script_progression "Upgrading source files..."
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir" --full_replace=1 ynh_setup_source --dest_dir="$install_dir" --full_replace
chmod -R o-rwx "$install_dir"
chown -R $app:$app "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:$app "$install_dir"
#================================================= #=================================================
# UPGRADE DEPENDENCIES # UPGRADE DEPENDENCIES
#================================================= #=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=7 ynh_script_progression "Upgrading dependencies..."
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version ynh_nodejs_install
ynh_exec_warn_less ynh_install_mongo --mongo_version=$mongo_version ynh_hide_warnings ynh_install_mongo
#=================================================
# SPECIFIC UPGRADE
#================================================= #=================================================
# CONFIGURE MONGOD # CONFIGURE MONGOD
#================================================= #=================================================
ynh_script_progression --message="Configuring mongod..." --weight=1 ynh_script_progression "Configuring mongod..."
ynh_replace_string --match_string="# engine:" --replace_string=" engine: wiredTiger" --target_file="/etc/mongod.conf" ynh_replace --match="# engine:" --replace=" engine: wiredTiger" --file="/etc/mongod.conf"
ynh_replace_string --match_string="#replication:" --replace_string="replication:\n replSetName: rs01" --target_file="/etc/mongod.conf" ynh_replace --match="#replication:" --replace="replication:\n replSetName: rs01" --file="/etc/mongod.conf"
ynh_exec_warn_less systemctl enable mongod --quiet ynh_hide_warnings systemctl enable mongod --quiet
ynh_systemd_action --service_name=mongod --action=restart --log_path=/var/log/mongodb/mongod.log --line_match="Waiting for connections" ynh_systemctl --service=mongod --action=restart --log_path=/var/log/mongodb/mongod.log --wait_until="Waiting for connections"
if ynh_exec_warn_less ynh_mongo_exec --command="printjson(rs.status())" | grep -q "no replset config has been received"; then if ynh_hide_warnings ynh_mongo_exec --command="printjson(rs.status())" | grep -q "no replset config has been received"; then
ynh_exec_warn_less ynh_mongo_exec --command="printjson(rs.initiate())" --eval ynh_hide_warnings ynh_mongo_exec --command="printjson(rs.initiate())"
fi fi
#============================================== #==============================================
# INSTALL ROCKETCHAT # INSTALL ROCKETCHAT
#============================================== #==============================================
ynh_script_progression --message="Building $app... (this will take some time and resources!)" --weight=29 ynh_script_progression "Building $app... (this will take some time and resources!)"
pushd $install_dir/programs/server pushd $install_dir/programs/server
ynh_use_nodejs
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn install --unsafe-perm ynh_hide_warnings ynh_exec_as_app node_load_PATH yarn install --unsafe-perm
popd popd
#================================================= #=================================================
# REAPPLY SYSTEM CONFIGURATIONS # REAPPLY SYSTEM CONFIGURATIONS
#================================================= #=================================================
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 ynh_script_progression "Upgrading system configurations related to $app..."
# Create a dedicated NGINX config # Create a dedicated NGINX config
ynh_add_nginx_config ynh_config_add_nginx
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_add_systemd_config ynh_config_add_systemd
# Use logrotate to manage app-specific logfile(s) # Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append ynh_config_add_logrotate
yunohost service add $app --description="Team collaboration communication platform" --log="/var/log/$app/$app.log" yunohost service add $app --description="Team collaboration communication platform" --log="/var/log/$app/$app.log"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=19 ynh_script_progression "Starting $app's systemd service..."
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="SERVER RUNNING" ynh_systemctl --service=$app --action="start" --log_path="systemd" --wait_until="SERVER RUNNING"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Upgrade of $app completed" --last ynh_script_progression "Upgrade of $app completed"