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 User=mastodon
WorkingDirectory=/opt/mastodon/live WorkingDirectory=/opt/mastodon/live
Environment="RAILS_ENV=production" Environment="RAILS_ENV=production"
Environment="DB_POOL=5" Environment="DB_POOL=20"
ExecStart=/opt/mastodon/.rbenv/shims/bundle exec sidekiq -c 5 -q default -q mailers -q pull -q push ExecStart=/opt/mastodon/.rbenv/shims/bundle exec sidekiq -c 20 -q default -q mailers -q pull -q push
TimeoutSec=15 TimeoutSec=15
Restart=always Restart=always
StandardError=syslog StandardError=syslog

View file

@ -1,42 +1,41 @@
location __PATH__ { location __PATH__ {
alias __FINALPATH__/live/public; # alias __FINALPATH__/live/public;
if ($scheme = http) { if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent; rewrite ^ https://$server_name$request_uri? permanent;
} }
try_files $uri @proxy;
try_files $uri @proxy; #--PRIVATE--# Include SSOWAT user panel.
#--PRIVATE--include conf.d/yunohost_panel.conf.inc;
# Include SSOWAT user panel. }
include conf.d/yunohost_panel.conf.inc;
} location @proxy {
proxy_set_header Host $host;
location @proxy { proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass_header Server;
proxy_set_header X-Forwarded-Proto https; proxy_pass http://127.0.0.1:3000;
proxy_pass_header Server; proxy_buffering off;
proxy_pass http://127.0.0.1:3000; proxy_redirect off;
proxy_buffering off; proxy_http_version 1.1;
proxy_redirect off; proxy_set_header Upgrade $http_upgrade;
proxy_http_version 1.1; proxy_set_header Connection "upgrade";
proxy_set_header Upgrade $http_upgrade; tcp_nodelay on;
proxy_set_header Connection "upgrade"; }
tcp_nodelay on;
} location /api/v1/streaming {
proxy_set_header Host $host;
location __PATH__/api/v1/streaming { proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:4000;
proxy_set_header X-Forwarded-Proto https; proxy_buffering off;
proxy_pass http://127.0.0.1:4000; proxy_redirect off;
proxy_buffering off; proxy_http_version 1.1;
proxy_redirect off; proxy_set_header Upgrade $http_upgrade;
proxy_http_version 1.1; proxy_set_header Connection "upgrade";
proxy_set_header Upgrade $http_upgrade; tcp_nodelay on;
proxy_set_header Connection "upgrade";
tcp_nodelay on;
} }

View file

