1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/rocketchat_ynh.git synced 2024-09-03 20:16:25 +02:00

Merge pull request #123 from YunoHost-Apps/upgrade

Apply last example_ynh
This commit is contained in:
Éric Gaspar 2022-07-02 18:52:56 +02:00 committed by GitHub
commit 2619bcdda3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 183 additions and 206 deletions

View file

@ -2,8 +2,8 @@
; Manifest
domain="domain.tld"
path="/path"
admin="john"
is_public=1
admin="john"
password="1Strong-Password"
; Checks
pkg_linter=1
@ -17,12 +17,8 @@
upgrade=1 from_commit=9280c034e8843e7e69622f0daa02ee74c916faa1
backup_restore=1
multi_instance=1
port_already_use=0
change_url=1
;;; Options
Email=
Notification=none
;;; Upgrade options
; commit=9280c034e8843e7e69622f0daa02ee74c916faa1
name=Testing (#118)
manifest_arg=domain=DOMAIN&path=PATH&admin=USER&is_public=1&password=pass&port=666&

View file

@ -24,4 +24,4 @@ location /.well-known/matrix/ {
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}

View file

@ -21,15 +21,15 @@
"name": "eric_G",
"email": ""
},
"requirements": {
"yunohost": ">> 4.3.2"
},
"multi_instance": true,
"services": [
"nginx"
],
"requirements": {
"yunohost": ">> 4.3.2"
},
"arguments": {
"install" : [
"install": [
{
"name": "domain",
"type": "domain"
@ -40,14 +40,6 @@
"example": "/rocketchat",
"default": "/rocketchat"
},
{
"name": "admin",
"type": "user"
},
{
"name": "password",
"type": "password"
},
{
"name": "is_public",
"type": "boolean",
@ -56,6 +48,14 @@
"fr": "Si cette case est cochée, Rocket.Chat sera accessible aux personnes nayant pas de compte. Vous pourrez changer ceci plus tard via la webadmin."
},
"default": true
},
{
"name": "admin",
"type": "user"
},
{
"name": "password",
"type": "password"
}
]
}

View file

