[enh] Backup/restore scripts. WIP

This commit is contained in:
opi 2016-05-07 18:21:06 +02:00
parent bd56eb4f5d
commit d0ab8c5f31
3 changed files with 161 additions and 0 deletions

View File

@ -2,6 +2,9 @@
"name": "Searx", "name": "Searx",
"id": "searx", "id": "searx",
"packaging_format": 1, "packaging_format": 1,
"requirements": {
"yunohost": ">> 2.3.15"
},
"description": { "description": {
"en": "A privacy-respecting, hackable metasearch engine", "en": "A privacy-respecting, hackable metasearch engine",
"fr": "Un méta-moteur de recherche respectueux de la vie privée et bidouillable" "fr": "Un méta-moteur de recherche respectueux de la vie privée et bidouillable"

35
scripts/backup Executable file
View File

@ -0,0 +1,35 @@
#!/bin/bash
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
set -e
# Source YNH helpers
. /usr/share/yunohost/helpers
# This is a multi-instance app, meaning it can be installed several times independently
# The id of the app as stated in the manifest is available as $YNH_APP_ID
# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...)
# The app instance name is available as $YNH_APP_INSTANCE_NAME
# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample
# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2
# - ynhexample__{N} for the subsequent installations, with N=3,4, ...
# The app instance name is probably what you are interested the most, since this is
# guaranteed to be unique. This is a good unique identifier to define installation path,
# db names, ...
app=$YNH_APP_INSTANCE_NAME
# Retrieve arguments
domain=$(sudo yunohost app setting $app domain)
# Backup directory location for the app from where the script is executed and
# which will be compressed afterward
backup_dir=$YNH_APP_BACKUP_DIR
# Backup sources & data
ynh_backup "/opt/yunohost/$app" "sources"
# Copy Nginx conf
sudo mkdir -p ./conf
ynh_backup "/etc/uwsgi/apps-available/$app.ini" "conf/searx.ini"
ynh_backup "/opt/yunohost/$app/searx/settings.yml" "conf/settings.yml"
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "conf/nginx.conf"

123
scripts/restore Executable file
View File

@ -0,0 +1,123 @@
#!/bin/bash
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
set -e
# Source YNH helpers
. /usr/share/yunohost/helpers
# This is a multi-instance app, meaning it can be installed several times independently
# The id of the app as stated in the manifest is available as $YNH_APP_ID
# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...)
# The app instance name is available as $YNH_APP_INSTANCE_NAME
# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample
# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2
# - ynhexample__{N} for the subsequent installations, with N=3,4, ...
# The app instance name is probably what you are interested the most, since this is
# guaranteed to be unique. This is a good unique identifier to define installation path,
# db names, ...
app=$YNH_APP_INSTANCE_NAME
# Get old parameter of the app
domain=$(sudo yunohost app setting $app domain)
path=$(sudo yunohost app setting $app path)
is_public=$(sudo yunohost app setting $app is_public)
# Check domain/path availability
sudo yunohost app checkurl $domain$path -a $app
if [[ ! $? -eq 0 ]]; then
echo "There is already an app on this URL : $domain$path" | sudo tee /dev/stderr
exit 1
fi
final_path=/opt/yunohost/searx
if [ -d $final_path ]; then
echo "There is already a directory: $final_path " | sudo tee /dev/stderr
exit 1
fi
nginx_conf=/etc/nginx/conf.d/$domain.d/$app.conf
if [ -f $nginx_conf ]; then
echo "There is already a nginx conf file at this path: $nginx_conf " | sudo tee /dev/stderr
exit 1
fi
# Run install script
# sudo bash -c "./install $domain $path $is_public $app"
# Path need a trailing slash, and location does not.
# See conf/nginx.conf* usage
location=$path
if [[ ! $path == */ ]]; then
# no trailing slash, so add it
path=$path/
fi
if [[ ! "$location" == "/" ]]; then
# remove possible trailing slash
location=${location%/}
fi
# Save specific settings
sudo yunohost app setting searx is_public -v $is_public
# Check depends installation
sudo apt-get install git build-essential libxslt-dev python-dev python-virtualenv python-pybabel zlib1g-dev libffi-dev libssl-dev python-lxml uwsgi uwsgi-plugin-python -y
# Check Swap
if [ $(sudo swapon -s | wc -l) = 1 ];
then
# It is NOT possible to setup a swap file on a tmpfs filesystem
mount | grep /tmp | grep tmpfs > /dev/null 2>&1
if [ $? = 1 ];
then
tmp_swap_file=/tmp/searx_swapfile
else
tmp_swap_file=/var/cache/searx_swapfile
fi
sudo dd if=/dev/zero of=$tmp_swap_file bs=1M count=256
sudo chmod 600 $tmp_swap_file
sudo mkswap $tmp_swap_file
sudo swapon $tmp_swap_file
fi
# Restore sources
final_path=/opt/yunohost/searx
sudo cp -a "./sources" $final_path
# Init virtualenv
sudo virtualenv --system-site-packages $final_path
sudo bash -c "source $final_path/bin/activate && pip install -r $final_path/requirements-ynh.txt"
# Disable swapfile
if [[ -v "$tmp_swap_file" ]];
then
sudo swapoff $tmp_swap_file
sudo rm -f $tmp_swap_file
fi
#Configuration Searx
sudo cp "./conf/settings.yml" "$final_path/searx/settings.yml"
# Set permissions to searx directory
sudo useradd searx -d $final_path
sudo chown searx:searx -R $final_path
# Copy uwsgi config
sudo cp "./conf/searx.ini" "/etc/uwsgi/apps-available/$app.ini"
sudo ln -s "/etc/uwsgi/apps-available/$app.ini" /etc/uwsgi/apps-enabled/
# Nginx conf
sudo cp "conf/nginx.conf" $nginx_conf
## Reload Nginx and regenerate SSOwat conf
sudo service nginx reload
sudo service uwsgi restart
sudo yunohost service add uwsgi -l /var/log/uwsgi/app/searx.log
if [ "$is_public" = "Yes" ];
then
sudo yunohost app setting searx unprotected_uris -v "/"
fi
sudo yunohost app ssowatconf