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

Fixes backup and restore

Adds working upgrade
This commit is contained in:
Selamanse 2017-07-21 14:35:08 +02:00
parent 0611a21ab2
commit 3493b1fd52
8 changed files with 87 additions and 58 deletions

View file

@ -8,7 +8,7 @@ WorkingDirectory=/var/lib/rocketchat
User=#USER#
ExecStart=/usr/local/bin/node main.js
Restart=always
SyslogIdentifier=Rocket.Chat
SyslogIdentifier=rocketchat
Environment="BIND_IP=127.0.0.1"
Environment="ROOT_URL=https://#ROOTURL##LOCATION#"
Environment="PORT=#PORT#"

View file

@ -7,7 +7,7 @@
},
"url": "https://github.com/selamanse/rocketchat_ynh",
"license": "MIT",
"version": "0.57.2-rc.1",
"version": "0.57.2-rc.2",
"maintainer": {
"name": "selamanse",
"email": "selamanse@scheinfrei.info",

11
scripts/_common.sh Normal file
View file

@ -0,0 +1,11 @@
# common.sh
ROCKETCHAT_VERSION=0.57.2
NODE_VERSION=4.7.1
waitforservice() {
isup=false; x=90; while [ $x -gt 0 ];do echo "Waiting approx. $x seconds..."; \
x=$(( $x - 1 )); sleep 1; if $(curl -m 1 -s localhost:$port${path:-/}/api/v1/info | \
grep -e "success.*true" >/dev/null 2>&1); then isup=true; break; fi; done && if $isup; \
then echo "service is up"; else ynh_die "$app could not be started"; fi
}

View file

@ -7,15 +7,6 @@ set -eu
source /usr/share/yunohost/helpers
#=================================================
# GENERIC START
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit on command errors and treat access to unset variables as an error
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
@ -24,8 +15,6 @@ app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get $app final_path)
domain=$(ynh_app_setting_get $app domain)
db_name=$(ynh_app_setting_get $app db_name)
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
#=================================================
# STANDARD BACKUP STEPS
@ -33,13 +22,18 @@ db_pwd=$(ynh_app_setting_get $app mysqlpwd)
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup "$final_path" "app"
workdir=$(pwd)
cd $final_path
tar -czf $workdir/rocket.chat.gtar .
cd $workdir
ynh_backup ./rocket.chat.gtar
#=================================================
# BACKUP THE NGINX CONFIGURATION
# BACKUP THE CONFIGURATION
#=================================================
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "nginx"
ynh_backup "/etc/systemd/system/$app.service" "conf/service"
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "conf/nginx"
#=================================================
# BACKUP THE MONGODB DATABASE

View file

@ -7,6 +7,7 @@ set -eu
# IMPORT GENERIC HELPERS
#=================================================
source ./_common.sh
source /usr/share/yunohost/helpers
#=================================================
@ -28,9 +29,6 @@ language=$YNH_APP_ARG_LANG
app=$YNH_APP_INSTANCE_NAME
serviceuser=rocketchat
ROCKETCHAT_VERSION=0.57.2
NODE_VERSION=4.7.1
workdir=$(pwd)
# find suitable port (default 3000)
@ -48,17 +46,14 @@ final_path="/var/lib/$app"
You should safely delete it before installing this app."
# Save specific settings
ynh_app_setting_set $app node_version $NODE_VERSION
ynh_app_setting_set $app rocketchat_version $ROCKETCHAT_VERSION
ynh_app_setting_set $app serviceuser $serviceuser
ynh_app_setting_set $app port $port
ynh_app_setting_set $app final_path $final_path
ynh_app_setting_set $app path $path
ynh_app_setting_set $app is_public $is_public
function waitforservice {
isup=false; x=90; while [ $x -gt 0 ];do echo "Waiting approx. $x seconds..."; \
x=$(( $x - 1 )); sleep 1; if $(curl -m 1 -s localhost:$port${path:-/}/api/v1/info | \
grep -e "success.*true" >/dev/null 2>&1); then isup=true; break; fi; done && if $isup; \
then echo "service is up"; else ynh_die "$app could not be started"; fi
}
#Install dependencies
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 >/dev/null
echo "deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/3.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
@ -75,6 +70,9 @@ sudo n $NODE_VERSION
# Create destination
sudo mkdir -p $final_path
# Create user
sudo useradd -d "$final_path" -M $serviceuser
# Copy and set systemd configuration
sed -i "s@#ROOTURL#@$domain@g" ../conf/rocketchat.service
sed -i "s@#LOCATION#@${path:-/}@g" ../conf/rocketchat.service
@ -97,6 +95,9 @@ sudo cp ../conf/nginx.conf "$nginx_conf"
echo "Downloading rocket.chat-$ROCKETCHAT_VERSION.gtar from https://rocket.chat/releases/${ROCKETCHAT_VERSION}/download."
sudo curl -s -L -o $final_path/rocket.chat-$ROCKETCHAT_VERSION.gtar "https://rocket.chat/releases/${ROCKETCHAT_VERSION}/download"
sudo tar -xzf $final_path/rocket.chat-$ROCKETCHAT_VERSION.gtar -C $final_path --strip-components=1 bundle
sudo rm $final_path/rocket.chat-$ROCKETCHAT_VERSION.gtar
sudo chown -R $serviceuser: $final_path
cd $final_path/programs/server/
@ -104,11 +105,6 @@ sudo npm install --production
cd $workdir
sudo useradd -d "$final_path" -M $serviceuser
sudo chown -R $serviceuser: $final_path
sudo chown -R $serviceuser: $final_path
sudo systemctl reload nginx
if [ "$is_public" = "Yes" ];
then

