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:
commit
c27edb1f7d
12 changed files with 275 additions and 132 deletions
|
@ -1,7 +1,8 @@
|
||||||
diaspora_ynh
|
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)
|
[![Install diaspora with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=diaspora)
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
@ -25,7 +26,4 @@ Installation effects:
|
||||||
- The installation directory can take up to 900MB and app start time can be take 5 minutes
|
- 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
|
Report a bug: https://github.com/YunoHost-Apps/diaspora_ynh/issues
|
||||||
|
|
|
@ -10,11 +10,11 @@
|
||||||
setup_root=1
|
setup_root=1
|
||||||
setup_nourl=0
|
setup_nourl=0
|
||||||
upgrade=1
|
upgrade=1
|
||||||
# upgrade=1 from_commit=CommitHash
|
upgrade=1 from_commit=0.7.13.0-ynh1
|
||||||
backup_restore=0
|
backup_restore=1
|
||||||
multi_instance=1
|
multi_instance=1
|
||||||
port_already_use=0
|
port_already_use=0
|
||||||
change_url=0
|
change_url=0 # not supported upstream
|
||||||
;;; Levels
|
;;; Levels
|
||||||
# If the level 5 (Package linter) is forced to 1. Please add justifications here.
|
# If the level 5 (Package linter) is forced to 1. Please add justifications here.
|
||||||
Level 5=auto
|
Level 5=auto
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Diaspora social network (instance {{ app}})
|
Description=Diaspora social network (instance __APP__)
|
||||||
Wants=redis.service postgresql.service
|
Wants=redis.service postgresql.service
|
||||||
After=redis.service postgresql.service
|
After=redis.service postgresql.service
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
d /run/{{ app }} 0755 {{ app }} {{ app }} - -
|
d /run/__APP__ 0755 __APP__ __APP__ - -
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Diaspora social network (sidekiq - instance {{ app }})
|
Description=Diaspora social network (sidekiq - instance __APP__)
|
||||||
PartOf={{ app }}.target
|
PartOf=__APP__.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
User={{ app }}
|
User=__APP__
|
||||||
Environment=RAILS_ENV=production
|
Environment=RAILS_ENV=production
|
||||||
WorkingDirectory={{ final_path }}/diaspora
|
WorkingDirectory=__FINALPATH__/diaspora
|
||||||
ExecStart=/bin/bash -lc "bin/bundle exec sidekiq"
|
ExecStart=/bin/bash -lc "bin/bundle exec sidekiq"
|
||||||
Restart=always
|
Restart=always
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy={{ app }}.target
|
WantedBy=__APP__.target
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Diaspora social network (unicorn - instance {{ app }})
|
Description=Diaspora social network (unicorn - instance __APP__)
|
||||||
PartOf={{ app }}.target
|
PartOf=__APP__.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
User={{ app }}
|
User=__APP__
|
||||||
Environment=RAILS_ENV=production
|
Environment=RAILS_ENV=production
|
||||||
WorkingDirectory={{ final_path }}/diaspora
|
WorkingDirectory=__FINALPATH__/diaspora
|
||||||
PIDFile=/run/{{ app }}/diaspora.pid
|
PIDFile=/run/__APP__/diaspora.pid
|
||||||
ExecStart=/bin/bash -lc "bin/bundle exec unicorn -c config/unicorn.rb -E production"
|
ExecStart=/bin/bash -lc "bin/bundle exec unicorn -c config/unicorn.rb -E production"
|
||||||
ExecReload=/bin/kill -USR2 $MAINPID
|
ExecReload=/bin/kill -USR2 $MAINPID
|
||||||
Restart=always
|
Restart=always
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy={{ app }}.target
|
WantedBy=__APP__.target
|
||||||
|
|
23
scripts/bundle_app
Normal file
23
scripts/bundle_app
Normal 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
40
scripts/create_services
Normal 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
|
135
scripts/install
135
scripts/install
|
@ -2,9 +2,17 @@
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
# - which service to register to ynuhosto? diaspora.target only ? All of them ?
|
# - which service to register to ynuhosto? diaspora.target only ? All of them ?
|
||||||
# - backup / restore
|
|
||||||
# - a setting to enable / disable registration
|
# - a setting to enable / disable registration
|
||||||
# - say something about the registration to https://the-federation.info/
|
# - 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
|
# GENERIC START
|
||||||
|
@ -18,8 +26,13 @@ source /usr/share/yunohost/helpers
|
||||||
#=================================================
|
#=================================================
|
||||||
# MANAGE SCRIPT FAILURE
|
# MANAGE SCRIPT FAILURE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Exit if an error occurs during the execution of the script
|
# 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
|
ynh_abort_if_errors
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -31,29 +44,18 @@ admin=$YNH_APP_ARG_ADMIN
|
||||||
admin_password=$YNH_APP_ARG_ADMIN_PASSWORD
|
admin_password=$YNH_APP_ARG_ADMIN_PASSWORD
|
||||||
admin_email=$(ynh_user_get_info --username=$admin --key=mail)
|
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
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
final_path=/var/www/$app
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Validating installation parameters..." --weight=1
|
ynh_script_progression --message="Validating installation parameters..." --weight=1
|
||||||
|
|
||||||
# Check web path availability
|
# Check web path availability
|
||||||
ynh_webpath_available --domain=$domain --path_url=/
|
ynh_webpath_available --domain=$domain --path_url=/
|
||||||
# check path availability
|
# check path availability
|
||||||
final_path=/var/www/$app
|
|
||||||
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
||||||
|
can_remove_home=1
|
||||||
# Register (book) web path
|
# Register (book) web path
|
||||||
ynh_webpath_register --app=$app --domain=$domain --path_url=/
|
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
|
ynh_install_app_dependencies $pkg_dependencies $ruby_build_dependencies
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CREATE A POSTGRESQL DATABASE
|
# CHECK DB AVAILABILITY
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Creating database..." --weight=1
|
ynh_script_progression --message="Check DB availability"
|
||||||
db_name=$(ynh_sanitize_dbid $app)
|
# now that we have psql for sure, test db existence
|
||||||
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
ynh_script_progression --message="Checking DB availability" --weight=1
|
||||||
ynh_psql_test_if_first_run
|
ynh_psql_database_exists --database $app && ynh_die --message="There is already a database: $app"
|
||||||
ynh_psql_setup_db $db_name $db_name
|
can_remove_db=1
|
||||||
db_pass=$(ynh_app_setting_get --app=$app --key=psqlpwd)
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CREATE DEDICATED USER
|
# 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
|
ynh_script_progression --message="Creating user..." --weight=1
|
||||||
# Create a system user
|
# Create a system user
|
||||||
ynh_system_user_create --username=$app --home_dir=$final_path --use_shell
|
ynh_system_user_create --username=$app --home_dir=$final_path --use_shell
|
||||||
|
can_remove_user=1
|
||||||
mkdir -p $final_path
|
mkdir -p $final_path
|
||||||
chown $app:$app $final_path
|
chmod 0750 $final_path -R
|
||||||
|
chown $app:www-data $final_path
|
||||||
# SWITCH TO NEW USER UNTIL EOF
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# INSTALL RVM AND RUBY FOR CURRENT USER
|
# INSTALL RVM AND RUBY FOR CURRENT USER
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Installing rvm..." --weight=10
|
ynh_script_progression --message="Installing rvm and ruby..." --weight=240
|
||||||
sudo -u $app gpg --import ../conf/piotr.kuczynski\@gmail.com.pgp ../conf/mpapis\@gmail.com.pgp
|
source ./install_rvm_ruby
|
||||||
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
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||||
#=================================================
|
#=================================================
|
||||||
# Download, check integrity, unucompress and patch the source from app.src
|
# Download, check integrity, unucompress and patch the source from app.src
|
||||||
|
pushd $final_path
|
||||||
ynh_script_progression --message="Download the sources..." --weight=16
|
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
|
sudo -u $app git clone https://github.com/diaspora/diaspora.git -b v0.7.13.0
|
||||||
popd
|
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
|
# 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
|
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
|
# Calculate and store the config file checksum into the app settings
|
||||||
ynh_script_progression --message="bundle the app..." --weight=1000
|
ynh_store_file_checksum --file="$final_path/diaspora/config/diaspora.yml"
|
||||||
# here we *absolutely* need bash (not dash) because dash does not understand what rvm puts in .profile
|
ynh_store_file_checksum --file="$final_path/diaspora/config/database.yml"
|
||||||
# (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
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# ASSETS PRECOMPILATION
|
# Bundle the ruby app
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Precompile assets..." --weight=400
|
ynh_script_progression --message="Precompile assets..." --weight=400
|
||||||
sudo -u $app /bin/bash --login << EOF
|
source ./bundle_app
|
||||||
RAILS_ENV=production bin/rake assets:precompile
|
|
||||||
EOF
|
|
||||||
popd
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# NGINX CONFIGURATION
|
# NGINX CONFIGURATION
|
||||||
|
@ -170,39 +162,12 @@ ynh_add_nginx_config
|
||||||
# SETUP SYSTEMD
|
# SETUP SYSTEMD
|
||||||
#=================================================
|
#=================================================
|
||||||
# Create a dedicated systemd config
|
# Create a dedicated systemd config
|
||||||
# TODO add service in yunohost panel ?
|
|
||||||
ynh_script_progression --message="configure systemd unit..." --weight=1
|
ynh_script_progression --message="configure systemd unit..." --weight=1
|
||||||
ynh_render_template ../conf/diaspora_sidekiq.service /etc/systemd/system/${app}_sidekiq.service
|
source ./create_services
|
||||||
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
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# ADVERTISE SERVICE IN ADMIN PANEL
|
# 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 \
|
--log $final_path/diaspora/log/production.log \
|
||||||
$final_path/diaspora/log/unicorn-stderr.log\
|
$final_path/diaspora/log/unicorn-stderr.log\
|
||||||
|
@ -216,12 +181,6 @@ yunohost service add $app.target\
|
||||||
# unprotected_uris allows SSO credentials to be passed anyway.
|
# unprotected_uris allows SSO credentials to be passed anyway.
|
||||||
ynh_app_setting_set $app unprotected_uris "/"
|
ynh_app_setting_set $app unprotected_uris "/"
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# RELOAD NGINX
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Reload nginx..." --weight=1
|
|
||||||
systemctl reload nginx
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CREATE AN ADMIN
|
# CREATE AN ADMIN
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -230,8 +189,8 @@ pushd $final_path/diaspora
|
||||||
sudo -u $app /bin/bash --login << EOF
|
sudo -u $app /bin/bash --login << EOF
|
||||||
RAILS_ENV=production bundle exec rails console << END
|
RAILS_ENV=production bundle exec rails console << END
|
||||||
user = User.build({username: '$admin', email: '$admin_email', password: '$admin_password', password_confirmation: '$admin_password' })
|
user = User.build({username: '$admin', email: '$admin_email', password: '$admin_password', password_confirmation: '$admin_password' })
|
||||||
user.seed_aspects
|
|
||||||
user.save
|
user.save
|
||||||
|
user.seed_aspects
|
||||||
Role.add_admin user.person
|
Role.add_admin user.person
|
||||||
END
|
END
|
||||||
EOF
|
EOF
|
||||||
|
|
17
scripts/install_rvm_ruby
Normal file
17
scripts/install_rvm_ruby
Normal 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
|
||||||
|
|
|
@ -9,6 +9,10 @@
|
||||||
source _common.sh
|
source _common.sh
|
||||||
source /usr/share/yunohost/helpers
|
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
|
# LOAD SETTINGS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -48,9 +52,11 @@ fi
|
||||||
#=================================================
|
#=================================================
|
||||||
# REMOVE THE POSTGRESQL DATABASE
|
# REMOVE THE POSTGRESQL DATABASE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
if [ $can_remove_db -eq 1 ]; then
|
||||||
ynh_script_progression --message="Remove database"
|
ynh_script_progression --message="Remove database"
|
||||||
# Remove a database if it exists, along with the associated user
|
# Remove a database if it exists, along with the associated user
|
||||||
ynh_psql_remove_db $db_name $db_name
|
ynh_psql_remove_db $db_name $db_name
|
||||||
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# REMOVE DEPENDENCIES
|
# REMOVE DEPENDENCIES
|
||||||
|
@ -67,30 +73,26 @@ ynh_script_progression --message="Remove nginx config"
|
||||||
# Remove the dedicated nginx config
|
# Remove the dedicated nginx config
|
||||||
ynh_remove_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
|
# GENERIC FINALIZATION
|
||||||
#=================================================
|
#=================================================
|
||||||
# REMOVE DEDICATED USER
|
# REMOVE DEDICATED USER
|
||||||
#=================================================
|
#=================================================
|
||||||
|
if [ $can_remove_user -eq 1 ]; then
|
||||||
ynh_script_progression --message="Remove $app user"
|
ynh_script_progression --message="Remove $app user"
|
||||||
# Delete a system user
|
# Delete a system user
|
||||||
# because we use gpg, sometimes rogue processes (gpg an d dirmngr) stays a bit,
|
# 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
|
# preventing the deletion of the user. Hence we kill all processes belonging to $app
|
||||||
pkill -9 -u `id -u $app`
|
pkill -9 -u `id -u $app`
|
||||||
ynh_system_user_delete $app
|
ynh_system_user_delete $app
|
||||||
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# REMOVE APP MAIN DIR
|
# REMOVE APP MAIN DIR
|
||||||
#=================================================
|
#=================================================
|
||||||
|
if [ $can_remove_home -eq 1 ]; then
|
||||||
ynh_script_progression --message="Remove $final_path"
|
ynh_script_progression --message="Remove $final_path"
|
||||||
# Remove the app directory securely
|
# Remove the app directory securely
|
||||||
ynh_secure_remove "$final_path"
|
ynh_secure_remove "$final_path"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
110
scripts/restore
110
scripts/restore
|
@ -1,13 +1,19 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
## vars for remove script
|
||||||
|
can_remove_db=0
|
||||||
|
can_remove_home=0
|
||||||
|
can_remove_user=0
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# GENERIC START
|
# GENERIC START
|
||||||
#=================================================
|
#=================================================
|
||||||
# IMPORT GENERIC HELPERS
|
# IMPORT GENERIC HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
source ../settings/scripts/_common.sh
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
pushd $(readlink -f ../settings/scripts)
|
||||||
#=================================================
|
#=================================================
|
||||||
# MANAGE SCRIPT FAILURE
|
# MANAGE SCRIPT FAILURE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -32,8 +38,106 @@ db_user=$db_name
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Validating restoration parameters..."
|
ynh_script_progression --message="Validating restoration parameters..."
|
||||||
|
|
||||||
ynh_webpath_available --domain=$domain --path_url=$path_url \
|
ynh_webpath_available --domain=$domain --path_url=/ \
|
||||||
|| ynh_die --message="Path not available: ${domain}${path_url}"
|
|| ynh_die --message="Domain not available: ${domain}"
|
||||||
test ! -d $final_path \
|
test ! -d $final_path \
|
||||||
|| ynh_die --message="There is already a directory: $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
|
||||||
|
|
Loading…
Reference in a new issue