1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/diaspora_ynh.git synced 2024-09-03 18:26:13 +02:00

Merge pull request #19 from YunoHost-Apps/testing

This commit is contained in:
Augustin Trancart 2020-05-21 16:16:34 +02:00 committed by GitHub
commit c27edb1f7d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 275 additions and 132 deletions

View file

@ -1,7 +1,8 @@
diaspora_ynh
==========
[![Integration level](https://dash.yunohost.org/integration/diaspora.svg)](https://dash.yunohost.org/appci/app/diaspora) ![](https://ci-apps.yunohost.org/ci/badges/diaspora.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/diaspora.maintain.svg)
[![Integration level](https://dash.yunohost.org/integration/diaspora.svg)](https://dash.yunohost.org/appci/app/diaspora) ![](https://ci-apps.yunohost.org/ci/badges/diaspora.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/diaspora.maintain.svg)[![Shipped version](https://img.shields.io/github/v/release/yunohost-apps/diaspora_ynh)](https://github.com/yunohost-apps/diaspora_ynh/releases)
[![Install diaspora with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=diaspora)
## Overview
@ -25,7 +26,4 @@ Installation effects:
- The installation directory can take up to 900MB and app start time can be take 5 minutes
**TODO**
* Add restore script
Report a bug: https://github.com/YunoHost-Apps/diaspora_ynh/issues

View file

@ -10,11 +10,11 @@
setup_root=1
setup_nourl=0
upgrade=1
# upgrade=1 from_commit=CommitHash
backup_restore=0
upgrade=1 from_commit=0.7.13.0-ynh1
backup_restore=1
multi_instance=1
port_already_use=0
change_url=0
change_url=0 # not supported upstream
;;; Levels
# If the level 5 (Package linter) is forced to 1. Please add justifications here.
Level 5=auto

View file

@ -1,5 +1,5 @@
[Unit]
Description=Diaspora social network (instance {{ app}})
Description=Diaspora social network (instance __APP__)
Wants=redis.service postgresql.service
After=redis.service postgresql.service

View file

@ -1 +1 @@
d /run/{{ app }} 0755 {{ app }} {{ app }} - -
d /run/__APP__ 0755 __APP__ __APP__ - -

View file

@ -1,13 +1,13 @@
[Unit]
Description=Diaspora social network (sidekiq - instance {{ app }})
PartOf={{ app }}.target
Description=Diaspora social network (sidekiq - instance __APP__)
PartOf=__APP__.target
[Service]
User={{ app }}
User=__APP__
Environment=RAILS_ENV=production
WorkingDirectory={{ final_path }}/diaspora
WorkingDirectory=__FINALPATH__/diaspora
ExecStart=/bin/bash -lc "bin/bundle exec sidekiq"
Restart=always
[Install]
WantedBy={{ app }}.target
WantedBy=__APP__.target

View file

@ -1,15 +1,15 @@
[Unit]
Description=Diaspora social network (unicorn - instance {{ app }})
PartOf={{ app }}.target
Description=Diaspora social network (unicorn - instance __APP__)
PartOf=__APP__.target
[Service]
User={{ app }}
User=__APP__
Environment=RAILS_ENV=production
WorkingDirectory={{ final_path }}/diaspora
PIDFile=/run/{{ app }}/diaspora.pid
WorkingDirectory=__FINALPATH__/diaspora
PIDFile=/run/__APP__/diaspora.pid
ExecStart=/bin/bash -lc "bin/bundle exec unicorn -c config/unicorn.rb -E production"
ExecReload=/bin/kill -USR2 $MAINPID
Restart=always
[Install]
WantedBy={{ app }}.target
WantedBy=__APP__.target

23
scripts/bundle_app Normal file
View file

@ -0,0 +1,23 @@
#!/bin/bash
pushd $final_path/diaspora
# here we *absolutely* need bash (not dash) because dash does not understand what rvm puts in .profile
# (wtf rvm for assuming everybody uses bash as default shell??)
# we also need a login shell to make sure .profile is loaded
sudo -u $app /bin/bash --login << EOF
rvm use --default 2.4
rvm 2.4 do gem install bundler:1.17.3
script/configure_bundler
bin/bundle install --full-index --with=postgresql
EOF
sudo -u $app /bin/bash --login << EOF
RAILS_ENV=production bundle exec rake db:migrate
EOF
#=================================================
# ASSETS PRECOMPILATION
#=================================================
sudo -u $app /bin/bash --login << EOF
RAILS_ENV=production bin/rake assets:precompile
EOF
popd

40
scripts/create_services Normal file
View file

@ -0,0 +1,40 @@
#!/bin/bash
# sidekiq
echo $app $final_path
install -T --mode=0644 -v ../conf/diaspora_sidekiq.service /etc/systemd/system/${app}_sidekiq.service
ynh_replace_string --match_string=__APP__ --replace_string=$app --target_file=/etc/systemd/system/${app}_sidekiq.service
ynh_replace_string --match_string=__FINALPATH__ --replace_string=$final_path --target_file=/etc/systemd/system/${app}_sidekiq.service
# web
install -T --mode=0644 -v ../conf/diaspora_web.service /etc/systemd/system/${app}_web.service
ynh_replace_string --match_string=__APP__ --replace_string=$app --target_file=/etc/systemd/system/${app}_web.service
ynh_replace_string --match_string=__FINALPATH__ --replace_string=$final_path --target_file=/etc/systemd/system/${app}_web.service
# tmp files
install -T --mode=0644 -v ../conf/diaspora.tmpfiles.d /etc/tmpfiles.d/${app}.conf
ynh_replace_string --match_string=__APP__ --replace_string=$app --target_file=/etc/tmpfiles.d/${app}.conf
# target unit
install -T --mode=0644 -v ../conf/diaspora.target /etc/systemd/system/${app}.target
ynh_replace_string --match_string=__APP__ --replace_string=$app --target_file=/etc/systemd/system/${app}.target
# reload, create, enable and start stuff
systemctl daemon-reload
systemd-tmpfiles --create
systemctl enable ${app}.target ${app}_sidekiq.service ${app}_web.service
systemctl restart ${app}.target
# wait for startup
timeout=100
for i in $(seq 1 $timeout)
do
# Read the log until the sentence is found, that means the app finished to start. Or run until the timeout
if grep --extended-regexp --quiet "listening on addr" "$final_path/diaspora/log/unicorn-stderr.log"
then
ynh_print_info --message="Diaspora* is up and running\!"
break
fi
if [ $i -eq 3 ]; then
echo -n "Please wait, diaspora* is starting" >&2
fi
if [ $i -ge 3 ]; then
echo -n "." >&2
fi
sleep 1
done

View file

@ -2,9 +2,17 @@
# TODO
# - which service to register to ynuhosto? diaspora.target only ? All of them ?
# - backup / restore
# - a setting to enable / disable registration
# - say something about the registration to https://the-federation.info/
# - ...
## vars for remove script
can_remove_db=0
can_remove_home=0
can_remove_user=0
# flag to make clean_setup display rvm log if rvm build has failed
should_display_rvm_log=0
#=================================================
# GENERIC START
@ -18,8 +26,13 @@ source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_clean_setup() {
# print rvm logs
if [ $should_display_rvm_log -eq 1 ]; then
find $final_path/.rvm/log/ -name make.log -exec cat {} \;
fi
}
ynh_abort_if_errors
#=================================================
@ -31,29 +44,18 @@ admin=$YNH_APP_ARG_ADMIN
admin_password=$YNH_APP_ARG_ADMIN_PASSWORD
admin_email=$(ynh_user_get_info --username=$admin --key=mail)
# 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
final_path=/var/www/$app
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..." --weight=1
# Check web path availability
ynh_webpath_available --domain=$domain --path_url=/
# check path availability
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
can_remove_home=1
# Register (book) web path
ynh_webpath_register --app=$app --domain=$domain --path_url=/
@ -76,14 +78,13 @@ ynh_script_progression --message="Installing dependencies..." --weight=27
ynh_install_app_dependencies $pkg_dependencies $ruby_build_dependencies
#=================================================
# CREATE A POSTGRESQL DATABASE
# CHECK DB AVAILABILITY
#=================================================
ynh_script_progression --message="Creating database..." --weight=1
db_name=$(ynh_sanitize_dbid $app)
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_psql_test_if_first_run
ynh_psql_setup_db $db_name $db_name
db_pass=$(ynh_app_setting_get --app=$app --key=psqlpwd)
ynh_script_progression --message="Check DB availability"
# now that we have psql for sure, test db existence
ynh_script_progression --message="Checking DB availability" --weight=1
ynh_psql_database_exists --database $app && ynh_die --message="There is already a database: $app"
can_remove_db=1
#=================================================
# CREATE DEDICATED USER
@ -91,30 +92,36 @@ db_pass=$(ynh_app_setting_get --app=$app --key=psqlpwd)
ynh_script_progression --message="Creating user..." --weight=1
# Create a system user
ynh_system_user_create --username=$app --home_dir=$final_path --use_shell
can_remove_user=1
mkdir -p $final_path
chown $app:$app $final_path
# SWITCH TO NEW USER UNTIL EOF
chmod 0750 $final_path -R
chown $app:www-data $final_path
#=================================================
# INSTALL RVM AND RUBY FOR CURRENT USER
#=================================================
ynh_script_progression --message="Installing rvm..." --weight=10
sudo -u $app gpg --import ../conf/piotr.kuczynski\@gmail.com.pgp ../conf/mpapis\@gmail.com.pgp
pushd $final_path
sudo -u $app curl -sSL https://get.rvm.io | sudo -u $app bash -s stable
ynh_script_progression --message="Installing ruby 2.4 (this can take a long time)..." --weight=230
sudo -u $app $final_path/.rvm/bin/rvm autolibs read-fail
sudo -u $app $final_path/.rvm/bin/rvm install 2.4
ynh_script_progression --message="Installing rvm and ruby..." --weight=240
source ./install_rvm_ruby
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
# Download, check integrity, unucompress and patch the source from app.src
pushd $final_path
ynh_script_progression --message="Download the sources..." --weight=16
sudo -u $app git clone https://github.com/diaspora/diaspora.git -b v0.7.13.0
popd
#=================================================
# CREATE A POSTGRESQL DATABASE
#=================================================
ynh_script_progression --message="Creating database..." --weight=1
db_name=$(ynh_sanitize_dbid $app)
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_psql_test_if_first_run
ynh_psql_setup_db --db_user=$db_name --db_name=$db_name
db_pass=$(ynh_app_setting_get --app=$app --key=psqlpwd)
#=================================================
# EXPORT VARIABLES FOR TEMPLATING
#=================================================
@ -132,32 +139,17 @@ ynh_render_template ../conf/diaspora.yml $final_path/diaspora/config/diaspora.ym
ynh_render_template ../conf/database.yml $final_path/diaspora/config/database.yml
#=================================================
# Bundle the ruby app
# STORE THE CHECKSUM OF THE CONFIG FILE
#=================================================
pushd $final_path/diaspora
ynh_script_progression --message="bundle the app..." --weight=1000
# here we *absolutely* need bash (not dash) because dash does not understand what rvm puts in .profile
# (wtf rvm for assuming everybody uses bash as default shell??)
# we also need a login shell to make sure .profile is loaded
sudo -u $app /bin/bash --login << EOF
rvm use --default 2.4
rvm 2.4 do gem install bundler:1.17.3
script/configure_bundler
bin/bundle install --full-index --with=postgresql
EOF
ynh_script_progression --message="Create db schema..." --weight=22
sudo -u $app /bin/bash --login << EOF
RAILS_ENV=production bundle exec rake db:migrate
EOF
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum --file="$final_path/diaspora/config/diaspora.yml"
ynh_store_file_checksum --file="$final_path/diaspora/config/database.yml"
#=================================================
# ASSETS PRECOMPILATION
# Bundle the ruby app
#=================================================
ynh_script_progression --message="Precompile assets..." --weight=400
sudo -u $app /bin/bash --login << EOF
RAILS_ENV=production bin/rake assets:precompile
EOF
popd
source ./bundle_app
#=================================================
# NGINX CONFIGURATION
@ -170,40 +162,13 @@ ynh_add_nginx_config
# SETUP SYSTEMD
#=================================================
# Create a dedicated systemd config
# TODO add service in yunohost panel ?
ynh_script_progression --message="configure systemd unit..." --weight=1
ynh_render_template ../conf/diaspora_sidekiq.service /etc/systemd/system/${app}_sidekiq.service
ynh_render_template ../conf/diaspora_web.service /etc/systemd/system/${app}_web.service
ynh_render_template ../conf/diaspora.tmpfiles.d /etc/tmpfiles.d/${app}.conf
ynh_render_template ../conf/diaspora.target /etc/systemd/system/${app}.target
systemctl daemon-reload
systemd-tmpfiles --create
systemctl enable ${app}.target ${app}_sidekiq.service ${app}_web.service
systemctl restart ${app}.target
#=================================================
# STORE THE CHECKSUM OF THE CONFIG FILE
#=================================================
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum --file="$final_path/diaspora/config/diaspora.yml"
ynh_store_file_checksum --file="$final_path/diaspora/config/database.yml"
#=================================================
# GENERIC FINALIZATION
#=================================================
#=================================================
# SETUP LOGROTATE
#=================================================
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
source ./create_services
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
yunohost service add postgresql --log /var/log/postgresql/postgresql-9.4-main.log --description "PostgreSQL RDBMS"
yunohost service add $app.target\
yunohost service add $app.target \
--log $final_path/diaspora/log/production.log \
$final_path/diaspora/log/unicorn-stderr.log\
$final_path/diaspora/log/unicorn-stdout.log\
@ -216,12 +181,6 @@ yunohost service add $app.target\
# unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set $app unprotected_uris "/"
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reload nginx..." --weight=1
systemctl reload nginx
#=================================================
# CREATE AN ADMIN
#=================================================
@ -230,8 +189,8 @@ pushd $final_path/diaspora
sudo -u $app /bin/bash --login << EOF
RAILS_ENV=production bundle exec rails console << END
user = User.build({username: '$admin', email: '$admin_email', password: '$admin_password', password_confirmation: '$admin_password' })
user.seed_aspects
user.save
user.seed_aspects
Role.add_admin user.person
END
EOF

17
scripts/install_rvm_ruby Normal file
View file

@ -0,0 +1,17 @@
#!/bin/bash
# some stuff we don't care about really.
cp -v ../conf/piotr.kuczynski\@gmail.com.pgp ../conf/mpapis\@gmail.com.pgp $final_path
chown $app:$app $final_path/piotr.kuczynski\@gmail.com.pgp $final_path/mpapis\@gmail.com.pgp
sudo -u $app gpg --import $final_path/piotr.kuczynski\@gmail.com.pgp $final_path/mpapis\@gmail.com.pgp
pushd $final_path
sudo -u $app curl -sSL https://get.rvm.io | sudo -u $app bash -s stable
sudo -u $app $final_path/.rvm/bin/rvm autolibs read-fail
# avoid some issues where /tmp is not big enough
export TMPDIR=$final_path/.gcc_tmp
sudo -u $app mkdir -p $TMPDIR
# unfortunately no prebuilt for debian... this will be long
should_display_rvm_log=1
sudo -u $app TMPDIR=$TMPDIR $final_path/.rvm/bin/rvm install 2.4
should_display_rvm_log=0
popd

View file

@ -9,6 +9,10 @@
source _common.sh
source /usr/share/yunohost/helpers
can_remove_db=${can_remove_db:=1}
can_remove_home=${can_remov_home:=1}
can_remove_user=${can_remove_user:=1}
#=================================================
# LOAD SETTINGS
#=================================================
@ -48,9 +52,11 @@ fi
#=================================================
# REMOVE THE POSTGRESQL DATABASE
#=================================================
ynh_script_progression --message="Remove database"
# Remove a database if it exists, along with the associated user
ynh_psql_remove_db $db_name $db_name
if [ $can_remove_db -eq 1 ]; then
ynh_script_progression --message="Remove database"
# Remove a database if it exists, along with the associated user
ynh_psql_remove_db $db_name $db_name
fi
#=================================================
# REMOVE DEPENDENCIES
@ -67,30 +73,26 @@ ynh_script_progression --message="Remove nginx config"
# Remove the dedicated nginx config
ynh_remove_nginx_config
#=================================================
# REMOVE LOGROTATE CONFIGURATION
#=================================================
ynh_script_progression --message="Remove logrotate config"
# Remove the app-specific logrotate config
# TODO setup logrotate ?
ynh_remove_logrotate
#=================================================
# GENERIC FINALIZATION
#=================================================
# REMOVE DEDICATED USER
#=================================================
ynh_script_progression --message="Remove $app user"
# Delete a system user
# because we use gpg, sometimes rogue processes (gpg an d dirmngr) stays a bit,
# preventing the deletion of the user. Hence we kill all processes belonging to $app
pkill -9 -u `id -u $app`
ynh_system_user_delete $app
if [ $can_remove_user -eq 1 ]; then
ynh_script_progression --message="Remove $app user"
# Delete a system user
# because we use gpg, sometimes rogue processes (gpg an d dirmngr) stays a bit,
# preventing the deletion of the user. Hence we kill all processes belonging to $app
pkill -9 -u `id -u $app`
ynh_system_user_delete $app
fi
#=================================================
# REMOVE APP MAIN DIR
#=================================================
ynh_script_progression --message="Remove $final_path"
# Remove the app directory securely
ynh_secure_remove "$final_path"
if [ $can_remove_home -eq 1 ]; then
ynh_script_progression --message="Remove $final_path"
# Remove the app directory securely
ynh_secure_remove "$final_path"
fi

View file

@ -1,13 +1,19 @@
#!/bin/bash
## vars for remove script
can_remove_db=0
can_remove_home=0
can_remove_user=0
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
pushd $(readlink -f ../settings/scripts)
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
@ -32,8 +38,106 @@ db_user=$db_name
#=================================================
ynh_script_progression --message="Validating restoration parameters..."
ynh_webpath_available --domain=$domain --path_url=$path_url \
|| ynh_die --message="Path not available: ${domain}${path_url}"
ynh_webpath_available --domain=$domain --path_url=/ \
|| ynh_die --message="Domain not available: ${domain}"
test ! -d $final_path \
|| ynh_die --message="There is already a directory: $final_path "
can_remove_home=1
#=================================================
# Reinstall dependencies
#=================================================
ynh_script_progression --message="Reinstalling dependencies..." --weight=27
ynh_install_app_dependencies $pkg_dependencies $ruby_build_dependencies
# now that we have psql for sure, test db existence
ynh_script_progression --message="Checking DB availability" --weight=1
ynh_psql_database_exists --database $app && ynh_die --message="There is already a database: $app"
can_remove_db=1
#=================================================
# Restoring dedicated USER
#=================================================
ynh_script_progression --message="Restoring user..." --weight=1
ynh_system_user_create --username=$app --home_dir=$final_path --use_shell
can_remove_user=1
mkdir -p $final_path
chmod 0750 $final_path -R
chown $app:www-data $final_path
#=================================================
# INSTALL RVM AND RUBY FOR CURRENT USER
#=================================================
ynh_script_progression --message="Reinstalling rvm and ruby..." --weight=50
source ./install_rvm_ruby
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
# Download, check integrity, unucompress and patch the source from app.src
pushd $final_path
ynh_script_progression --message="Download the sources..." --weight=16
sudo -u $app git clone https://github.com/diaspora/diaspora.git -b v0.7.13.0
popd
#=================================================
# Restore files
#=================================================
ynh_script_progression --message="Restore the files" --weight=16
ynh_restore_file --origin_path=/var/www/diaspora/diaspora/config/database.yml
ynh_restore_file --origin_path=/var/www/diaspora/diaspora/config/diaspora.yml
ynh_restore_file --not_mandatory --origin_path=/var/www/diaspora/diaspora/public/uploads/
# restoring somewhere postgres can read
ynh_restore_file --origin_path=/var/www/diaspora/backup/diaspora.dump --dest_path=/tmp/diaspora.dump
#=================================================
# Restore database
#=================================================
ynh_script_progression --message="Recreating and restoring database..." --weight=16
db_name=$(ynh_sanitize_dbid $app)
ynh_psql_test_if_first_run
db_pass=$(ynh_app_setting_get --app=$app --key=psqlpwd)
ynh_psql_setup_db --db_user=$db_name --db_name=$db_name --db_pwd=$db_pass
ynh_script_progression --message="Restoring database..."
sudo -u postgres pg_restore \
--single-transaction \
--dbname=$app \
/tmp/diaspora.dump
ynh_secure_remove --file=/tmp/diaspora.dump
#=================================================
# Bundle the ruby app
#=================================================
ynh_script_progression --message="Precompile assets..." --weight=200
source ./bundle_app
#=================================================
# Restore nginx conf files
#=================================================
ynh_script_progression --message="Recreate nginx config from source"
ynh_add_nginx_config
#=================================================
# Restore services
#=================================================
ynh_script_progression --message="Restore services..."
source ./create_services
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
yunohost service add $app.target\
--log $final_path/diaspora/log/production.log \
$final_path/diaspora/log/unicorn-stderr.log\
$final_path/diaspora/log/unicorn-stdout.log\
$final_path/diaspora/log/sidekiq.log\
--description "Diaspora service (unicorn web and sidekiq)"
#=================================================
# SETUP SSOWAT
#=================================================
# unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set $app unprotected_uris "/"
popd