@ -135,18 +135,16 @@ SECURE_REMOVE () { # Deleting a folder with variable verification
fi fi
} }
REMOVE_BDD () { # Delete database and users # Create a db without password
# $1 = Database name #
# Uses '$app' as user name and database # usage: ynh_mysql_create_user user
db_user=$1 # | arg: user - the user name to create
if mysqlshow -u root -p$(sudo cat $MYSQL_ROOT_PWD_FILE) | grep -q "^| $db_user"; then ynh_psql_create_db_without_password() {
echo "Delete db" db=$1
ynh_mysql_drop_db $db_user sudo su -c "psql" postgres <<< \
ynh_mysql_drop_user $db_user "CREATE USER $db CREATEDB;"
fi
} }
# Create a user # Create a user
# #
# usage: ynh_mysql_create_user user pwd [host] # 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_SETUP () {
# Clean installation residues that are not supported by the remove script. # Clean installation residues that are not supported by the remove script.
# Clean hosts # Clean hosts
sudo sed -i '/#MASTODON/d' /etc/hosts echo ""
} }
TRAP_ON # Active trap to stop the script if an error is detected. 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 path=$YNH_APP_ARG_PATH
admin_mastodon=$YNH_APP_ARG_ADMIN admin_mastodon=$YNH_APP_ARG_ADMIN
is_public=$YNH_APP_ARG_IS_PUBLIC is_public=$YNH_APP_ARG_IS_PUBLIC
#language=$YNH_APP_ARG_LANGUAGE
app=$YNH_APP_INSTANCE_NAME 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 apt-get -y install nodejs
sudo npm install -g yarn sudo npm install -g yarn
## Install postgresql database # Create DB without password
sudo systemctl restart postgresql sudo systemctl restart postgresql
dbname=$app ynh_psql_create_db_without_password "$app"
dbuser=$app
# Generate random password
dbpass=$(ynh_string_random)
ynh_psql_create_db "$dbname" "$dbuser" "$dbpass"
# Download all Ruby source # Download all Ruby source
sudo git clone https://github.com/rbenv/rbenv.git $final_path/.rbenv 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/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 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}" sudo chown -R $app: "${final_path}"
# Install de rbenv # Install de rbenv
@ -87,7 +82,6 @@ pushd ~/.rbenv
src/configure && make -C src src/configure && make -C src
echo 'export PATH="/opt/mastodon/.rbenv/bin:/opt/mastodon/live/bin:$PATH"' >> ~/.bashrc echo 'export PATH="/opt/mastodon/.rbenv/bin:/opt/mastodon/live/bin:$PATH"' >> ~/.bashrc
echo 'eval "\$(rbenv init -)"' >> ~/.bashrc echo 'eval "\$(rbenv init -)"' >> ~/.bashrc
echo "alias su='env PATH=\$PATH'" >> ~/.bashrc
COMMANDS COMMANDS
# Install ruby-build # Install ruby-build
@ -110,11 +104,12 @@ MCOMMANDS
# Adjust Mastodon config # Adjust Mastodon config
pushd $final_path/live/ pushd $final_path/live/
sudo cp -a .env.production.sample .env.production 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_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_USER=postgres@DB_USER=${app}@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@DB_NAME=postgres@DB_NAME=${app}_production@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_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@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" 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 # Create database
# Preconfig CSS & JS # Preconfig CSS & JS
# Create admin user
# Create confirm email
sudo su - $app <<ENDCOMMANDS sudo su - $app <<ENDCOMMANDS
pushd ~/live pushd ~/live
RAILS_ENV=production bin/bundle exec rails db:setup RAILS_ENV=production bin/bundle exec rails db:setup
RAILS_ENV=production bin/bundle exec rails assets:precompile RAILS_ENV=production bin/bundle exec rails assets:precompile
ENDCOMMANDS 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 # Add Services
pushd /var/cache/yunohost/from_file/mastodon_ynh-master/scripts 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 chown root: /etc/systemd/system/mastodon-streaming.service
sudo systemctl enable /etc/systemd/system/mastodon-*.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 # # 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 # Add service YunoHost
sudo yunohost service add mastodon-web 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 # Install crontab
sudo cp ../conf/crontab_mastodon /etc/cron.d/$app 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 # Private or not
if [ "$is_public" = "Yes" ]; if [ "$is_public" = "Yes" ];
@ -177,10 +176,7 @@ fi
# Reload SSOwat configuration # Reload SSOwat configuration
sudo yunohost app ssowatconf sudo yunohost app ssowatconf
# Reload Nginx and regenerate SSOwat conf # Reload Nginx
sudo systemctl reload nginx || true sudo systemctl reload nginx || true
# debug # debug
sudo systemctl status nginx 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 # Retrieve app settings
domain=$(ynh_app_setting_get "$app" domain) 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 # Delete service on Yunohost monitoring
if sudo yunohost service status | grep -q mastodon-web if sudo yunohost service status | grep -q mastodon-web
then then
@ -34,33 +58,8 @@ then
sudo yunohost service remove mastodon-streaming sudo yunohost service remove mastodon-streaming
fi 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 # delete postgresql database & user
ynh_psql_drop_db $app ynh_psql_drop_db "${app}_production"
ynh_psql_drop_user $app
# Remove Debian package # Remove Debian package
#sudo apt-get remove --purge -y imagemagick ffmpeg libpq-dev libxml2-dev libxslt1-dev file curl git #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' SECURE_REMOVE '/opt/$app'
[[ -n $domain ]] && sudo rm -f "/etc/nginx/conf.d/${domain}.d/${app}.conf" [[ -n $domain ]] && sudo rm -f "/etc/nginx/conf.d/${domain}.d/${app}.conf"
# Suppression d'un lien symbolique # Delete nginx configuration
rm /usr/bin/ruby REMOVE_NGINX_CONF
REMOVE_NGINX_CONF # Suppression de la configuration nginx # Delete log
SECURE_REMOVE '/var/log/$app/'
SECURE_REMOVE '/var/log/$app/' # Suppression des log # Delete cronlog
SECURE_REMOVE '/etc/cron.d/$app'
# Remove user # Remove user
sudo userdel -f $app 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