Improve data storage management and improve scripts

This commit is contained in:
Josué Tille 2024-04-12 22:19:27 +02:00
parent 0c75e06768
commit ba9717b8f8
No known key found for this signature in database
GPG key ID: 5F259226AD51F2F5
8 changed files with 102 additions and 63 deletions

View file

@ -5,7 +5,7 @@ name = "Seafile"
description.en = "Open Source Cloud Storage"
description.fr = "Stockage Cloud Open Source"
version = "9.0.9~ynh2"
version = "9.0.9~ynh3"
maintainers = ["Josué Tille"]

View file

@ -5,6 +5,14 @@
time_zone=$(cat /etc/timezone)
python_version="$(python3 -V | cut -d' ' -f2 | cut -d. -f1-2)"
# Create special path with / at the end
if [[ $path == '/' ]]
then
path2="$path"
else
path2="$path/"
fi
#=================================================
# DEFINE ALL COMMON FONCTIONS
#=================================================

View file

@ -11,6 +11,8 @@ source ../settings/scripts/_common.sh
# Source YunoHost helpers
source /usr/share/yunohost/helpers
seafile_version=$(ynh_app_upstream_version)
if systemctl is-active seafile --quiet || systemctl is-active seahub --quiet; then
ynh_print_warn --message="It's hightly recommended to make your backup when the service is stopped. Please stop seafile service and seahub service with this command before to run the backup 'systemctl stop seafile.service seahub.service'"
fi

View file

@ -11,6 +11,8 @@ source ./_common.sh
# Source YunoHost helpers
source /usr/share/yunohost/helpers
seafile_version=$(ynh_app_upstream_version)
# Create special path with / at the end
if [[ $path == '/' ]]
then

View file

