Commit 160bffae authored by root's avatar root

Finish remove script

allow for restore by not letting it fail. next step is to check out the restore and backup
parent c8b226ac
......@@ -24,13 +24,13 @@ Mobile clients that are known to work well:
I'm using this package as a way to learn packaging for yunohost. This package is far from perfect and should not be used on production servers. If you have recommendations, please let me know on the fediverse at `@Ilja@mastodon.pirateparty.be`
What should work:
* Installation (I made changes that need still testing atm)
* Installation
* Removal
* Backup (Should check if it still works properly with the last changes)
* Restore (You'll need to remove the instance prior to restore. This should change in the future.)
What does not work:
* upgrade
* upgrade (there's only a very naive implementation atm)
* Change URL (this is technically impossible at this time due to the nature of federation)
What is not implemented:
......@@ -40,20 +40,18 @@ What is not implemented:
Extra info:
* Multiple installs are possible
* On installation you can choose to enable scopes on the Pleroma-FE
* You can choose to close regstrations on installation, but then you'll need to create invite tokens if you want others to join your instance as well. You can do this by accessing your yunohost server over ssh and run `cd /var/www/pleroma/pleroma/ && MIX_ENV=prod mix generate_invite_token`. See: https://git.pleroma.social/pleroma/pleroma/wikis/Admin%20tasks
* On installation you'll be able to chose a dedicated domain for Pleroma. You'll also be asked for a username and password for a user. This user will have moderator rights. Note that the password will be visible if you install using the `--debug` flag!
* Pleroma will be listed in the admin-panel under services, so you can stop and start the service there
* Postgresql will also be listed in the admin-panel
* You can choose to close regstrations on installation, but then you'll need to create invite tokens if you want others to join your instance as well. You can do this by accessing your yunohost server over ssh and run `cd /var/www/pleroma/pleroma/ && MIX_ENV=prod mix generate_invite_token`. See: https://git.pleroma.social/pleroma/pleroma/wikis/Admin%20tasks
* On installation you can choose to enable scopes on the Pleroma-FE
* If you're not afraid of the terminal, check out https://git.pleroma.social/pleroma/pleroma/wikis/home to see what more you can do with your awesome instance!
* You can upgrade your Pleroma instance by logging in over ssh as root and run `su - pleroma -c "cd /var/www/pleroma/pleroma;git pull;MIX_ENV=prod mix deps.get;MIX_ENV=prod mix ecto.migrate;" && systemctl restart pleroma`
* To check your current Pleroma version you can go to `yourdomain.tld/api/v1/instance`
TODO:
* Make generate_config more elegant
* check logrotate
* Make the remove more elegant (esp the removal of the DB)
* Make backup and restore work as expected
* Use psql helpers for backup/restore if possible
* Make update work properly (atm there's only a very naive implementation)
* Check with linter/community... to add to the community packages
* Check with linter/community... to add this to the community packages
......@@ -22,10 +22,6 @@ ynh_delete_file_checksum () {
# usage: ynh_string_random [length]
# | arg: length - the string length to generate (default: 24)
ynh_string_random() {
str=''
while [ ${#str} -lt ${1:-24} ]; do
str=$str$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9');
done
echo $str | sed -n 's/\(.\{'"${1:-24}"'\}\).*/\1/p'
cat /dev/urandom | tr -c -d 'A-Za-z0-9' | head -c ${1:-24}
}
......@@ -6,8 +6,8 @@
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
source _common.sh
#=================================================
# LOAD SETTINGS
......@@ -25,7 +25,8 @@ db_name=$(ynh_app_setting_get $app db_name)
# STOP AND REMOVE SERVICE
#=================================================
# Remove the dedicated systemd config
ynh_print_info "Disable systemd and removing config"
systemctl stop $app
ynh_remove_systemd_config
systemctl disable $app
rm /etc/systemd/system/$app.service
......@@ -47,7 +48,9 @@ fi
# REMOVE THE DATABASE
#=================================================
PLSQL_HOME= #get postgres user home
ynh_print_info "Removing database"
PLSQL_HOME=$(su - postgres -c "pwd")
cp -rf "./_remove_db.sql" "$PLSQL_HOME/drop_$db_name.psql"
ynh_replace_string "{APP}" "$app" "$PLSQL_HOME/drop_$db_name.psql"
ynh_replace_string "{DB_NAME}" "$db_name" "$PLSQL_HOME/drop_$db_name.psql"
......@@ -55,51 +58,29 @@ chown postgres: $PLSQL_HOME/drop_$db_name.psql
su - postgres -c "psql -f drop_$db_name.psql"
rm $PLSQL_HOME/drop_$db_name.psql
# TODO: old way in case previous didn't work
su - postgres -c "
touch drop_$db_name.psql
> drop_$db_name.psql
echo 'SELECT pg_terminate_backend(pg_stat_activity.pid)' >> drop_$db_name.psql
echo FROM pg_stat_activity >> drop_$db_name.psql
echo WHERE pg_stat_activity.datname = \'$db_name\' >> drop_$db_name.psql
echo ' AND pid <> pg_backend_pid();' >> drop_$db_name.psql
echo 'REVOKE ALL PRIVILEGES ON ALL TABLES IN $db_name public FROM $app;' >> drop_$db_name.psql
echo 'REVOKE ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public FROM $app;' >> drop_$db_name.psql
echo 'REVOKE ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA public FROM $app;' >> drop_$db_name.psql
echo 'REVOKE ALL PRIVILEGES ON SCHEMA public FROM $app;' >> drop_$db_name.psql
echo 'DROP DATABASE IF EXISTS $db_name;' >> drop_$db_name.psql
echo 'DROP USER $app;' >> drop_$db_name.psql
psql -f drop_$db_name.psql
rm drop_$db_name.psql
"
#=================================================
# REMOVE APP MAIN DIR
#=================================================
ynh_print_info "Removing main directory"
ynh_secure_remove "$final_path"
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_print_info "Removing nginx configuration"
ynh_remove_nginx_config
rm /etc/nginx/conf.d/$app-cache.conf
#=================================================
# REMOVE LOGROTATE CONFIGURATION
#=================================================
# Remove the app-specific logrotate config
#ynh_remove_logrotate
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_print_info "Removing dependencies"
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
......@@ -112,14 +93,13 @@ ynh_remove_app_dependencies
# Remove the log files
ynh_secure_remove "/var/log/$app/"
# Remove the app folder
rm -rf "$final_path"
#=================================================
# GENERIC FINALIZATION
#=================================================
# REMOVE DEDICATED USER
#=================================================
# Delete the system user
userdel -f $app
ynh_print_info "Removing system user"
ynh_system_user_delete $app
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
final_path=$(ynh_app_setting_get $app final_path)
db_name=$(ynh_app_setting_get $app db_name)
#=================================================
# STANDARD REMOVE
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
# Remove the dedicated systemd config
ynh_remove_systemd_config
systemctl disable $app
rm /etc/systemd/system/$app.service
rm /etc/systemd/system/$app.service.d
rm /usr/lib/systemd/system/$app.service
rm /usr/lib/systemd/system/$app.service.d
#=================================================
# REMOVE SERVICE FROM ADMIN PANEL
#=================================================
if yunohost service status | grep -q $app
then
echo "Remove $app service"
yunohost service remove $app
fi
#=================================================
# REMOVE THE DATABASE
#=================================================
PLSQL_HOME= #get postgres user home
cp -rf "./_remove_db.sql" "$PLSQL_HOME/drop_$db_name.psql"
ynh_replace_string "{APP}" "$app" "$PLSQL_HOME/drop_$db_name.psql"
ynh_replace_string "{DB_NAME}" "$db_name" "$PLSQL_HOME/drop_$db_name.psql"
chown postgres: $PLSQL_HOME/drop_$db_name.psql
su - postgres -c "psql -f drop_$db_name.psql"
rm $PLSQL_HOME/drop_$db_name.psql
# TODO: old way in case previous didn't work
su - postgres -c "
touch drop_$db_name.psql
> drop_$db_name.psql
echo 'SELECT pg_terminate_backend(pg_stat_activity.pid)' >> drop_$db_name.psql
echo FROM pg_stat_activity >> drop_$db_name.psql
echo WHERE pg_stat_activity.datname = \'$db_name\' >> drop_$db_name.psql
echo ' AND pid <> pg_backend_pid();' >> drop_$db_name.psql
echo 'REVOKE ALL PRIVILEGES ON ALL TABLES IN $db_name public FROM $app;' >> drop_$db_name.psql
echo 'REVOKE ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public FROM $app;' >> drop_$db_name.psql
echo 'REVOKE ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA public FROM $app;' >> drop_$db_name.psql
echo 'REVOKE ALL PRIVILEGES ON SCHEMA public FROM $app;' >> drop_$db_name.psql
echo 'DROP DATABASE IF EXISTS $db_name;' >> drop_$db_name.psql
echo 'DROP USER $app;' >> drop_$db_name.psql
psql -f drop_$db_name.psql
rm drop_$db_name.psql
"
#=================================================
# REMOVE APP MAIN DIR
#=================================================
ynh_secure_remove "$final_path"
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_remove_nginx_config
rm /etc/nginx/conf.d/$app-cache.conf
#=================================================
# REMOVE LOGROTATE CONFIGURATION
#=================================================
# Remove the app-specific logrotate config
#ynh_remove_logrotate
#=================================================
# REMOVE DEPENDENCIES
#=================================================
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
#=================================================
# SPECIFIC REMOVE
#=================================================
# REMOVE THE CRON FILE
#=================================================
# Remove the log files
ynh_secure_remove "/var/log/$app/"
# Remove the app folder
rm -rf "$final_path"
#=================================================
# GENERIC FINALIZATION
#=================================================
# REMOVE DEDICATED USER
#=================================================
# Delete the system user
userdel -f $app
#!/bin/bash
# yunohost backup --debug restore 20180908-191040
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
if [ ! -e _common.sh ]; then
# Get the _common.sh file if it's not in the current directory
cp ../settings/scripts/_common.sh ./_common.sh
chmod a+rx _common.sh
fi
source _common.sh
source /usr/share/yunohost/helpers
source _common.sh
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
......@@ -30,16 +23,24 @@ app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get $app final_path)
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path_url)
port=$(ynh_app_setting_get $app port)
db_name=$(ynh_app_setting_get $app db_name)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_webpath_available $domain / \
|| ynh_die "Path not available: ${domain}${path_url}"
test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path "
test ! -e "$final_path" || ynh_die "This path already contains a folder"
# Check web path availability
ynh_webpath_available $domain $path_url
# Register (book) web path
# ynh_webpath_register $app $domain $path_url
# Check if port is still free
test $port = $(ynh_find_port $port) || ynh_die "Port $port is no longer available"
# TODO: use different port when needed
#=================================================
# STANDARD MODIFICATIONS
......@@ -47,6 +48,11 @@ test ! -d $final_path \
# INSTALL DEPENDENCIES
#=================================================
ynh_print_info "Installing dependencies"
# In case https capability for apt insn't installed yet
apt-get install --yes apt-transport-https
if ! [ -e /etc/apt/sources.list.d/erlang-solutions.list ]
then
mkdir --parents /etc/apt/sources.list.d/
......@@ -57,11 +63,12 @@ then
rm erlang_solutions.asc
fi
apt-get update
ynh_install_app_dependencies git build-essential postgresql-9.6 postgresql-contrib-9.6 elixir erlang-dev erlang-parsetools erlang-xmerl erlang-tools esl-erlang
ynh_install_app_dependencies git build-essential postgresql postgresql-contrib elixir erlang-dev erlang-parsetools erlang-xmerl erlang-tools
#=================================================
# RECREATE DEDICATED USER
#=================================================
mkdir --parents $final_path
useradd $app --home-dir=$final_path
......@@ -76,7 +83,11 @@ chown -R $app: $final_path
# RESTORE THE POSTGRESQL DATABASE
#=================================================
ynh_print_info "Setting up the database"
# Fail installation if database already exists
! su - postgres -c "psql -lqt" | cut -d \| -f 1 | grep -ws $db_name || ynh_die "The database $db_name already exists"
chown postgres $final_path/backup
su - postgres -c "psql -f $final_path/pleroma/config/setup_db.psql"
su - postgres -c "psql $db_name < $final_path/backup/$db_name.sql"
......@@ -87,9 +98,13 @@ su - postgres -c "psql $db_name < $final_path/backup/$db_name.sql"
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_print_info "Final configurations"
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_restore_file "/etc/nginx/conf.d/$app-cache.conf"
systemctl reload nginx
#=================================================
# RESTORE SYSTEMD
#=================================================
......@@ -104,13 +119,8 @@ systemctl enable --now $app.service
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
yunohost service add $app --log "/var/log/$app/APP.log"
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
#ynh_restore_file "/etc/logrotate.d/$app"
yunohost service add $app
yunohost service add postgresql
#=================================================
# SETUP SSOWAT
......@@ -123,11 +133,12 @@ ynh_app_setting_set $app skipped_uris "/"
# FINALIZATION
#=================================================
systemctl reload nginx
ynh_print_info "Sending love to Lain"
# Restart 'cause I always have an internal server error the first time.
sleep 10
systemctl restart nginx
systemctl restart $app
echo "If you're not afraid of the terminal, check out https://git.pleroma.social/pleroma/pleroma/wikis/home to see what more you can do with your awesome instance!"
ynh_print_info "If you're not afraid of the terminal, check out https://git.pleroma.social/pleroma/pleroma/wikis/home to see what more you can do with your awesome instance!"
......@@ -9,7 +9,8 @@
source _common.sh
source /usr/share/yunohost/helpers
echo '/!\'" Upgrade hasn't been tested yet "'/!\'
ynh_print_info '/!\'" Upgrade hasn't been tested yet "'/!\'
ynh_print_info 'nieuwe ding'
#=================================================
# LOAD SETTINGS
......@@ -42,11 +43,11 @@ db_name=$(ynh_app_setting_get $app db_name)
#=================================================
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
#ynh_backup_before_upgrade
#ynh_clean_setup () {
# restore it if the upgrade fails
ynh_restore_upgradebackup
}
# ynh_restore_upgradebackup
#}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
......@@ -63,11 +64,11 @@ path_url=$(ynh_normalize_url_path $path_url)
# PULL CHANGES AND SPECIFIC SETUP
#=================================================
su - $app -c "cd $final_path/pleroma;git pull;MIX_ENV=prod mix deps.get;MIX_ENV=prod mix ecto.migrate;"
# su - $app -c "cd $final_path/pleroma;git pull;MIX_ENV=prod mix deps.get;MIX_ENV=prod mix ecto.migrate;"
#=================================================
# RESTART PLEROMA
#=================================================
systemctl restart $app
# systemctl restart $app
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment