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

Merge pull request #100 from anmol26s/master

Some changes to improve the app
This commit is contained in:
nemsia 2018-06-21 10:50:06 +02:00 committed by GitHub
commit 6a4ca2a0e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 196 additions and 145 deletions

View file

@ -2,9 +2,9 @@
auto_remove=1
; Manifest
domain="domain.tld" (DOMAIN)
admin="john" (USER)
path="/path" (PATH)
passwd="12345678"
admin="john" (USER)
language="fr_FR"
; Checks
pkg_linter=1
setup_sub_dir=0

View file

@ -7,7 +7,7 @@
User=__APP__
WorkingDirectory=__FINALPATH__/live
Environment="NODE_ENV=production"
Environment="PORT=4000"
Environment="PORT=__PORT_STREAM__"
ExecStart=/usr/bin/npm run start
TimeoutSec=15
Restart=always

View file

@ -7,7 +7,7 @@
User=__APP__
WorkingDirectory=__FINALPATH__/live
Environment="RAILS_ENV=production"
Environment="PORT=3000"
Environment="PORT=__PORT_WEB__"
ExecStart=__FINALPATH__/live/bin/bundle exec puma -C config/puma.rb
TimeoutSec=15
Restart=always

View file

@ -28,7 +28,7 @@ location @proxy {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_pass_header Server;
proxy_pass http://127.0.0.1:3000;
proxy_pass http://127.0.0.1:__PORT_WEB__;
proxy_buffering off;
proxy_redirect off;
proxy_http_version 1.1;
@ -42,7 +42,7 @@ location /api/v1/streaming {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_pass http://127.0.0.1:4000;
proxy_pass http://127.0.0.1:__PORT_STREAM__;
proxy_buffering off;
proxy_redirect off;
proxy_http_version 1.1;

View file

@ -40,15 +40,6 @@
},
"example": "john"
},
{
"name": "passwd",
"type": "password",
"ask": {
"en": "Enter password of this administrator ≥ 8 character",
"fr": "Ajouter le mot de passe pour cette administrateur ≥ 8 charactères"
},
"example": "adminpassword"
},
{
"name": "language",
"ask": {

View file

@ -107,7 +107,6 @@ ynh_psql_execute_file_as_root() {
# | arg: pwd - Password of the database. If not given, a password will be generated
ynh_psql_setup_db () {
db_user="$1"
app="$1"
db_name="$2"
new_db_pwd=$(ynh_string_random) # Generate a random password
# If $3 is not given, use new_db_pwd instead for db_pwd.
@ -162,7 +161,7 @@ ynh_psql_dump_db() {
ynh_psql_create_user() {
user="$1"
pwd="$2"
sudo --login --user=postgres psql -c"CREATE USER $user WITH PASSWORD '$pwd' CREATEDB;" postgres
sudo --login --user=postgres psql -c"CREATE USER $user WITH PASSWORD '$pwd'" postgres
}
# Drop a user
@ -173,3 +172,60 @@ ynh_psql_drop_user() {
user="$1"
sudo --login --user=postgres dropuser "$user"
}
# Send an email to inform the administrator
#
# usage: ynh_send_readme_to_admin app_message [recipients]
# | arg: app_message - The message to send to the administrator.
# | arg: recipients - The recipients of this email. Use spaces to separate multiples recipients. - default: root
# example: "root admin@domain"
# If you give the name of a YunoHost user, ynh_send_readme_to_admin will find its email adress for you
# example: "root admin@domain user1 user2"
ynh_send_readme_to_admin() {
local app_message="${1:-...No specific information...}"
local recipients="${2:-root}"
# Retrieve the email of users
find_mails () {
local list_mails="$1"
local mail
local recipients=" "
# Read each mail in argument
for mail in $list_mails
do
# Keep root or a real email address as it is
if [ "$mail" = "root" ] || echo "$mail" | grep --quiet "@"
then
recipients="$recipients $mail"
else
# But replace an user name without a domain after by its email
if mail=$(ynh_user_get_info "$mail" "mail" 2> /dev/null)
then
recipients="$recipients $mail"
fi
fi
done
echo "$recipients"
}
recipients=$(find_mails "$recipients")
local mail_subject="☁️🆈🅽🅷☁️: \`$app\` was just installed!"
local mail_message="This is an automated message from your beloved YunoHost server.
Specific information for the application $app.
$app_message
---
Automatic diagnosis data from YunoHost
$(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')"
# Define binary to use for mail command
if [ -e /usr/bin/bsd-mailx ]
then
local mail_bin=/usr/bin/bsd-mailx
else
local mail_bin=/usr/bin/mail.mailutils
fi
# Send the email to the recipients
echo "$mail_message" | $mail_bin -a "Content-Type: text/plain; charset=UTF-8" -s "$mail_subject" "$recipients"
}

View file

@ -34,10 +34,13 @@ app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get "$app" domain)
final_path=$(ynh_app_setting_get "$app" final_path)
db_name=$(ynh_app_setting_get "$app" db_name)
if [ -z "$db_name" ]; then
db_name="${app}_production"
ynh_app_setting_set "$app" db_name "$db_name"
fi
# Stop Mastodon Services
# Restart Mastodon
yunohost service stop "$app-web"
yunohost service stop "$app-sidekiq"
yunohost service stop "$app-streaming"
#=================================================
# STANDARD BACKUP STEPS
@ -58,6 +61,7 @@ ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
ynh_psql_dump_db "$db_name" > db.sql
ynh_backup "db.sql"
#=================================================
# SPECIFIC BACKUP
@ -74,3 +78,16 @@ ynh_backup "/etc/systemd/system/$app-streaming.service"
#=================================================
ynh_backup "/etc/apt/sources.list.d/yarn.list" "apt_yarn.list"
yunohost service start "$app-web"
yunohost service start "$app-sidekiq"
yunohost service start "$app-streaming"
# Waiting start all services
sleep 30
#=================================================
# RELOAD NGINX
#=================================================
systemctl reload nginx

View file

@ -25,8 +25,10 @@ ynh_abort_if_errors
domain=$YNH_APP_ARG_DOMAIN
admin_mastodon=$YNH_APP_ARG_ADMIN
admin_mastodon_mail=$(ynh_user_get_info $admin_mastodon 'mail')
admin_pass=$YNH_APP_ARG_PASSWD
admin_pass=$(ynh_string_random 24)
language=$YNH_APP_ARG_LANGUAGE
port_web=$(ynh_find_port 3000)
port_stream=$(ynh_find_port 4000)
path_url="/"
@ -39,9 +41,6 @@ app=$YNH_APP_INSTANCE_NAME
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
# TODO: remove this test, don't as password anymore, generate it and send it by email to admin with: https://github.com/YunoHost-Apps/Experimental_helpers/tree/master/send_readme_to_admin
[[ ${#admin_pass} -gt 7 ]] || ynh_die "Password is too weak, must be longer than 7 characters"
# Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url)
@ -54,11 +53,11 @@ ynh_webpath_register $app $domain $path_url
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app admin $admin_mastodon
ynh_app_setting_set $app pass $admin_pass
ynh_app_setting_set $app language $language
ynh_app_setting_set $app path $path_url
ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app admin $admin_mastodon
ynh_app_setting_set $app language $language
ynh_app_setting_set $app port_web $port_web
ynh_app_setting_set $app port_stream $port_stream
#=================================================
@ -87,16 +86,8 @@ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
ynh_package_update
# Creates the destination directory and stores its location.
ynh_app_setting_set "$app" final_path "$final_path"
# Install de Node.js
# TODO: use https://github.com/YunoHost-Apps/Experimental_helpers/blob/master/ynh_install_nodejs/ynh_install_nodejs
(
cd /opt
curl -sL https://deb.nodesource.com/setup_6.x | bash -
apt-get -y install nodejs
)
# install nodejs
ynh_install_nodejs 8
# TODO: use the same mecanism with other files
ynh_install_app_dependencies \
@ -114,27 +105,25 @@ ynh_install_app_dependencies \
yarn
#=================================================
# CREATE A DATABASE
# DATABASE SETUP
#=================================================
# TODO: use non-official https://github.com/YunoHost-Apps/Experimental_helpers/blob/master/postgres/postgres
# TODO: this commands doesn't looks like a requirement, you may fully remove it
# Set UTF8 encoding by default
ynh_psql_test_if_first_run
db_user=$(ynh_sanitize_dbid "$app")
# Create postgresql database
db_name="${app}_production"
db_name=$(ynh_sanitize_dbid "$db_name")
db_pwd=$(ynh_string_random)
ynh_app_setting_set $app db_name $db_name
ynh_app_setting_set $app db_pwd $db_pwd
ynh_psql_setup_db "$db_user" "$db_name" "$db_pwd"
db_pwd=$(ynh_string_random 30)
ynh_app_setting_set "$app" db_name "$db_name"
ynh_app_setting_set "$app" db_pwd "$db_pwd"
ynh_psql_test_if_first_run
ynh_psql_create_user "$app" "$db_pwd"
ynh_psql_execute_as_root \
"CREATE DATABASE $db_name ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 OWNER $app;"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
# Creates the destination directory and stores its location.
ynh_app_setting_set "$app" final_path "$final_path"
# Download all sources rbenv, ruby and mastodon
ynh_setup_source "$final_path/.rbenv" "app-rbenv"
@ -145,18 +134,16 @@ ynh_setup_source "$final_path/live" "app-mastodon"
# NGINX CONFIGURATION
#=================================================
# TODO: use official helper ynh_add_nginx_config
# Modify Nginx configuration file and copy it to Nginx conf directory
sed -i "s@__PATH__@$app@g" ../conf/nginx.conf*
sed -i "s@__FINALPATH__@$final_path@g" ../conf/nginx.conf*
cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
# Create a dedicated nginx config
ynh_replace_string "__PORT_WEB__" "$port_web" "../conf/nginx.conf"
ynh_replace_string "__PORT_STREAM__" "$port_stream" "../conf/nginx.conf"
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
# TODO: use official helper ynh_system_user_create
# Create user unix
# Create a system user
adduser $app --home $final_path --gecos "First Last,RoomNumber,WorkPhone,HomePhone" --disabled-password
chown -R "$app" "$final_path"
@ -189,34 +176,32 @@ yarn install --pure-lockfile
popd
# Adjust Mastodon config
# TODO: use official helper ynh_replace_string
# TODO: save the config file in conf folder, to make replacement easier to read
# TODO: use ynh_string_random
cp -a $final_path/live/.env.production.sample $final_path/live/.env.production
sed -i "s@REDIS_HOST=redis@REDIS_HOST=127.0.0.1@g" "${final_path}/live/.env.production"
sed -i "s@DB_HOST=db@DB_HOST=/var/run/postgresql@g" "${final_path}/live/.env.production"
sed -i "s@DB_USER=postgres@DB_USER=${db_user}@g" "${final_path}/live/.env.production"
sed -i "s@DB_NAME=postgres@DB_NAME=${db_name}@g" "${final_path}/live/.env.production"
sed -i "s@DB_PASS=@DB_PASS=${db_pwd}@g" "${final_path}/live/.env.production"
sed -i "s@LOCAL_DOMAIN=example.com@LOCAL_DOMAIN=${domain}@g" "${final_path}/live/.env.production"
ynh_replace_string "REDIS_HOST=redis" "REDIS_HOST=127.0.0.1" "${final_path}/live/.env.production"
ynh_replace_string "DB_HOST=db" "DB_HOST=/var/run/postgresql" "${final_path}/live/.env.production"
ynh_replace_string "DB_USER=postgres" "DB_USER=${app}" "${final_path}/live/.env.production"
ynh_replace_string "DB_NAME=postgres" "DB_NAME=${db_name}" "${final_path}/live/.env.production"
ynh_replace_string "DB_PASS=" "DB_PASS=${db_pwd}" "${final_path}/live/.env.production"
ynh_replace_string "LOCAL_DOMAIN=example.com" "LOCAL_DOMAIN=${domain}" "${final_path}/live/.env.production"
language="$(echo $language | head -c 2)"
sed -i "s@# DEFAULT_LOCALE=de@DEFAULT_LOCALE=${language}@g" "${final_path}/live/.env.production"
ynh_replace_string "# DEFAULT_LOCALE=de" "DEFAULT_LOCALE=${language}" "${final_path}/live/.env.production"
paperclip_secret=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128)
secret_key_base=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128)
otp_secret=$(head -n128 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c128)
sed -i "s@PAPERCLIP_SECRET=@PAPERCLIP_SECRET=${paperclip_secret}@g" "${final_path}/live/.env.production"
sed -i "s@SECRET_KEY_BASE=@SECRET_KEY_BASE=${secret_key_base}@g" "${final_path}/live/.env.production"
sed -i "s@OTP_SECRET=@OTP_SECRET=${otp_secret}@g" "${final_path}/live/.env.production"
ynh_replace_string "PAPERCLIP_SECRET=" "PAPERCLIP_SECRET=$paperclip_secret" "${final_path}/live/.env.production"
ynh_replace_string "SECRET_KEY_BASE=" "SECRET_KEY_BASE=$secret_key_base" "${final_path}/live/.env.production"
ynh_replace_string "OTP_SECRET=" "OTP_SECRET=$otp_secret" "${final_path}/live/.env.production"
sed -i "s@SMTP_LOGIN=@#SMTP_LOGIN=@g" "${final_path}/live/.env.production"
sed -i "s@SMTP_PASSWORD=@#SMTP_PASSWORD=@g" "${final_path}/live/.env.production"
sed -i "s@SMTP_SERVER=smtp.mailgun.org@SMTP_SERVER=localhost@g" "${final_path}/live/.env.production"
sed -i "s@SMTP_PORT=587@SMTP_PORT=25@g" "${final_path}/live/.env.production"
sed -i 's,SMTP_FROM_ADDRESS=notifications@example.com,SMTP_FROM_ADDRESS='${admin_mastodon}'@'${domain}',' "${final_path}/live/.env.production"
sed -i "s@#SMTP_AUTH_METHOD=plain@SMTP_AUTH_METHOD=none@g" "${final_path}/live/.env.production"
sed -i "s@#SMTP_OPENSSL_VERIFY_MODE=peer@SMTP_OPENSSL_VERIFY_MODE=none@g" "${final_path}/live/.env.production"
ynh_replace_string "SMTP_LOGIN=" "#SMTP_LOGIN=" "${final_path}/live/.env.production"
ynh_replace_string "SMTP_PASSWORD=" "#SMTP_PASSWORD=" "${final_path}/live/.env.production"
ynh_replace_string "SMTP_SERVER=smtp.mailgun.org" "SMTP_SERVER=localhost" "${final_path}/live/.env.production"
ynh_replace_string "SMTP_PORT=587" "SMTP_PORT=25" "${final_path}/live/.env.production"
ynh_replace_string "SMTP_FROM_ADDRESS=notifications@example.com" "SMTP_FROM_ADDRESS=$admin_mastodon@$domain" "${final_path}/live/.env.production"
ynh_replace_string "#SMTP_AUTH_METHOD=plain" "SMTP_AUTH_METHOD=none" "${final_path}/live/.env.production"
ynh_replace_string "#SMTP_OPENSSL_VERIFY_MODE=peer" "SMTP_OPENSSL_VERIFY_MODE=none" "${final_path}/live/.env.production"
# Preconfig CSS & JS
# Install Mastodon
@ -232,9 +217,14 @@ sed -i "s@#SMTP_OPENSSL_VERIFY_MODE=peer@SMTP_OPENSSL_VERIFY_MODE=none@g" "${fin
INSTALL
)
# TODO: use ynh_find_port to have generic port selection for RAILS
#=================================================
# SETUP SYSTEMD
#=================================================
# Create a dedicated systemd config
ynh_replace_string "__PORT_WEB__" "$port_web" "../conf/mastodon-web.service"
ynh_replace_string "__PORT_STREAM__" "$port_stream" "../conf/mastodon-streaming.service"
ynh_add_systemd_config "$app-web" "mastodon-web.service"
# TODO: use ynh_find_port to have generic port selection for NODES
ynh_add_systemd_config "$app-sidekiq" "mastodon-sidekiq.service"
ynh_add_systemd_config "$app-streaming" "mastodon-streaming.service"
@ -286,3 +276,15 @@ ynh_app_setting_set "$app" unprotected_uris "/"
# Reload Nginx
systemctl reload nginx
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
message="Mastodon was successfully installed :)
Please open 'https://$domain$path_url'
The admin username is: '$admin_mastodon_mail'
The admin password is: '$admin_pass'
If you facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/mastodon_ynh"
ynh_send_readme_to_admin "$message" "$admin_mastodon"

View file

@ -12,7 +12,6 @@ source /usr/share/yunohost/helpers
source _future.sh
#=================================================
# LOAD SETTINGS
#=================================================
@ -22,11 +21,6 @@ app=$YNH_APP_INSTANCE_NAME
# Retrieve app settings
domain=$(ynh_app_setting_get "$app" domain)
db_name=$(ynh_app_setting_get "$app" db_name)
if [ -z "$db_name" ]; then
db_name="${app}_production"
ynh_app_setting_set "$app" db_name "$db_name"
fi
db_user=$(ynh_sanitize_dbid "$app")
final_path=$(ynh_app_setting_get "$app" final_path)
#=================================================
@ -67,13 +61,13 @@ fi
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
ynh_remove_nodejs
#=================================================
# REMOVE THE PostgreSQL DATABASE
#=================================================
# delete postgresql database & user
ynh_psql_remove_db "$db_name" "$db_user"
ynh_psql_remove_db "$db_name" "$app"
#=================================================
# REMOVE APP MAIN DIR
@ -85,18 +79,12 @@ ynh_secure_remove "$final_path"
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_secure_remove "/etc/nginx/conf.d/${domain}.d/${app}.conf"
systemctl reload nginx
ynh_remove_nginx_config
#=================================================
# SPECIFIC REMOVE
#=================================================
# REMOVE THE CRON FILE
#=================================================
# Delete cronlog
ynh_secure_remove /etc/cron.d/$app
#=================================================
# REMOVE source.list
@ -115,5 +103,4 @@ ynh_secure_remove /etc/apt/sources.list.d/yarn.list
#=================================================
# REMOVE DEDICATED USER
#=================================================
userdel -f $app
ynh_system_user_delete $app

View file

@ -62,7 +62,6 @@ ynh_restore_file "$final_path"
# RECREATE THE DEDICATED USER
#=================================================
# Create user unix
adduser $app --home $final_path --gecos "First Last,RoomNumber,WorkPhone,HomePhone" --disabled-password
#=================================================
@ -95,13 +94,8 @@ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
ynh_package_update
# Install de Node.js
# TODO: use https://github.com/YunoHost-Apps/Experimental_helpers/blob/master/ynh_install_nodejs/ynh_install_nodejs
(
cd /opt
curl -sL https://deb.nodesource.com/setup_6.x | bash -
apt-get -y install nodejs
)
# install nodejs
ynh_install_nodejs 8
# TODO: use the same mecanism with other files
ynh_install_app_dependencies \
@ -123,25 +117,17 @@ ynh_install_app_dependencies \
#=================================================
# Restore PostgreSQL database
db_user=$(ynh_sanitize_dbid "$app")
db_name=$(ynh_app_setting_get "$app" db_name)
if [ -z "$db_name" ]; then
db_name="${app}_production"
ynh_app_setting_set "$app" db_name "$db_name"
fi
db_pwd=$(ynh_app_setting_get "$app" db_pwd)
ynh_psql_test_if_first_run
ynh_psql_setup_db "$db_user" "$db_name" "$db_pwd"
ynh_psql_create_user "$app" "$db_pwd"
ynh_psql_execute_as_root \
"CREATE DATABASE $db_name ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 OWNER $app;"
ynh_psql_execute_file_as_root ./db.sql "$db_name"
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
yunohost service add $app-web
yunohost service add $app-sidekiq
yunohost service add $app-streaming
#=================================================
# RESTORE SYSTEMD
@ -152,11 +138,21 @@ ynh_restore_file "/etc/systemd/system/$app-sidekiq.service"
ynh_restore_file "/etc/systemd/system/$app-streaming.service"
systemctl enable "$app-web" "$app-sidekiq" "$app-streaming"
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
yunohost service add $app-web
yunohost service add $app-sidekiq
yunohost service add $app-streaming
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PHP-FPM
# RELOAD NGINX AND services
#=================================================
systemctl restart "$app-web" "$app-sidekiq" "$app-streaming"
# Waiting start all services
sleep 30
systemctl reload nginx

View file

@ -25,6 +25,8 @@ admin=$(ynh_app_setting_get "$app" admin)
language=$(ynh_app_setting_get "$app" language)
final_path=$(ynh_app_setting_get "$app" final_path)
path_url="/"
port_web=$(ynh_app_setting_get "$app" port_web)
port_stream=$(ynh_app_setting_get "$app" port_stream)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
@ -48,14 +50,6 @@ if [[ "$admin" = "" || "$language" = "" ]]; then
ynh_die
fi
# If db_pwd doesn't exist, create it
if [[ -z "$db_pwd" ]]; then
db_pwd=$(ynh_string_random)
ynh_app_setting_set $app db_pwd $db_pwd
ynh_psql_test_if_first_run
sudo --login --user=postgres psql -c"ALTER user $app WITH PASSWORD '$db_pwd'" postgres
sed -i "s@DB_PASS=@DB_PASS=${db_pwd}@g" "${final_path}/live/.env.production"
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
@ -86,14 +80,7 @@ echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.lis
# INSTALL DEPENDENCIES
#=================================================
# upgrade Node.js v4 to v6
# TODO: use https://github.com/YunoHost-Apps/Experimental_helpers/blob/master/ynh_install_nodejs/ynh_install_nodejs
node_version=$(nodejs --version)
if [[ $node_version =~ ^v4.*$ ]]; then
pushd /opt
curl -sL https://deb.nodesource.com/setup_6.x | sudo bash -
sudo apt-get -y install nodejs
fi
ynh_install_nodejs 8
# add additional package for upgrade
ynh_package_install pkg-config libprotobuf-dev protobuf-compiler libicu-dev libidn11-dev postgresql-server-dev-all
@ -112,20 +99,19 @@ yunohost service stop "$app-sidekiq"
yunohost service stop "$app-streaming"
# Download Mastodon
ynh_setup_source "$final_path/live" "app-mastodon"
ynh_setup_source "$final_path/live" "app-mastodon"
# Clean un-need Files
# Clean files which are not needed anymore
ynh_secure_remove $final_path/live/config/initializers/timeout.rb
#=================================================
# NGINX CONFIGURATION
#=================================================
# TODO: use official helper ynh_add_nginx_config
# Modify Nginx configuration file and copy it to Nginx conf directory
sed -i "s@__PATH__@$app@g" ../conf/nginx.conf*
sed -i "s@__FINALPATH__@$final_path@g" ../conf/nginx.conf*
cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
ynh_replace_string "__PORT_WEB__" "$port_web" "../conf/nginx.conf"
ynh_replace_string "__PORT_STREAM__" "$port_stream" "../conf/nginx.conf"
ynh_add_nginx_config
# Upgrade rbenv and ruby plugins
ynh_setup_source "$final_path/.rbenv" "app-rbenv"
@ -176,9 +162,25 @@ RAILS_ENV=production $final_path/.rbenv/versions/2.5.1/bin/bundle exec rails db:
COMMANDS
)
#=================================================
# RESTART MASTODON
# SETUP SYSTEMD
#=================================================
# Create a dedicated systemd config
ynh_replace_string "__PORT_WEB__" "$port_web" "../conf/mastodon-web.service"
ynh_replace_string "__PORT_STREAM__" "$port_stream" "../conf/mastodon-streaming.service"
ynh_add_systemd_config "$app-web" "mastodon-web.service"
ynh_add_systemd_config "$app-sidekiq" "mastodon-sidekiq.service"
ynh_add_systemd_config "$app-streaming" "mastodon-streaming.service"
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
# Add service YunoHost
yunohost service add "$app-web"
yunohost service add "$app-sidekiq"
yunohost service add "$app-streaming"
yunohost service start "$app-web"
yunohost service start "$app-sidekiq"
yunohost service start "$app-streaming"