@ -13,29 +13,22 @@ source /usr/share/yunohost/helpers
seafile_version=$(ynh_app_upstream_version)
# Create special path with / at the end
if [[ $path == '/' ]]
then
path2=$path
else
path2=$path"/"
fi
#=================================================
# STANDARD MODIFICATIONS
#=================================================
ynh_script_progression --message="Creating base directory..."
ln -s $data_dir $install_dir/seafile-data
mkdir -p $install_dir/logs
if [ -n "$(ls -A $data_dir)" ]; then
if [ -n "$(ls -A "$data_dir")" ]; then
old_data_dir_path="${data_dir}_$(date '+%Y%m%d.%H%M%S')"
ynh_print_warn "Data directory was not empty. Data was moved to $old_data_dir_path"
mkdir -p $old_data_dir_path
mkdir -p "$old_data_dir_path"
mv -t "$old_data_dir_path" "$data_dir"/*
fi
mkdir -p /var/log/"$app"
mkdir -p "$data_dir"/{seafile-data,seahub-data}
# Download new version from sources
ynh_script_progression --message="Installing sources files..." --weight=7
ynh_setup_source --dest_dir=$install_dir/seafile-server-$seafile_version
@ -46,9 +39,8 @@ install_dependance
# init databases
ynh_script_progression --message="Configuring MySQL database..."
db_user=seafile
db_helper=ynh_"mysql"_setup_db
$db_helper --db_user $db_user --db_name ccnetdb --db_pwd "$db_pwd"
$db_helper --db_user $db_user --db_name seahubdb --db_pwd "$db_pwd"
ynh_''mysql_setup_db --db_user "$db_user" --db_name ccnetdb --db_pwd "$db_pwd"
ynh_''mysql_setup_db --db_user "$db_user" --db_name seahubdb --db_pwd "$db_pwd"
ynh_script_progression --message="Configuring application..." --weight=3
@ -56,23 +48,23 @@ ynh_script_progression --message="Configuring application..." --weight=3
set_permission
ynh_replace_special_string --match_string 'seafile_config.seafile_dir = seafile_config.validate_seafile_dir(seafile_dir)' \
--replace_string 'seafile_config.seafile_dir = seafile_dir' \
--target_file $install_dir/seafile-server-$seafile_version/setup-seafile-mysql.py
sudo -u $app bash $install_dir/seafile-server-$seafile_version/setup-seafile-mysql.sh auto \
--target_file "$install_dir/seafile-server-$seafile_version/setup-seafile-mysql.py"
sudo -u "$app" bash "$install_dir/seafile-server-$seafile_version/setup-seafile-mysql.sh" auto \
--server-name "$server_name" \
--server-ip $domain \
--fileserver-port $port_fileserver \
--server-ip "$domain" \
--fileserver-port "$port_fileserver" \
--use-existing-db 1 \
--mysql-host localhost \
--mysql-port 3306 \
--mysql-user $db_user \
--mysql-user "$db_user" \
--mysql-user-passwd "$db_pwd" \
--seafile-db "$db_name" \
--ccnet-db ccnetdb \
--seahub-db seahubdb
# Retrive values from auto generated config file
seahub_secret_key=$(grep -P 'SECRET_KEY\s*=\s*".+"' $install_dir/conf/seahub_settings.py | cut -d'"' -f2)
ynh_app_setting_set --app $app --key seahub_secret_key --value $seahub_secret_key
seahub_secret_key=$(grep -P 'SECRET_KEY\s*=\s*".+"' "$install_dir"/conf/seahub_settings.py | cut -d'"' -f2)
ynh_app_setting_set --app "$app" --key seahub_secret_key --value "$seahub_secret_key"
# Update seafile config files
ynh_add_config --template=seahub_settings.py --destination=$install_dir/conf/seahub_settings.py
@ -83,10 +75,27 @@ ynh_add_config --template=seafdav.conf --destination=$install_dir/conf/seafdav.c
# Configure admin info
# It will be used the first start
admin_email=$(ynh_user_get_info --username $admin --key 'mail')
admin_email=$(ynh_user_get_info --username "$admin" --key 'mail')
cp ../conf/create_admin.json $install_dir/conf/admin.txt
ynh_replace_string --match_string __ADMIN__ --replace_string $admin_email --target_file $install_dir/conf/admin.txt
ynh_replace_special_string --match_string __PASSWORD__ --replace_string $admin_password --target_file $install_dir/conf/admin.txt
ynh_replace_string --match_string __ADMIN__ --replace_string "$admin_email" --target_file $install_dir/conf/admin.txt
ynh_replace_special_string --match_string __PASSWORD__ --replace_string "$admin_password" --target_file $install_dir/conf/admin.txt
# Use symlink to store data
if [ -e "$install_dir"/seafile-data ]; then
mv -t "$data_dir"/seafile-data "$install_dir"/seafile-data/*
ynh_secure_remove --file="$install_dir"/seafile-data
fi
if [ -e "$install_dir"/seahub-data ]; then
mv -t "$data_dir"/seahub-data "$install_dir"/seahub-data/*
ynh_secure_remove --file="$install_dir"/seahub-data
fi
if [ -e "$install_dir"/logs ]; then
mv -t /var/log/"$app" "$install_dir"/logs/*
ynh_secure_remove --file="$install_dir"/logs
fi
ln -s "$data_dir"/seafile-data "$install_dir"/seafile-data
ln -s "$data_dir"/seahub-data "$install_dir"/seahub-data
ln -s /var/log/"$app" "$install_dir"/logs
# Fix local warning
ynh_replace_string --match_string en_US.UTF-8 --replace_string ${LANG:-'en_US.UTF-8'} --target_file $install_dir/seafile-server-$seafile_version/seahub.sh
@ -106,8 +115,7 @@ ynh_add_nginx_config
# Add logrotate
ynh_script_progression --message="Configuring log rotation..."
ynh_use_logrotate --logfile $install_dir/logs
ln -s $install_dir/logs /var/log/seafile
ynh_use_logrotate --logfile=/var/log/"$app"
# Add fail2ban
ynh_script_progression --message="Configuring fail2ban..."

View file

@ -11,6 +11,8 @@ source ./_common.sh
# Source YunoHost helpers
source /usr/share/yunohost/helpers
seafile_version=$(ynh_app_upstream_version)
#=================================================
# STANDARD REMOVE
#=================================================

View file

@ -11,6 +11,8 @@ source ../settings/scripts/_common.sh
# Source YunoHost helpers
source /usr/share/yunohost/helpers
seafile_version=$(ynh_app_upstream_version)
ynh_script_progression --message="Loading settings..."
# Retrieve arguments

View file

@ -11,36 +11,19 @@ source ./_common.sh
# Source YunoHost helpers
source /usr/share/yunohost/helpers
# Retrieve arguments
installed_version=${YNH_APP_CURRENT_VERSION/~ynh*/}
seafile_version=$(ynh_app_upstream_version)
# Create special path with / at the end
if [[ $path == '/' ]]
then
path2=$path
else
path2=$path"/"
fi
# Retrieve arguments
installed_version=${YNH_APP_CURRENT_VERSION/~ynh*/}
if [ "$YNH_APP_CURRENT_VERSION" == '-' ]; then
if [ "$YNH_APP_CURRENT_VERSION" == '-' ] || ynh_compare_current_package_version --comparison=le --version='7.0~ynh1'; then
ynh_die "Upgrade from this version not supported"
fi
ynh_script_progression --message="Stoping services..."
# stop seafile server
if [ -e /etc/init.d/seafile-server ]
then
# Old init script support
systemctl stop seafile-server --quiet
systemctl disable seafile-server --quiet
ynh_secure_remove --file=/etc/init.d/seafile-server
yunohost service remove seafile-server
else
ynh_systemd_action --service_name seafile --action stop
ynh_systemd_action --service_name seahub --action stop
fi
ynh_systemd_action --service_name seafile --action stop
ynh_systemd_action --service_name seahub --action stop
sleep 5
pkill -f seafile-controller || true
pkill -f seaf-server || true
@ -56,34 +39,66 @@ if mysqlshow | grep -q seafiledb; then
$mysqlconn -e "RENAME TABLE seafiledb.$name to $db_name.$name";
done;
$mysqlconn -e "DROP DATABASE seafiledb"
ynh_replace_string --match_string='db_name = seafiledb' --replace_string='db_name = seafile' --target_file=$install_dir/conf/seafile.conf
sed -i "s|password\s*=\s*.*^|password = $db_pwd|g" $install_dir/conf/seafile.conf
ynh_replace_string --match_string='db_name = seafiledb' --replace_string='db_name = seafile' --target_file="$install_dir"/conf/seafile.conf
sed -i "s|password\s*=\s*.*^|password = $db_pwd|g" "$install_dir"/conf/seafile.conf
fi
# Set missing settings
if [ -z ${seahub_secret_key:-} ]; then
seahub_secret_key=$(grep -P 'SECRET_KEY\s*=\s*".+"' $install_dir/conf/seahub_settings.py | cut -d'"' -f2)
ynh_app_setting_set --app $app --key seahub_secret_key --value $seahub_secret_key
if [ -z "${seahub_secret_key:-}" ]; then
seahub_secret_key=$(grep -P 'SECRET_KEY\s*=\s*".+"' "$install_dir"/conf/seahub_settings.py | cut -d'"' -f2)
ynh_app_setting_set --app "$app" --key seahub_secret_key --value "$seahub_secret_key"
fi
#
# Update data dir if needed
#
# Create link to /home/yunohost.app/seafile/seafile-data in case of old install with data dir defined in config instead of symlink
# Also update link if not pointing to correct path
if [ ! -L /home/yunohost.app/seafile-data ] || \
[ $(readlink $install_dir/seafile-data) = '/home/yunohost.app/seafile-data' ]; then
mv $install_dir/seafile-data $install_dir/seafile-data$(date '+%Y%m%d.%H%M%S')
ln -s $data_dir $install_dir/seafile-data
[ "$(readlink "$install_dir"/seafile-data)" != "$data_dir/seafile-data" ]; then
mv "$install_dir"/seafile-data "$install_dir/seafile-data_$(date '+%Y%m%d.%H%M%S')"
ln -s "$data_dir"/seafile-data "$install_dir"/seafile-data
fi
# Move if needed old /home/yunohost.app/seafile-data dir to /home/yunohost.app/seafile/seafile-data
if [ -e /home/yunohost.app/seafile-data ]; then
if [ -e $data_dir ]; then
mv $data_dir $data_dir$(date '+%Y%m%d.%H%M%S')
if [ -e "$data_dir" ]; then
mv "$data_dir" "${data_dir}_$(date '+%Y%m%d.%H%M%S')"
fi
mv /home/yunohost.app/seafile-data $data_dir
mkdir -p "$data_dir"
mv /home/yunohost.app/seafile-data "$data_dir"/
fi
# In case of seafile-data content was directly stored in /home/yunohost.app/seafile
if [ -e "$data_dir"/storage ]; then
mkdir -p "$data_dir"/seafile-data
mv -t "$data_dir"/seafile-data "$data_dir"/{commits,fs,httptemp,library-template,storage,tmpfiles,webdavtmp} || true # In case of some of dir don't exist
fi
# Move seahub data to /home/yunohost.app/seafile/seahub-data
if [ ! -L "$install_dir"/seahub-data ]; then
if [ -e "$data_dir"/seahub-data ]; then
mv "$data_dir"/seahub-data "$data_dir/seahub-data_$(date '+%Y%m%d.%H%M%S')"
fi
mv "$install_dir"/seahub-data "$data_dir"/
ln -s "$data_dir"/seahub-data "$install_dir"/seahub-data
fi
# Move logs storage to /var/log/seafile
if [ ! -L "$install_dir"/logs ]; then
if [ -e /var/log/"$app" ]; then
mv /var/log/"$app" /var/log/"${app}_$(date '+%Y%m%d.%H%M%S')"
fi
mv "$install_dir"/logs /var/log/"${app}"
ln -s /var/log/"${app}" "$install_dir"/logs
fi
ynh_script_progression --message="Upgrading source files..." --weight=6
# Download new version from sources
ynh_script_progression --message="Installing sources files..." --weight=7
ynh_setup_source --dest_dir=$install_dir/seafile-server-$seafile_version
ynh_setup_source --dest_dir="$install_dir"/seafile-server-$seafile_version
ynh_script_progression --message="Installing python dependancies..."
install_dependance
@ -171,7 +186,7 @@ set_permission
# Add logrotate
ynh_script_progression --message="Configuring log rotation..."
ynh_use_logrotate --logfile $install_dir/logs --nonappend
ynh_use_logrotate --logfile=/var/log/"$app" --nonappend
# Add fail2ban
ynh_script_progression --message="Configuring fail2ban..." --weight=10