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.en = "Open Source Cloud Storage"
description.fr = "Stockage Cloud Open Source" description.fr = "Stockage Cloud Open Source"
version = "9.0.9~ynh2" version = "9.0.9~ynh3"
maintainers = ["Josué Tille"] maintainers = ["Josué Tille"]

View file

@ -5,6 +5,14 @@
time_zone=$(cat /etc/timezone) time_zone=$(cat /etc/timezone)
python_version="$(python3 -V | cut -d' ' -f2 | cut -d. -f1-2)" 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 # DEFINE ALL COMMON FONCTIONS
#================================================= #=================================================

View file

@ -11,6 +11,8 @@ source ../settings/scripts/_common.sh
# Source YunoHost helpers # Source YunoHost helpers
source /usr/share/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 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'" 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 fi

View file

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

View file

@ -13,29 +13,22 @@ source /usr/share/yunohost/helpers
seafile_version=$(ynh_app_upstream_version) seafile_version=$(ynh_app_upstream_version)
# Create special path with / at the end
if [[ $path == '/' ]]
then
path2=$path
else
path2=$path"/"
fi
#================================================= #=================================================
# STANDARD MODIFICATIONS # STANDARD MODIFICATIONS
#================================================= #=================================================
ynh_script_progression --message="Creating base directory..." 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')" 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" 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"/* mv -t "$old_data_dir_path" "$data_dir"/*
fi fi
mkdir -p /var/log/"$app"
mkdir -p "$data_dir"/{seafile-data,seahub-data}
# Download new version from sources # Download new version from sources
ynh_script_progression --message="Installing sources files..." --weight=7 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
@ -46,9 +39,8 @@ install_dependance
# init databases # init databases
ynh_script_progression --message="Configuring MySQL database..." ynh_script_progression --message="Configuring MySQL database..."
db_user=seafile db_user=seafile
db_helper=ynh_"mysql"_setup_db ynh_''mysql_setup_db --db_user "$db_user" --db_name ccnetdb --db_pwd "$db_pwd"
$db_helper --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"
$db_helper --db_user $db_user --db_name seahubdb --db_pwd "$db_pwd"
ynh_script_progression --message="Configuring application..." --weight=3 ynh_script_progression --message="Configuring application..." --weight=3
@ -56,23 +48,23 @@ ynh_script_progression --message="Configuring application..." --weight=3
set_permission set_permission
ynh_replace_special_string --match_string 'seafile_config.seafile_dir = seafile_config.validate_seafile_dir(seafile_dir)' \ 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' \ --replace_string 'seafile_config.seafile_dir = seafile_dir' \
--target_file $install_dir/seafile-server-$seafile_version/setup-seafile-mysql.py --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 \ sudo -u "$app" bash "$install_dir/seafile-server-$seafile_version/setup-seafile-mysql.sh" auto \
--server-name "$server_name" \ --server-name "$server_name" \
--server-ip $domain \ --server-ip "$domain" \
--fileserver-port $port_fileserver \ --fileserver-port "$port_fileserver" \
--use-existing-db 1 \ --use-existing-db 1 \
--mysql-host localhost \ --mysql-host localhost \
--mysql-port 3306 \ --mysql-port 3306 \
--mysql-user $db_user \ --mysql-user "$db_user" \
--mysql-user-passwd "$db_pwd" \ --mysql-user-passwd "$db_pwd" \
--seafile-db "$db_name" \ --seafile-db "$db_name" \
--ccnet-db ccnetdb \ --ccnet-db ccnetdb \
--seahub-db seahubdb --seahub-db seahubdb
# Retrive values from auto generated config file # 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) 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 ynh_app_setting_set --app "$app" --key seahub_secret_key --value "$seahub_secret_key"
# Update seafile config files # Update seafile config files
ynh_add_config --template=seahub_settings.py --destination=$install_dir/conf/seahub_settings.py 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 # Configure admin info
# It will be used the first start # 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 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_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_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 # 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 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 # Add logrotate
ynh_script_progression --message="Configuring log rotation..." ynh_script_progression --message="Configuring log rotation..."
ynh_use_logrotate --logfile $install_dir/logs ynh_use_logrotate --logfile=/var/log/"$app"
ln -s $install_dir/logs /var/log/seafile
# Add fail2ban # Add fail2ban
ynh_script_progression --message="Configuring fail2ban..." ynh_script_progression --message="Configuring fail2ban..."

View file

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

View file

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

View file

@ -11,36 +11,19 @@ source ./_common.sh
# Source YunoHost helpers # Source YunoHost helpers
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
# Retrieve arguments
installed_version=${YNH_APP_CURRENT_VERSION/~ynh*/}
seafile_version=$(ynh_app_upstream_version) seafile_version=$(ynh_app_upstream_version)
# Create special path with / at the end # Retrieve arguments
if [[ $path == '/' ]] installed_version=${YNH_APP_CURRENT_VERSION/~ynh*/}
then
path2=$path
else
path2=$path"/"
fi
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" ynh_die "Upgrade from this version not supported"
fi fi
ynh_script_progression --message="Stoping services..." ynh_script_progression --message="Stoping services..."
# stop seafile server ynh_systemd_action --service_name seafile --action stop
if [ -e /etc/init.d/seafile-server ] ynh_systemd_action --service_name seahub --action stop
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
sleep 5 sleep 5
pkill -f seafile-controller || true pkill -f seafile-controller || true
pkill -f seaf-server || 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"; $mysqlconn -e "RENAME TABLE seafiledb.$name to $db_name.$name";
done; done;
$mysqlconn -e "DROP DATABASE seafiledb" $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 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 sed -i "s|password\s*=\s*.*^|password = $db_pwd|g" "$install_dir"/conf/seafile.conf
fi fi
# Set missing settings # Set missing settings
if [ -z ${seahub_secret_key:-} ]; then if [ -z "${seahub_secret_key:-}" ]; then
seahub_secret_key=$(grep -P 'SECRET_KEY\s*=\s*".+"' $install_dir/conf/seahub_settings.py | cut -d'"' -f2) 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 ynh_app_setting_set --app "$app" --key seahub_secret_key --value "$seahub_secret_key"
fi fi
#
# Update data dir if needed # 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 ] || \ if [ ! -L /home/yunohost.app/seafile-data ] || \
[ $(readlink $install_dir/seafile-data) = '/home/yunohost.app/seafile-data' ]; then [ "$(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') mv "$install_dir"/seafile-data "$install_dir/seafile-data_$(date '+%Y%m%d.%H%M%S')"
ln -s $data_dir $install_dir/seafile-data ln -s "$data_dir"/seafile-data "$install_dir"/seafile-data
fi 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 /home/yunohost.app/seafile-data ]; then
if [ -e $data_dir ]; then if [ -e "$data_dir" ]; then
mv $data_dir $data_dir$(date '+%Y%m%d.%H%M%S') mv "$data_dir" "${data_dir}_$(date '+%Y%m%d.%H%M%S')"
fi 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 fi
ynh_script_progression --message="Upgrading source files..." --weight=6 ynh_script_progression --message="Upgrading source files..." --weight=6
# Download new version from sources # Download new version from sources
ynh_script_progression --message="Installing sources files..." --weight=7 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..." ynh_script_progression --message="Installing python dependancies..."
install_dependance install_dependance
@ -171,7 +186,7 @@ set_permission
# Add logrotate # Add logrotate
ynh_script_progression --message="Configuring log rotation..." 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 # Add fail2ban
ynh_script_progression --message="Configuring fail2ban..." --weight=10 ynh_script_progression --message="Configuring fail2ban..." --weight=10