View file

@ -7,6 +7,7 @@ set -u
# IMPORT GENERIC HELPERS
#=================================================
source ./_common.sh
source /usr/share/yunohost/helpers
app=$YNH_APP_INSTANCE_NAME
@ -23,6 +24,11 @@ sudo rm -rf $final_path
sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf
sudo rm -rf /var/log/$app
sudo rm -f /etc/systemd/system/$app.service
# remove database!!!
sudo mongo rocketchat --eval "db.dropDatabase()"
# remove user!!!
sudo userdel -r $serviceuser
sudo systemctl daemon-reload

View file

@ -23,19 +23,23 @@ ynh_abort_if_errors
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
path=$(ynh_app_setting_get $app path)
final_path=$(ynh_app_setting_get $app final_path)
db_name=$(ynh_app_setting_get $app db_name)
serviceuser=$(ynh_app_setting_get $app serviceuser)
# Check domain/path availability
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|| ynh_die
sudo yunohost app checkurl "${domain}${path}" -a "$app" || ynh_die
# Check destination directory
DESTDIR="/var/www/$app"
[[ -d $DESTDIR ]] && ynh_die \
"The destination directory '$DESTDIR' already exists.\
You should safely delete it before restoring this app."
[[ -d $final_path ]] && ynh_die \
"The destination directory '$final_path' already exists.\
You should safely delete it before restoring this app."
# Create destination
sudo mkdir -p $final_path
# Create user
sudo useradd -d "$final_path" -M $serviceuser
#=================================================
# STANDARD RESTORATION STEPS
@ -43,16 +47,31 @@ db_name=$(ynh_app_setting_get $app db_name)
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_restore_file "nginx"
sudo cp -a "conf/nginx" "/etc/nginx/conf.d/$domain.d/$app.conf"
sudo systemctl reload nginx
#=================================================
# RESTORE THE SYSTEMD CONFIGURATION
#=================================================
sudo cp -a "conf/service" "/etc/systemd/system/rocketchat.service"
sudo systemctl daemon-reload
sudo systemctl enable rocketchat
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_restore_file "app"
sudo tar -xzf ./rocket.chat.gtar -C $final_path
sudo chown -R $serviceuser: $final_path
#=================================================
# RESTORE THE MONGODB
#=================================================
sudo mongorestore --dbpath /var/lib/mongodb ./dump
sudo mongorestore ./dump
#=================================================
# START APP RELATED SERVICES
#=================================================
sudo systemctl start rocketchat

View file

@ -8,26 +8,29 @@ set -eu
#=================================================
source /usr/share/yunohost/helpers
ROCKETCHAT_VERSION=0.57.2
NODE_VERSION=4.7.1
# Source common variables and helpers
source ./_common.sh
app=$YNH_APP_INSTANCE_NAME
final_path="/var/www/$app"
final_path=$(ynh_app_setting_get $app final_path)
serviceuser=$(ynh_app_setting_get $app serviceuser)
path=$(ynh_app_setting_get $app path)
port=$(ynh_app_setting_get $app port)
# remove old things
sudo systemctl stop Rocketchat.service
sudo m -rf $final_path
sudo mkdir $final_path
sudo systemctl stop rocketchat
# install newer node version
sudo n $NODE_VERSION
sudo rm -rf $final_path
sudo mkdir -p $final_path
# upgrade to the latest rocketchat
sudo curl -s -L -o $final_path/rocket.chat-latest.gtar "https://rocket.chat/releases/latest/download"
sudo tar -xzf $final_path/rocket.chat-latest.gtar -C $final_path --strip-components=1 bundle
sudo rm $final_path/rocket.chat-latest.gtar
# download install newer rocketchat version
echo "Downloading rocket.chat-$ROCKETCHAT_VERSION.gtar from https://rocket.chat/releases/${ROCKETCHAT_VERSION}/download."
sudo curl -s -L -o $final_path/rocket.chat-$ROCKETCHAT_VERSION.gtar "https://rocket.chat/releases/${ROCKETCHAT_VERSION}/download"
sudo tar -xzf $final_path/rocket.chat-$ROCKETCHAT_VERSION.gtar -C $final_path --strip-components=1 bundle
cd $final_path/programs/server/
sudo npm install
sudo npm install --production
sudo systemctl start Rocketchat.service
sudo chown -R $serviceuser: $final_path
sudo systemctl start rocketchat
waitforservice