@ -17,11 +17,8 @@ pkg_dependencies="apt-transport-https build-essential gzip curl fontconfig graph
# EXPERIMENTAL HELPERS
#=================================================
MONGO_DEBIAN_SERVICENAME="mongodb"
MONGO_CE_SERVICENAME="mongod"
MONGO_DEBIAN_DEPENDENCIES="mongodb mongodb-server mongo-tools"
MONGO_CE_DEPENDENCIES="mongodb-org mongodb-org-server mongodb-org-tools"
MONGO_DEBIAN_CONFIG="/etc/mongodb.conf"
MONGO_CE_DEPENDENCIES="mongodb-org mongodb-org-server mongodb-org-tools mongodb-mongosh"
MONGO_CE_CONFIG="/etc/mongod.conf"
MONGO_CE_REPO="deb http://repo.mongodb.org/apt/debian buster/mongodb-org/5.0 main"
MONGO_CE_KEY="https://www.mongodb.org/static/pgp/server-5.0.asc"
@ -32,14 +29,14 @@ MONGO_CE_KEY="https://www.mongodb.org/static/pgp/server-5.0.asc"
# example: ynh_mongo_exec --command="db.getMongo().getDBNames().indexOf(\"wekan\")"
#
# usage: ynh_mongo_exec [--user=user] [--password=password] [--authenticationdatabase=authenticationdatabase] [--database=database] [--host=host] [--port=port] --command="command" [--eval]
# | arg: -u, --user= - The user name to connect as
# | arg: -p, --password= - The user password
# | arg: -d, --authenticationdatabase= - The authenticationdatabase to connect to
# | arg: -d, --database= - The database to connect to
# | arg: -h, --host= - The host to connect to
# | arg: -P, --port= - The port to connect to
# | arg: -c, --command= - The command to evaluate
# | arg: -e, --eval - Evaluate instead of execute the command.
# | arg: -u, --user= - The user name to connect as
# | arg: -p, --password= - The user password
# | arg: -d, --authenticationdatabase= - The authenticationdatabase to connect to
# | arg: -d, --database= - The database to connect to
# | arg: -h, --host= - The host to connect to
# | arg: -P, --port= - The port to connect to
# | arg: -c, --command= - The command to evaluate
# | arg: -e, --eval - Evaluate instead of execute the command.
#
#
ynh_mongo_exec() {
@ -110,7 +107,7 @@ ynh_mongo_exec() {
database=""
fi
mongo --quiet $user $password $authenticationdatabase $host $port <<EOF
mongosh --quiet --username $user --password $password --authenticationDatabase $authenticationdatabase --host $host --port $port <<EOF
$database
${command}
quit()
@ -124,7 +121,7 @@ EOF
database=""
fi
mongo --quiet $database $user $password $authenticationdatabase $host $port --eval="$command"
mongosh --quiet $database --username $user --password $password --authenticationDatabase $authenticationdatabase --host $host --port $port --eval="$command"
fi
}
@ -175,9 +172,9 @@ ynh_mongo_dump_db() {
# [internal]
#
# usage: ynh_mongo_create_user --db_user=user --db_pwd=pwd --db_name=name
# | arg: -u, --db_user= - The user name to create
# | arg: -p, --db_pwd= - The password to identify user by
# | arg: -n, --db_name= - Name of the database to grant privilegies
# | arg: -u, --db_user= - The user name to create
# | arg: -p, --db_pwd= - The password to identify user by
# | arg: -n, --db_name= - Name of the database to grant privilegies
#
#
ynh_mongo_create_user() {
@ -244,8 +241,8 @@ ynh_mongo_restore_db() {
# [internal]
#
# usage: ynh_mongo_drop_user --db_user=user --db_name=name
# | arg: -u, --db_user= - The user to drop
# | arg: -n, --db_name= - Name of the database
# | arg: -u, --db_user= - The user to drop
# | arg: -n, --db_name= - Name of the database
#
#
ynh_mongo_drop_user() {
@ -263,9 +260,9 @@ ynh_mongo_drop_user() {
# Create a database, an user and its password. Then store the password in the app's config
#
# usage: ynh_mongo_setup_db --db_user=user --db_name=name [--db_pwd=pwd]
# | arg: -u, --db_user= - Owner of the database
# | arg: -n, --db_name= - Name of the database
# | arg: -p, --db_pwd= - Password of the database. If not provided, a password will be generated
# | arg: -u, --db_user= - Owner of the database
# | arg: -n, --db_name= - Name of the database
# | arg: -p, --db_pwd= - Password of the database. If not provided, a password will be generated
#
# After executing this helper, the password of the created database will be available in $db_pwd
# It will also be stored as "mongopwd" into the app settings.
@ -295,8 +292,8 @@ ynh_mongo_setup_db() {
# Remove a database if it exists, and the associated user
#
# usage: ynh_mongo_remove_db --db_user=user --db_name=name
# | arg: -u, --db_user= - Owner of the database
# | arg: -n, --db_name= - Name of the database
# | arg: -u, --db_user= - Owner of the database
# | arg: -n, --db_name= - Name of the database
#
#
ynh_mongo_remove_db() {
@ -324,26 +321,16 @@ ynh_mongo_remove_db() {
#
#
ynh_install_mongo() {
ynh_script_progression --message="Installing MongoDB..." --weight=5
# Define Mongo Service Name
if $(dpkg --compare-versions $(cat /etc/debian_version) gt "10.0")
then
ynh_install_extra_app_dependencies --repo="$MONGO_CE_REPO" --package="$MONGO_CE_DEPENDENCIES" --key="$MONGO_CE_KEY"
MONGODB_SERVICENAME=$MONGO_CE_SERVICENAME
else
ynh_print_info --message="Installing MongoDB Debian..."
ynh_install_app_dependencies $MONGO_DEBIAN_DEPENDENCIES
MONGODB_SERVICENAME=$MONGO_DEBIAN_SERVICENAME
fi
mongodb_servicename=$MONGODB_SERVICENAME
ynh_print_info --message="Installing MongoDB Community Edition..."
ynh_install_extra_app_dependencies --repo="$MONGO_CE_REPO" --package="$MONGO_CE_DEPENDENCIES" --key="$MONGO_CE_KEY"
mongodb_servicename=$MONGO_CE_SERVICENAME
# Make sure MongoDB is started and enabled
systemctl is-enabled $MONGODB_SERVICENAME -q || systemctl enable $MONGODB_SERVICENAME --quiet
systemctl is-active $MONGODB_SERVICENAME -q || ynh_systemd_action --service_name=$MONGODB_SERVICENAME --action=restart --line_match="aiting for connections" --log_path="/var/log/mongodb/$MONGODB_SERVICENAME.log"
systemctl is-enabled $mongodb_servicename -q || systemctl enable $mongodb_servicename --quiet
systemctl is-active $mongodb_servicename -q || ynh_systemd_action --service_name=$mongodb_servicename --action=restart --line_match="aiting for connections" --log_path="/var/log/mongodb/$mongodb_servicename.log"
# Integrate MongoDB service in YunoHost
yunohost service add $MONGODB_SERVICENAME --description="MongoDB daemon" --log="/var/log/mongodb/$MONGODB_SERVICENAME.log"
yunohost service add $mongodb_servicename --description="MongoDB daemon" --log="/var/log/mongodb/$mongodb_servicename.log"
}
# Remove MongoDB
@ -357,15 +344,11 @@ ynh_remove_mongo() {
# Only remove the mongodb service if it is not installed.
if ! ynh_package_is_installed --package="mongodb*"
then
ynh_script_progression --message="Removing MongoDB service..." --weight=2
# Define Mongo Service Name
if [ "$(lsb_release --codename --short)" = "buster" ]; then
MONGODB_SERVICENAME=$MONGO_CE_SERVICENAME
else
MONGODB_SERVICENAME=$MONGO_DEBIAN_SERVICENAME
fi
ynh_print_info --message="Removing MongoDB service..."
mongodb_servicename=$MONGO_CE_SERVICENAME
# Remove the mongodb service
yunohost service remove $MONGODB_SERVICENAME
# ynh_secure_remove --file=$MONGO_ROOT_PWD_FILE
yunohost service remove $mongodb_servicename
ynh_secure_remove --file="/var/lib/mongodb"
ynh_secure_remove --file="/var/log/mongodb"
fi
}

View file

@ -15,7 +15,6 @@ source /usr/share/yunohost/helpers
#=================================================
ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script.
true
}
# Exit if an error occurs during the execution of the script
@ -24,6 +23,7 @@ ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
@ -32,7 +32,10 @@ domain=$(ynh_app_setting_get --app=$app --key=domain)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#=================================================
# STANDARD BACKUP STEPS
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
ynh_print_info --message="Declaring files to be backed up..."
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
@ -45,14 +48,14 @@ ynh_backup --src_path="$final_path"
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP LOGROTATE
#=================================================
ynh_backup --src_path="/etc/logrotate.d/$app"
#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP SYSTEMD
#=================================================

View file

@ -28,6 +28,8 @@ ynh_script_progression --message="Loading installation settings..." --weight=1
# Needed for helper "ynh_add_nginx_config"
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
# Add settings here as needed by your application
port=$(ynh_app_setting_get --app=$app --key=port)
#=================================================
@ -38,6 +40,7 @@ ynh_script_progression --message="Backing up the app before changing its URL (ma
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
ynh_clean_check_starting
# Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
@ -108,7 +111,7 @@ fi
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd"
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="SERVER RUNNING"
#=================================================
# RELOAD NGINX

View file

@ -14,7 +14,7 @@ source /usr/share/yunohost/helpers
#=================================================
ynh_clean_setup () {
true
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
@ -26,17 +26,24 @@ ynh_abort_if_errors
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
is_public=$YNH_APP_ARG_IS_PUBLIC
password=$YNH_APP_ARG_PASSWORD
admin=$YNH_APP_ARG_ADMIN
email=$(ynh_user_get_info --username=$admin --key=mail)
password=$YNH_APP_ARG_PASSWORD
app=$YNH_APP_INSTANCE_NAME
email=$(ynh_user_get_info --username=$admin --key=mail)
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..." --weight=1
# Check machine architecture (in particular, we don't support ARM and 32bit machines)
if [ $YNH_ARCH == "i386" ] || [ $YNH_ARCH == "armel" ] || [ $YNH_ARCH == "armhf" ]
then
ynh_die --message="Sorry, but this app can only be installed on a x86, 64 bits machine :("
fi
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
@ -70,11 +77,17 @@ ynh_app_setting_set --app=$app --key=port --value=$port
#=================================================
ynh_script_progression --message="Installing dependencies..." --weight=20
ynh_install_app_dependencies $pkg_dependencies
# Install Nodejs
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
ynh_install_mongo
ynh_exec_warn_less ynh_install_mongo
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..." --weight=3
# Create a system user
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# CREATE A MONGODB DATABASE
@ -86,14 +99,6 @@ db_user=$db_name
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_mongo_setup_db --db_user=$db_user --db_name=$db_name
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..." --weight=3
# Create a system user
ynh_system_user_create --username=$app --home_dir=$final_path
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
@ -101,7 +106,7 @@ ynh_script_progression --message="Setting up source files..." --weight=2
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir=$final_path
ynh_setup_source --dest_dir="$final_path"
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
@ -117,14 +122,29 @@ ynh_add_nginx_config
#=================================================
# SPECIFIC SETUP
#=================================================
# CONFIGURE MONGOD
#=================================================
ynh_script_progression --message="Configuring mongod..." --weight=1
ynh_replace_string --match_string="# engine:" --replace_string=" engine: wiredTiger" --target_file=$MONGO_CE_CONFIG
ynh_replace_string --match_string="#replication:" --replace_string="replication:\n replSetName: rs01" --target_file=$MONGO_CE_CONFIG
ynh_exec_warn_less systemctl enable $MONGO_CE_SERVICENAME --quiet
ynh_systemd_action --service_name=$MONGO_CE_SERVICENAME --action=restart --log_path=/var/log/mongodb/$MONGO_CE_SERVICENAME.log --line_match="Waiting for connections"
if ynh_exec_warn_less 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
fi
#==============================================
# INSTALL ROCKETCHAT
#==============================================
ynh_script_progression --message="Building $app... (this will take some time and resources!)" --weight=20
pushd $final_path/programs/server
ynh_use_nodejs
ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm install --unsafe-perm 2>/dev/null
ynh_use_nodejs
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm install --unsafe-perm
popd
#=================================================
@ -135,21 +155,6 @@ ynh_script_progression --message="Configuring a systemd service..." --weight=1
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# MODIFY A CONFIG FILE
#=================================================
ynh_script_progression --message="Configuring a mongod..." --weight=1
sed -i "s/^# engine:/ engine: wiredTiger/" /etc/mongod.conf
sed -i "s/^#replication:/replication:\n replSetName: rs01/" /etc/mongod.conf
ynh_exec_warn_less systemctl enable $mongodb_servicename --quiet
ynh_systemd_action --service_name=$mongodb_servicename --action=restart
sleep 10
ynh_mongo_exec --command="printjson(rs.initiate())" --eval
#=================================================
# GENERIC FINALIZATION
#=================================================
@ -165,33 +170,25 @@ ynh_use_logrotate
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --description="Team collaboration communication platform" --log="/var/log/$app/$app.log"
#=================================================
# START MONGO SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a MongoDB service..." --weight=2
# Start a mongod service
ynh_exec_warn_less systemctl enable $mongodb_servicename --quiet
ynh_systemd_action --service_name=$mongodb_servicename --action="restart"
yunohost service add $app --description="Team collaboration communication platform"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=2
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd"
sleep 60
ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="SERVER RUNNING"
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Configuring permissions..." --weight=1
# Make app public if necessary or protect it
# Make app public if necessary
if [ $is_public -eq 1 ]
then
# Everyone can access the app.
# The "main" permission is automatically created before the install script.
ynh_permission_update --permission="main" --add="visitors"
fi

View file

@ -28,19 +28,13 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path)
# REMOVE SERVICE INTEGRATION IN YUNOHOST
#=================================================
# 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
then
ynh_script_progression --message="Removing $app service..." --weight=1
ynh_script_progression --message="Removing $app service integration..." --weight=1
yunohost service remove $app
fi
if ynh_exec_warn_less yunohost service status "$mongodb_servicename" >/dev/null
then
ynh_script_progression --message="Removing $mongodb_servicename service integration..."
yunohost service remove "$mongodb_servicename"
fi
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
@ -48,7 +42,6 @@ ynh_script_progression --message="Stopping and removing the systemd service..."
# Remove the dedicated systemd config
ynh_remove_systemd_config
ynh_remove_systemd_config --service=$mongodb_servicename
#=================================================
# REMOVE LOGROTATE CONFIGURATION
@ -63,19 +56,15 @@ ynh_remove_logrotate
#=================================================
ynh_script_progression --message="Removing the MongoDB database..."
ynh_replace_string --match_string="engine: wiredTiger" --replace_string="# engine:" --target_file=$MONGO_CE_CONFIG
ynh_replace_string --match_string="replication:" --replace_string="#replication:" --target_file=$MONGO_CE_CONFIG
ynh_replace_string --match_string=" replSetName: rs01" --replace_string="" --target_file=$MONGO_CE_CONFIG
ynh_systemd_action --service_name=$MONGO_CE_SERVICENAME --action=restart --log_path=/var/log/mongodb/$MONGO_CE_SERVICENAME.log --line_match="Waiting for connections"
# Remove a database if it exists, along with the associated user
ynh_mongo_remove_db --db_user=$db_user --db_name=$db_name
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..." --weight=1
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
ynh_remove_nodejs
ynh_remove_mongo
#=================================================
# REMOVE APP MAIN DIR
#=================================================
@ -96,6 +85,16 @@ ynh_script_progression --message="Removing NGINX web server configuration..." --
# Remove the dedicated NGINX config
ynh_remove_nginx_config
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..." --weight=1
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
ynh_remove_nodejs
ynh_remove_mongo
#=================================================
# GENERIC FINALIZATION
#=================================================

View file

@ -1,5 +1,7 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
@ -13,8 +15,7 @@ source /usr/share/yunohost/helpers
#=================================================
ynh_clean_setup () {
#### Remove this function if there's nothing to clean before calling the remove script.
true
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
@ -37,23 +38,18 @@ db_user=$db_name
#=================================================
ynh_script_progression --message="Validating restoration parameters..." --weight=1
test ! -d $final_path || ynh_die --message="There is already a directory: $final_path "
test ! -d $final_path \
|| ynh_die --message="There is already a directory: $final_path "
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
# Create the dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir=$final_path
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# RESTORE THE APP MAIN DIR
@ -74,10 +70,16 @@ chown -R $app:$app "$final_path"
ynh_script_progression --message="Reinstalling dependencies..." --weight=1
# Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
ynh_install_mongo
ynh_exec_warn_less ynh_install_mongo
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the NGINX web server configuration..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE THE MONGODB DATABASE
@ -89,19 +91,19 @@ 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
#=================================================
# MODIFY A CONFIG FILE
# CONFIGURE MONGOD
#=================================================
ynh_script_progression --message="Configuring a mongod..." --weight=3
ynh_script_progression --message="Configuring mongod..." --weight=3
sed -i "s/^# engine:/ engine: wiredTiger/" /etc/mongod.conf
sed -i "s/^#replication:/replication:\n replSetName: rs01/" /etc/mongod.conf
ynh_replace_string --match_string="# engine:" --replace_string=" engine: wiredTiger" --target_file=$MONGO_CE_CONFIG
ynh_replace_string --match_string="#replication:" --replace_string="replication:\n replSetName: rs01" --target_file=$MONGO_CE_CONFIG
ynh_exec_warn_less systemctl enable $mongodb_servicename --quiet
ynh_systemd_action --service_name=$mongodb_servicename --action=restart
ynh_exec_warn_less systemctl enable $MONGO_CE_SERVICENAME --quiet
ynh_systemd_action --service_name=$MONGO_CE_SERVICENAME --action=restart --log_path=/var/log/mongodb/$MONGO_CE_SERVICENAME.log --line_match="Waiting for connections"
sleep 10
ynh_mongo_exec --command="printjson(rs.initiate())" --eval
if ynh_exec_warn_less 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
fi
#=================================================
# RESTORE SYSTEMD
@ -123,24 +125,14 @@ ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app --description="Team collaboration communication platform" --log="/var/log/$app/$app.log"
#=================================================
# START MONGO SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a MongoDB service..." --weight=2
# Start a mongod service
ynh_exec_warn_less systemctl enable $mongodb_servicename --quiet
ynh_systemd_action --service_name=$mongodb_servicename --action="restart"
yunohost service add $app --description="Team collaboration communication platform"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=5
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd"
sleep 60
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="SERVER RUNNING"
#=================================================
# GENERIC FINALIZATION

View file

@ -29,6 +29,7 @@ email=$(ynh_app_setting_get --app=$app --key=email)
#=================================================
# CHECK VERSION
#=================================================
ynh_script_progression --message="Checking version..."
upgrade_type=$(ynh_check_app_version_changed)
@ -40,12 +41,22 @@ ynh_script_progression --message="Backing up the app before upgrading (may take
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
ynh_clean_check_starting
# Restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd"
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
@ -64,15 +75,6 @@ if ynh_legacy_permissions_exists; then
ynh_app_setting_delete --app=$app --key=is_public
fi
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd"
#=================================================
# CREATE DEDICATED USER
#=================================================
@ -98,6 +100,15 @@ chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=7
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
ynh_exec_warn_less ynh_install_mongo
#=================================================
# NGINX CONFIGURATION
#=================================================
@ -107,13 +118,21 @@ ynh_script_progression --message="Upgrading NGINX web server configuration..." -
ynh_add_nginx_config
#=================================================
# UPGRADE DEPENDENCIES
# SPECIFIC UPGRADE
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=7
# CONFIGURE MONGOD
#=================================================
ynh_script_progression --message="Configuring mongod..." --weight=1
ynh_install_app_dependencies $pkg_dependencies
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
ynh_install_mongo
ynh_replace_string --match_string="# engine:" --replace_string=" engine: wiredTiger" --target_file=$MONGO_CE_CONFIG
ynh_replace_string --match_string="#replication:" --replace_string="replication:\n replSetName: rs01" --target_file=$MONGO_CE_CONFIG
ynh_exec_warn_less systemctl enable $MONGO_CE_SERVICENAME --quiet
ynh_systemd_action --service_name=$MONGO_CE_SERVICENAME --action=restart --log_path=/var/log/mongodb/$MONGO_CE_SERVICENAME.log --line_match="Waiting for connections"
if ynh_exec_warn_less 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
fi
#==============================================
# INSTALL ROCKETCHAT
@ -121,8 +140,8 @@ ynh_install_mongo
ynh_script_progression --message="Building $app... (this will take some time and resources!)" --weight=20
pushd $final_path/programs/server
ynh_use_nodejs
ynh_exec_as $app env $ynh_node_load_PATH npm install --unsafe-perm 2>/dev/null
ynh_use_nodejs
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH npm install --unsafe-perm
popd
#=================================================
@ -134,20 +153,7 @@ ynh_script_progression --message="Upgrading systemd configuration..." --weight=2
ynh_add_systemd_config
#=================================================
# MODIFY A CONFIG FILE
#=================================================
ynh_script_progression --message="Configuring a mongod..." --weight=1
sed -i "s/^# engine:/ engine: wiredTiger/" /etc/mongod.conf
sed -i "s/^#replication:/replication:\n replSetName: rs01/" /etc/mongod.conf
ynh_exec_warn_less systemctl enable $mongodb_servicename --quiet
ynh_systemd_action --service_name=$mongodb_servicename --action="restart"
sleep 10
mongo --eval "printjson(rs.initiate())"
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
#=================================================
@ -161,16 +167,14 @@ ynh_use_logrotate --non-append
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app --description="Team collaboration communication platform" --log="/var/log/$app/$app.log"
yunohost service add $app --description="Team collaboration communication platform"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=10
ynh_systemd_action --service_name=$mongodb_servicename --action="restart" --log_path="systemd"
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd"
sleep 60
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="SERVER RUNNING"
#=================================================
# RELOAD NGINX