1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/glitchsoc_ynh.git synced 2024-09-03 19:15:59 +02:00

Merge branch 'master' into master

This commit is contained in:
__cyp 2017-04-10 16:01:13 +02:00 committed by GitHub
commit ea42525c13
8 changed files with 261 additions and 101 deletions

View file

@ -7,8 +7,8 @@
User=mastodon
WorkingDirectory=/opt/mastodon/live
Environment="RAILS_ENV=production"
Environment="DB_POOL=5"
ExecStart=/opt/mastodon/.rbenv/shims/bundle exec sidekiq -c 5 -q default -q mailers -q pull -q push
Environment="DB_POOL=20"
ExecStart=/opt/mastodon/.rbenv/shims/bundle exec sidekiq -c 20 -q default -q mailers -q pull -q push
TimeoutSec=15
Restart=always
StandardError=syslog

View file

@ -1,15 +1,14 @@
location __PATH__ {
alias __FINALPATH__/live/public;
# alias __FINALPATH__/live/public;
if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent;
}
try_files $uri @proxy;
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
#--PRIVATE--# Include SSOWAT user panel.
#--PRIVATE--include conf.d/yunohost_panel.conf.inc;
}
location @proxy {
@ -27,7 +26,7 @@
tcp_nodelay on;
}
location __PATH__/api/v1/streaming {
location /api/v1/streaming {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

View file

@ -135,18 +135,16 @@ SECURE_REMOVE () { # Deleting a folder with variable verification
fi
}
REMOVE_BDD () { # Delete database and users
# $1 = Database name
# Uses '$app' as user name and database
db_user=$1
if mysqlshow -u root -p$(sudo cat $MYSQL_ROOT_PWD_FILE) | grep -q "^| $db_user"; then
echo "Delete db"
ynh_mysql_drop_db $db_user
ynh_mysql_drop_user $db_user
fi
# Create a db without password
#
# usage: ynh_mysql_create_user user
# | arg: user - the user name to create
ynh_psql_create_db_without_password() {
db=$1
sudo su -c "psql" postgres <<< \
"CREATE USER $db CREATEDB;"
}
# Create a user
#
# usage: ynh_mysql_create_user user pwd [host]

30
scripts/backup Normal file
View file

@ -0,0 +1,30 @@
#!/bin/bash
# Exit on command errors and treat unset variables as an error
set -eu
# Get multi-instances specific variables
app=$YNH_APP_INSTANCE_NAME
# Source app helpers
source /usr/share/yunohost/helpers
# Retrieve app settings
domain=$(ynh_app_setting_get "$app" domain)
# Copy the app files
final_path="/opt/${app}"
ynh_backup "$final_path" "sources" 1
# Copy the nginx conf files
ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf"
ynh_backup "/etc/cron.d/${app}.conf" "cron.conf"
ynh_backup "/etc/systemd/system/mastodon-web.service" "systemd_web.service"
ynh_backup "/etc/systemd/system/mastodon-sidekiq.service" "systemd_sidekiq.service"
ynh_backup "/etc/systemd/system/mastodon-streaming.service" "systemd_streaming.service"
# Backup db
sudo su - postgres <<COMMANDS
pg_dump mastodon_production > /home/backup/mastodon_db.sql
COMMANDS
ynh_backup "/home/backup/mastodon_db.sql" "mastodon_db.sql"

View file

@ -9,7 +9,7 @@ source /usr/share/yunohost/helpers # Source app helpers
CLEAN_SETUP () {
# Clean installation residues that are not supported by the remove script.
# Clean hosts
sudo sed -i '/#MASTODON/d' /etc/hosts
echo ""
}
TRAP_ON # Active trap to stop the script if an error is detected.
@ -17,7 +17,6 @@ domain=$YNH_APP_ARG_DOMAIN
path=$YNH_APP_ARG_PATH
admin_mastodon=$YNH_APP_ARG_ADMIN
is_public=$YNH_APP_ARG_IS_PUBLIC
#language=$YNH_APP_ARG_LANGUAGE
app=$YNH_APP_INSTANCE_NAME
@ -66,19 +65,15 @@ curl -sL https://deb.nodesource.com/setup_4.x | sudo bash -
sudo apt-get -y install nodejs
sudo npm install -g yarn
## Install postgresql database
# Create DB without password
sudo systemctl restart postgresql
dbname=$app
dbuser=$app
# Generate random password
dbpass=$(ynh_string_random)
ynh_psql_create_db "$dbname" "$dbuser" "$dbpass"
ynh_psql_create_db_without_password "$app"
# Download all Ruby source
sudo git clone https://github.com/rbenv/rbenv.git $final_path/.rbenv
sudo git clone https://github.com/rbenv/ruby-build.git $final_path/.rbenv/plugins/ruby-build
sudo git clone https://github.com/tootsuite/mastodon.git $final_path/live
sudo git clone git://github.com/dcarley/rbenv-sudo.git $final_path/.rbenv/plugins/rbenv-sudo
sudo chown -R $app: "${final_path}"
# Install de rbenv
@ -87,7 +82,6 @@ pushd ~/.rbenv
src/configure && make -C src
echo 'export PATH="/opt/mastodon/.rbenv/bin:/opt/mastodon/live/bin:$PATH"' >> ~/.bashrc
echo 'eval "\$(rbenv init -)"' >> ~/.bashrc
echo "alias su='env PATH=\$PATH'" >> ~/.bashrc
COMMANDS
# Install ruby-build
@ -110,11 +104,12 @@ MCOMMANDS
# Adjust Mastodon config
pushd $final_path/live/
sudo cp -a .env.production.sample .env.production
sudo sed -i "s@REDIS_HOST=localhost@REDIS_HOST=127.0.0.1@g" "${final_path}/live/.env.production"
sudo sed -i "s@REDIS_HOST=redis@REDIS_HOST=127.0.0.1@g" "${final_path}/live/.env.production"
sudo sed -i "s@DB_HOST=db@DB_HOST=/var/run/postgresql@g" "${final_path}/live/.env.production"
sudo sed -i "s@DB_USER=mastodon@DB_USER=${dbuser}@g" "${final_path}/live/.env.production"
sudo sed -i "s@DB_NAME=mastodon@DB_NAME=${dbname}@g" "${final_path}/live/.env.production"
sudo sed -i "s@LOCAL_DOMAIN=domainedevotreinstance.tld@LOCAL_DOMAIN=${domain}@g" "${final_path}/live/.env.production"
sudo sed -i "s@DB_USER=postgres@DB_USER=${app}@g" "${final_path}/live/.env.production"
sudo sed -i "s@DB_NAME=postgres@DB_NAME=${app}_production@g" "${final_path}/live/.env.production"
# sudo sed -i "s@DB_PASS=@DB_PASS=${dbpass}@g" "${final_path}/live/.env.production"
sudo sed -i "s@LOCAL_DOMAIN=example.com@LOCAL_DOMAIN=${domain}@g" "${final_path}/live/.env.production"
sudo sed -i "s@PAPERCLIP_SECRET=@PAPERCLIP_SECRET=$(head -n32 /dev/urandom | tr -dc -d 'A-Za-z0-9' | head -c32)@g" "${final_path}/live/.env.production"
sudo sed -i "s@SECRET_KEY_BASE=@SECRET_KEY_BASE=$(head -n32 /dev/urandom | tr -dc -d 'A-Za-z0-9' | head -c32)@g" "${final_path}/live/.env.production"
@ -125,12 +120,17 @@ sudo sed -i 's,SMTP_FROM_ADDRESS=notifications@example.com,SMTP_FROM_ADDRESS='${
# Create database
# Preconfig CSS & JS
# Create admin user
# Create confirm email
sudo su - $app <<ENDCOMMANDS
pushd ~/live
RAILS_ENV=production bin/bundle exec rails db:setup
RAILS_ENV=production bin/bundle exec rails assets:precompile
ENDCOMMANDS
# RAILS_ENV=production bin/bundle exec rails mastodon:make_admin USERNAME=$admin_mastodon
# RAILS_ENV=production bin/bundle exec rails mastodon:confirm_email USER_EMAIL=$admin_mastodon@$domain
# Add Services
pushd /var/cache/yunohost/from_file/mastodon_ynh-master/scripts
@ -142,10 +142,9 @@ sudo cp ../conf/mastodon-streaming.service /etc/systemd/system/mastodon-streamin
sudo chown root: /etc/systemd/system/mastodon-streaming.service
sudo systemctl enable /etc/systemd/system/mastodon-*.service
sudo systemctl daemon-reload
sudo systemctl start mastodon-web.service mastodon-sidekiq.service mastodon-streaming.service
# sudo systemctl start mastodon-web.service mastodon-sidekiq.service mastodon-streaming.service
# # debug
sudo systemctl status mastodon-web.service mastodon-sidekiq.service mastodon-streaming.service
# sudo systemctl status mastodon-web.service mastodon-sidekiq.service mastodon-streaming.service
# Add service YunoHost
sudo yunohost service add mastodon-web
@ -159,7 +158,7 @@ sudo sed -i "s@__FINALPATH__@$final_path@g" /etc/nginx/conf.d/$domain.d/$app.con
# Install crontab
sudo cp ../conf/crontab_mastodon /etc/cron.d/$app
sudo sed -i "s@__AP__@$app@g" /etc/cron.d/$app
sudo sed -i "s@__APP__@$app@g" /etc/cron.d/$app
# Private or not
if [ "$is_public" = "Yes" ];
@ -177,10 +176,7 @@ fi
# Reload SSOwat configuration
sudo yunohost app ssowatconf
# Reload Nginx and regenerate SSOwat conf
# Reload Nginx
sudo systemctl reload nginx || true
# debug
sudo systemctl status nginx
# Nettoyer hosts
sudo sed -i '/#MASTODON/d' /etc/hosts

View file

@ -13,6 +13,30 @@ app=$YNH_APP_INSTANCE_NAME
# Retrieve app settings
domain=$(ynh_app_setting_get "$app" domain)
# Stop mastodon-web
if [ -e "/etc/systemd/system/mastodon-web.service" ]; then
echo "Delete systemd script"
sudo systemctl stop mastodon-web.service
sudo rm "/etc/systemd/system/mastodon-web.service"
sudo systemctl disable mastodon-web.service
fi
# Stop mastodon-sidekiq
if [ -e "/etc/systemd/system/mastodon-sidekiq.service" ]; then
echo "Delete systemd script"
sudo systemctl stop mastodon-sidekiq.service
sudo rm "/etc/systemd/system/mastodon-sidekiq.service"
sudo systemctl disable mastodon-sidekiq.service
fi
# Stop mastodon-sidekiq
if [ -e "/etc/systemd/system/mastodon-streaming.service" ]; then
echo "Delete systemd script"
sudo systemctl stop mastodon-sidekiq.streaming
sudo rm "/etc/systemd/system/mastodon-streaming.service"
sudo systemctl disable mastodon-streaming.service
fi
# Delete service on Yunohost monitoring
if sudo yunohost service status | grep -q mastodon-web
then
@ -34,33 +58,8 @@ then
sudo yunohost service remove mastodon-streaming
fi
# Stop mastodon-web
if [ -e "/etc/systemd/system/mastodon-web.service" ]; then
echo "Delete systemd script"
sudo service mastodon-web.service stop
sudo rm "/etc/systemd/system/mastodon-web.service"
sudo systemctl disable mastodon-web.service
fi
# Stop mastodon-sidekiq
if [ -e "/etc/systemd/system/mastodon-sidekiq.service" ]; then
echo "Delete systemd script"
sudo service mastodon-sidekiq.service stop
sudo rm "/etc/systemd/system/mastodon-sidekiq.service"
sudo systemctl disable mastodon-sidekiq.service
fi
# Stop mastodon-sidekiq
if [ -e "/etc/systemd/system/mastodon-streaming.service" ]; then
echo "Delete systemd script"
sudo service mastodon-sidekiq.streaming stop
sudo rm "/etc/systemd/system/mastodon-streaming.service"
sudo systemctl disable mastodon-streaming.service
fi
# delete postgresql database & user
ynh_psql_drop_db $app
ynh_psql_drop_user $app
ynh_psql_drop_db "${app}_production"
# Remove Debian package
#sudo apt-get remove --purge -y imagemagick ffmpeg libpq-dev libxml2-dev libxslt1-dev file curl git
@ -75,12 +74,13 @@ ynh_psql_drop_user $app
SECURE_REMOVE '/opt/$app'
[[ -n $domain ]] && sudo rm -f "/etc/nginx/conf.d/${domain}.d/${app}.conf"
# Suppression d'un lien symbolique
rm /usr/bin/ruby
# Delete nginx configuration
REMOVE_NGINX_CONF
REMOVE_NGINX_CONF # Suppression de la configuration nginx
SECURE_REMOVE '/var/log/$app/' # Suppression des log
# Delete log
SECURE_REMOVE '/var/log/$app/'
# Delete cronlog
SECURE_REMOVE '/etc/cron.d/$app'
# Remove user
sudo userdel -f $app

83
scripts/restore Normal file
View file

@ -0,0 +1,83 @@
#!/bin/bash
# This restore script is adapted to Yunohost >=2.4
# Exit on command errors and treat unset variables as an error
set -eu
# The parameter $app is the id of the app instance ex: ynhexample__2
app=$YNH_APP_INSTANCE_NAME
# Source app helpers
source /usr/share/yunohost/helpers
# Get old parameter of the app
domain=$(ynh_app_setting_get $app domain)
path=$(ynh_app_setting_get $app path)
is_public=$(ynh_app_setting_get $app is_public)
# Check domain/path availability
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|| ynh_die "Path not available: ${domain}${path}"
# Check $final_path
final_path="/opt/${app}"
if [ -d $final_path ]; then
ynh_die "There is already a directory: $final_path"
fi
# Check configuration files nginx
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
if [ -f $nginx_conf ]; then
ynh_die "The NGINX configuration already exists at '${nginx_conf}'.
You should safely delete it before restoring this app."
# Check configuration files php-fpm
crontab_conf="/etc/cron.d/${app}"
if [ -f $crontab_conf ]; then
ynh_die "The CRONTAB configuration already exists at '${crontab_conf}'.
You should safely delete it before restoring this app."
fi
# Restore services
web_systemd="/etc/systemd/system/${app}-web.service"
if [ -f "${web_systemd}" ]; then
ynh_die "The MASTODON WEB configuration already exists at '${web_systemd}'.
You should safely delete it before restoring this app."
fi
sidekiq_systemd="/etc/systemd/system/${app}-sidekiq.service"
if [ -f "${sidekiq_systemd}" ]; then
ynh_die "The MASTODON SIDEKIQ configuration already exists at '${sidekiq_systemd}'.
You should safely delete it before restoring this app."
fi
streaming_systemd="/etc/systemd/system/${app}-streaming.service"
if [ -f "${streaming_systemd}" ]; then
ynh_die "The MASTODON STREAMING configuration already exists at '${streaming_systemd}'.
You should safely delete it before restoring this app."
fi
# Restore sources & data
sudo cp -a ./sources "$final_path"
# Set permissions
sudo chown -R $app: "$final_path"
# Restore db
ynh_psql_create_db_without_password "$app"
sudo su - postgres <<COMMANDS
pg_dump mastodon_production < ./mastodon_db.sql
COMMANDS
# Restore Mastodon
sudo su - $app <<RCOMMANDS
cd ~/live
RAILS_ENV=production bin/bundle exec rails db:migrate
RAILS_ENV=production bin/bundle exec rails assets:precompile
RCOMMANDS
# Restore nginx configuration files
sudo cp -a ./nginx.conf "$nginx_conf"
# Restore crontab
sudo cp -a ./cron.conf "$crontab_conf"
# Reload services
sudo systemctl reload nginx

54
scripts/upgrade Normal file
View file

@ -0,0 +1,54 @@
#!/bin/bash
# Exit on command errors and treat unset variables as an error
set -eu
source .fonctions # Loads the generic functions usually used in the script
source /usr/share/yunohost/helpers # Source YunoHost helpers
# See comments in install script
app=$YNH_APP_INSTANCE_NAME
# Retrieve app settings
domain=$(ynh_app_setting_get "$app" domain)
path=$(ynh_app_setting_get "$app" path)
admin=$(ynh_app_setting_get "$app" admin)
is_public=$(ynh_app_setting_get "$app" is_public)
CHECK_PATH # Checks and corrects the syntax of the path.
# Check if admin is not null
if [[ "$admin" = "" || "$is_public" = "" || "$language" = "" ]]; then
echo "Unable to upgrade, please contact support"
ynh_die
fi
final_path=/opt/$app
db_name=$app
# Modify Nginx configuration file and copy it to Nginx conf directory
sudo sed -i "s@__PATH__@$app@g" ../conf/nginx.conf*
sudo sed -i "s@__FINALPATH__@$final_path/@g" ../conf/nginx.conf*
# Update Mastodon
sudo su - $app <<COMMANDS
pushd ~/live
git pull
RAILS_ENV=production bin/bundle exec rails db:migrate
RAILS_ENV=production bin/bundle exec rails assets:precompile
COMMANDS
# If app is public, add url to SSOWat conf as skipped_uris
if [ $is_public = "Yes" ];
then
ynh_app_setting_set "$app" unprotected_uris "/"
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
else
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
fi
# Reload Nginx
sudo systemctl reload nginx
# Reload Mastodon
sudo systemctl restart mastodon-*.service