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

Apply example_ynh

This commit is contained in:
yalh76 2019-05-16 01:48:41 +02:00
parent 0b6694b495
commit 51d33a309d
11 changed files with 301 additions and 407 deletions

View file

@ -1,9 +1,9 @@
# Pleroma app for Yunohost # Pleroma app for Yunohost
[![Integration level](https://dash.yunohost.org/integration/pleroma.svg)](https://dash.yunohost.org/appci/app/pleroma) [![Integration level](https://dash.yunohost.org/integration/pleroma.svg)](https://dash.yunohost.org/appci/app/pleroma)
[![Install pleroma with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=pleroma) [![Install Pleroma with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=pleroma)
> *This package allow you to install pleroma quickly and simply on a YunoHost server. > *This package allow you to install Pleroma quickly and simply on a YunoHost server.
If you don't have YunoHost, please see [here](https://yunohost.org/#/install) to know how to install and enjoy it.* If you don't have YunoHost, please see [here](https://yunohost.org/#/install) to know how to install and enjoy it.*
## Overview ## Overview
@ -83,9 +83,9 @@ The app can be used by multiple users.
#### Supported architectures #### Supported architectures
* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/pleroma%20%28Community%29.svg)](https://ci-apps.yunohost.org/ci/apps/pleroma/) * x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/pleroma%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/pleroma/)
* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/pleroma%20%28Community%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/pleroma/) * ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/pleroma%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/pleroma/)
* Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/ci/logs/pleroma%20%28Community%29.svg)](https://ci-stretch.nohost.me/ci/apps/pleroma/) * Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/ci/logs/pleroma%20%28Apps%29.svg)](https://ci-stretch.nohost.me/ci/apps/pleroma/)
## Limitations ## Limitations
@ -95,7 +95,7 @@ The app can be used by multiple users.
* Report a bug: https://github.com/YunoHost-Apps/pleroma_ynh/issues * Report a bug: https://github.com/YunoHost-Apps/pleroma_ynh/issues
* App website: https://pleroma.social/ * App website: https://pleroma.social/
* Pleroma Gitlab repo: https://git.pleroma.social/pleroma/pleroma/ * Upstream app repository https://git.pleroma.social/pleroma/pleroma/
* YunoHost website: https://yunohost.org/ * YunoHost website: https://yunohost.org/
--- ---

View file

@ -18,7 +18,7 @@
"name": "yalh76" "name": "yalh76"
}], }],
"requirements": { "requirements": {
"yunohost": ">= 3.4" "yunohost": ">= 3.5"
}, },
"multi_instance": true, "multi_instance": true,
"services": [ "services": [

View file

@ -17,7 +17,7 @@
- [ ] **Approval (LGTM)** - [ ] **Approval (LGTM)**
*Code review and approval have to be from a member of @YunoHost/apps group* *Code review and approval have to be from a member of @YunoHost/apps group*
- **CI succeeded** : - **CI succeeded** :
[![Build Status](https://ci-apps-hq.yunohost.org/jenkins/job/pleroma_ynh%20-BRANCH-/badge/icon)](https://ci-apps-hq.yunohost.org/jenkins/job/pleroma_ynh%20-BRANCH-/) [![Build Status](https://ci-apps-dev.yunohost.org/jenkins/job/pleroma_ynh%20-BRANCH-/badge/icon)](https://ci-apps-dev.yunohost.org/jenkins/job/pleroma_ynh%20-BRANCH-/)
*Please replace '-BRANCH-' in this link by the name of the branch used.* *Please replace '-BRANCH-' in this link by the name of the branch used.*
*If the PR is from a forked repository. Please provide public results from package_check.* *If the PR is from a forked repository. Please provide public results from package_check.*
When the PR is marked as ready to merge, you have to wait for 3 days before really merging it. When the PR is marked as ready to merge, you have to wait for 3 days before really merging it.

View file

@ -7,7 +7,6 @@
#================================================= #=================================================
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source ../settings/scripts/ynh_systemd_action
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
@ -23,61 +22,75 @@ ynh_abort_if_errors
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_print_info "Loading installation settings..." ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get $app final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
db_name=$(ynh_app_setting_get $app db_name) db_name=$(ynh_app_setting_get --app=$app --key=db_name)
cache=$(ynh_app_setting_get "$app" cache) cache=$(ynh_app_setting_get --app=$app --key=cache)
#================================================= #=================================================
# STANDARD BACKUP STEPS # STANDARD BACKUP STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_print_info --message="Stopping a systemd service..."
ynh_systemd_action --service_name=$app --action="stop"
#================================================= #=================================================
# BACKUP THE APP MAIN DIR # BACKUP THE APP MAIN DIR
#================================================= #=================================================
ynh_print_info "Backing up the main app directory..." ynh_print_info --message="Backing up the main app directory..."
ynh_backup "$final_path" ynh_backup --src_path="$final_path"
#================================================= #=================================================
# BACKUP THE NGINX CONFIGURATION # BACKUP THE NGINX CONFIGURATION
#================================================= #=================================================
ynh_print_info "Backing up nginx web server configuration..." ynh_print_info --message="Backing up nginx web server configuration..."
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
if [ $cache -eq 1 ] if [ $cache -eq 1 ]
then then
ynh_backup "/etc/nginx/conf.d/$app-cache.conf" ynh_backup --src_path="/etc/nginx/conf.d/$app-cache.conf"
fi fi
#================================================= #=================================================
# BACKUP THE POSTGRESQL DATABASE # BACKUP THE POSTGRESQL DATABASE
#================================================= #=================================================
ynh_print_info "Backing up the PostgreSQL database..." ynh_print_info --message="Backing up the PostgreSQL database..."
ynh_psql_dump_db "$db_name" > db.sql ynh_psql_dump_db --database="$db_name" > db.sql
#================================================= #=================================================
# SPECIFIC BACKUP # SPECIFIC BACKUP
#================================================= #=================================================
# BACKUP LOGROTATE # BACKUP LOGROTATE
#================================================= #=================================================
ynh_print_info "Backing up logrotate configuration..." ynh_print_info --message="Backing up logrotate configuration..."
ynh_backup "/etc/logrotate.d/$app" ynh_backup --src_path="/etc/logrotate.d/$app"
#================================================= #=================================================
# BACKUP SYSTEMD # BACKUP SYSTEMD
#================================================= #=================================================
ynh_print_info "Backing up systemd configuration..." ynh_print_info --message="Backing up systemd configuration..."
ynh_backup "/etc/systemd/system/$app.service" ynh_backup --src_path="/etc/systemd/system/$app.service"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_print_info --message="Starting a systemd service..."
ynh_systemd_action --service_name=$app --action="start"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

View file

@ -7,7 +7,6 @@
#================================================= #=================================================
source _common.sh source _common.sh
source ynh_systemd_action
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
@ -25,23 +24,15 @@ app=$YNH_APP_INSTANCE_NAME
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_print_info "Loading installation settings..." ynh_print_info --message="Loading installation settings..."
# Needed for helper "ynh_add_nginx_config" # Needed for helper "ynh_add_nginx_config"
final_path=$(ynh_app_setting_get $app final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
# Add settings here as needed by your application # Add settings here as needed by your application
#db_name=$(ynh_app_setting_get "$app" db_name) #db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#db_pwd=$(ynh_app_setting_get $app db_pwd) #db_user=$db_name
#db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd)
#=================================================
# CHECK THE SYNTAX OF THE PATHS
#=================================================
test -n "$old_path" || old_path="/"
test -n "$new_path" || new_path="/"
new_path=$(ynh_normalize_url_path $new_path)
old_path=$(ynh_normalize_url_path $old_path)
#================================================= #=================================================
# CHECK WHICH PARTS SHOULD BE CHANGED # CHECK WHICH PARTS SHOULD BE CHANGED
@ -61,10 +52,17 @@ fi
#================================================= #=================================================
# STANDARD MODIFICATIONS # STANDARD MODIFICATIONS
#=================================================
# STOP SERVICE
#=================================================
ynh_print_info --message="Stopping a systemd service..."
ynh_systemd_action --service_name=$app --action="stop"
#================================================= #=================================================
# MODIFY URL IN NGINX CONF # MODIFY URL IN NGINX CONF
#================================================= #=================================================
ynh_print_info "Updating nginx web server configuration..." ynh_print_info --message="Updating nginx web server configuration..."
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
@ -72,7 +70,7 @@ nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
if [ $change_path -eq 1 ] if [ $change_path -eq 1 ]
then then
# Make a backup of the original nginx config file if modified # Make a backup of the original nginx config file if modified
ynh_backup_if_checksum_is_different "$nginx_conf_path" ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
# Set global variables for nginx helper # Set global variables for nginx helper
domain="$old_domain" domain="$old_domain"
path_url="$new_path" path_url="$new_path"
@ -84,51 +82,46 @@ fi
if [ $change_domain -eq 1 ] if [ $change_domain -eq 1 ]
then then
# Delete file checksum for the old conf file location # Delete file checksum for the old conf file location
ynh_delete_file_checksum "$nginx_conf_path" ynh_delete_file_checksum --file="$nginx_conf_path"
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
# Store file checksum for the new config file location # Store file checksum for the new config file location
ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf" ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
fi fi
#================================================= #=================================================
# SPECIFIC MODIFICATIONS # SPECIFIC MODIFICATIONS
#=================================================
# STOP SERVICE
#=================================================
ynh_systemd_action --action=stop --service_name=$app
#================================================= #=================================================
# MODIFY A CONFIG FILE # MODIFY A CONFIG FILE
#================================================= #=================================================
ynh_replace_string "$old_domain" "$new_domain" "$final_path/$app/config/prod.secret.exs" ynh_replace_string --match_string="$old_domain" --replace_string="$new_domain" --target_file="$final_path/$app/config/prod.secret.exs"
#=================================================
# START SERVICE
#=================================================
ynh_systemd_action --action=start --service_name=$app --log_path=systemd --line_match="Running Pleroma.Web.Endpoint"
#================================================= #=================================================
# STORE THE CONFIG FILE CHECKSUM # STORE THE CONFIG FILE CHECKSUM
#================================================= #=================================================
ynh_backup_if_checksum_is_different "$final_path/$app/config/prod.secret.exs" ynh_backup_if_checksum_is_different --file="$final_path/$app/config/prod.secret.exs"
# Recalculate and store the checksum of the file for the next upgrade. # Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum "$final_path/$app/config/prod.secret.exs" ynh_store_file_checksum --file="$final_path/$app/config/prod.secret.exs"
#================================================= #=================================================
# GENERIC FINALISATION # GENERIC FINALISATION
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_print_info --message="Starting a systemd service..."
ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Running Pleroma.Web.Endpoint"
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_print_info "Reloading nginx web server..." ynh_print_info --message="Reloading nginx web server..."
systemctl reload nginx ynh_systemd_action --service_name=nginx --action=reload
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_print_info "Change of URL completed for $app" ynh_print_info --message="Change of URL completed for $app"

View file

@ -7,8 +7,7 @@
#================================================= #=================================================
source _common.sh source _common.sh
source ynh_systemd_action source ynh_add_extra_apt_repos__3
source ynh_add_secure_repos__3
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
@ -34,8 +33,8 @@ name=$YNH_APP_ARG_NAME
registration=$YNH_APP_ARG_REGISTRATION registration=$YNH_APP_ARG_REGISTRATION
cache=$YNH_APP_ARG_CACHE cache=$YNH_APP_ARG_CACHE
size=$YNH_APP_ARG_SIZE size=$YNH_APP_ARG_SIZE
random_key=$(ynh_string_random 64) random_key=$(ynh_string_random --length=64)
admin_email=$(ynh_user_get_info $admin 'mail') admin_email=$(ynh_user_get_info --username=$admin --key="mail")
## Bypass package_checker name not compatible with pleroma ## Bypass package_checker name not compatible with pleroma
if [ "$admin" = "package_checker" ] if [ "$admin" = "package_checker" ]
@ -48,115 +47,103 @@ app=$YNH_APP_INSTANCE_NAME
#================================================= #=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#================================================= #=================================================
ynh_print_info "Validating installation parameters..." ynh_print_info --message="Validating installation parameters..."
final_path=/var/www/$app final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder" test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
# Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url)
# Register (book) web path # Register (book) web path
ynh_webpath_register $app $domain $path_url ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
#================================================= #=================================================
# STORE SETTINGS FROM MANIFEST # STORE SETTINGS FROM MANIFEST
#================================================= #=================================================
ynh_print_info "Storing installation settings..." ynh_print_info --message="Storing installation settings..."
ynh_app_setting_set $app domain $domain ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set $app path $path_url ynh_app_setting_set --app=$app --key=path --value=$path_url
ynh_app_setting_set $app admin $admin ynh_app_setting_set --app=$app --key=admin --value=$admin
ynh_app_setting_set $app is_public $is_public ynh_app_setting_set --app=$app --key=is_public --value=$is_public
ynh_app_setting_set "$app" name "$name" ynh_app_setting_set --app=$app --key=name --value="$name"
ynh_app_setting_set "$app" registration "$registration" ynh_app_setting_set --app=$app --key=registration --value="$registration"
ynh_app_setting_set "$app" cache "$cache" ynh_app_setting_set --app=$app --key=cache --value="$cache"
ynh_app_setting_set "$app" size "$size" ynh_app_setting_set --app=$app --key=size --value="$size"
ynh_app_setting_set "$app" admin_email "$admin_email" ynh_app_setting_set --app=$app --key=admin_email --value="$admin_email"
ynh_app_setting_set "$app" random_key "$random_key" ynh_app_setting_set --app=$app --key=random_key --value="$random_key"
#================================================= #=================================================
# STANDARD MODIFICATIONS # STANDARD MODIFICATIONS
#================================================= #=================================================
# FIND AND OPEN A PORT # FIND AND OPEN A PORT
#================================================= #=================================================
ynh_print_info "Configuring firewall ..." ynh_print_info --message="Configuring firewall..."
# Find a free port # Find a free port
port=$(ynh_find_port 8095) port=$(ynh_find_port --port=8095)
ynh_app_setting_set $app port $port ynh_app_setting_set --app=$app --key=port --value=$port
#================================================= #=================================================
# INSTALL DEPENDENCIES # INSTALL DEPENDENCIES
#================================================= #=================================================
ynh_print_info "Installing dependencies ..." ynh_print_info --message="Installing dependencies..."
ynh_install_app_dependencies $pkg_dependencies ynh_install_app_dependencies $pkg_dependencies
#=================================================
# INSTALL EXTRA DEPENDENCIES
#=================================================
ynh_print_info "Installing extra dependencies ..."
lsb_name="$(lsb_release --codename --short)" lsb_name="$(lsb_release --codename --short)"
ynh_install_extra_app_dependencies --repo="deb http://packages.erlang-solutions.com/debian $lsb_name contrib" --package="$extra_pkg_dependencies" --key='https://packages.erlang-solutions.com/debian/erlang_solutions.asc' ynh_install_extra_app_dependencies --repo="deb http://packages.erlang-solutions.com/debian $lsb_name contrib" --package="$extra_pkg_dependencies" --key='https://packages.erlang-solutions.com/debian/erlang_solutions.asc'
#================================================= #=================================================
# CREATE A POSTGRESQL DATABASE # CREATE A POSTGRESQL DATABASE
#================================================= #=================================================
ynh_print_info "Creating a PostgreSQL database..." ynh_print_info --message="Creating a PostgreSQL database..."
db_name=$(ynh_sanitize_dbid $app) db_name=$(ynh_sanitize_dbid --db_name=$app)
db_pwd=$(ynh_string_random 30) db_user=$db_name
ynh_app_setting_set $app db_name $db_name db_pwd=$(ynh_string_random --length=30)
ynh_app_setting_set "$app" db_pwd "$db_pwd" ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_app_setting_set --app=$app --key=db_pwd --value=$db_pwd
ynh_psql_test_if_first_run ynh_psql_test_if_first_run
ynh_psql_create_user "$app" "$db_pwd" ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_psql_execute_as_root "CREATE DATABASE $db_name ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 OWNER $db_name;" ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS unaccent;" --database=$db_name
ynh_psql_execute_as_root "\connect $db_name ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name
CREATE EXTENSION IF NOT EXISTS unaccent;" ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS citext;" --database=$db_name
ynh_psql_execute_as_root "\connect $db_name ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";" --database=$db_name
CREATE EXTENSION IF NOT EXISTS pg_trgm;"
ynh_psql_execute_as_root "\connect $db_name
CREATE EXTENSION IF NOT EXISTS citext;"
ynh_psql_execute_as_root "\connect $db_name
CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";"
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
ynh_print_info "Setting up source files ..." ynh_print_info --message="Setting up source files..."
ynh_app_setting_set $app final_path $final_path ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path/$app" ynh_setup_source --dest_dir="$final_path/$app"
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
ynh_print_info "Configuring nginx web server..." ynh_print_info --message="Configuring nginx web server..."
# Create a dedicated nginx config # Create a dedicated nginx config
ynh_add_nginx_config ynh_add_nginx_config
if [ $cache -eq 1 ] if [ $cache -eq 1 ]
then then
cp -rf "../conf/cache.conf" "/etc/nginx/conf.d/$app-cache.conf" cp -rf "../conf/cache.conf" "/etc/nginx/conf.d/$app-cache.conf"
ynh_replace_string "{APP}" "$app" "/etc/nginx/conf.d/$app-cache.conf" ynh_replace_string --match_string="{APP}" --replace_string="$app" --target_file="/etc/nginx/conf.d/$app-cache.conf"
ynh_replace_string "__SIZE__" "$size" "/etc/nginx/conf.d/$app-cache.conf" ynh_replace_string --match_string="__SIZE__" --replace_string="$size" --target_file="/etc/nginx/conf.d/$app-cache.conf"
ynh_store_file_checksum "/etc/nginx/conf.d/$app-cache.conf" ynh_store_file_checksum --file="/etc/nginx/conf.d/$app-cache.conf"
ynh_replace_string "{APP}" "$app" "../conf/media.conf" ynh_replace_string --match_string="{APP}" --replace_string="$app" --target_file="../conf/media.conf"
ynh_replace_string "__PORT__" "$port" "../conf/media.conf" ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/media.conf"
sudo su -c "cat ../conf/media.conf >> /etc/nginx/conf.d/$domain.d/$app.conf" sudo su -c "cat ../conf/media.conf >> /etc/nginx/conf.d/$domain.d/$app.conf"
ynh_store_file_checksum "/etc/nginx/conf.d/$domain.d/$app.conf" ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf"
fi fi
#================================================= #=================================================
# CREATE DEDICATED USER # CREATE DEDICATED USER
#================================================= #=================================================
ynh_print_info "Configuring system user ..." ynh_print_info --message="Configuring system user ..."
# Create a system user # Create a system user
ynh_system_user_create "$app" "$final_path" ynh_system_user_create --username=$app --home_dir="$final_path"
#================================================= #=================================================
# SPECIFIC SETUP # SPECIFIC SETUP
@ -166,27 +153,27 @@ ynh_system_user_create "$app" "$final_path"
cp -f ../conf/generated_config.exs "$final_path/$app/config/prod.secret.exs" cp -f ../conf/generated_config.exs "$final_path/$app/config/prod.secret.exs"
ynh_replace_string "__DOMAIN__" "$domain" "$final_path/$app/config/prod.secret.exs" ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/$app/config/prod.secret.exs"
ynh_replace_string "__KEY__" "$random_key" "$final_path/$app/config/prod.secret.exs" ynh_replace_string --match_string="__KEY__" --replace_string="$random_key" --target_file="$final_path/$app/config/prod.secret.exs"
ynh_replace_string "__INSTANCE_NAME__" "$name" "$final_path/$app/config/prod.secret.exs" ynh_replace_string --match_string="__INSTANCE_NAME__" --replace_string="$name" --target_file="$final_path/$app/config/prod.secret.exs"
ynh_replace_string "__DB_NAME__" "$db_name" "$final_path/$app/config/prod.secret.exs" ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$final_path/$app/config/prod.secret.exs"
ynh_replace_string "__DB_PWD__" "$db_pwd" "$final_path/$app/config/prod.secret.exs" ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$final_path/$app/config/prod.secret.exs"
ynh_replace_string "__ADMIN_EMAIL__" "$admin_email" "$final_path/$app/config/prod.secret.exs" ynh_replace_string --match_string="__ADMIN_EMAIL__" --replace_string="$admin_email" --target_file="$final_path/$app/config/prod.secret.exs"
ynh_replace_string "__PORT__" "$port" "$final_path/$app/config/prod.secret.exs" ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$final_path/$app/config/prod.secret.exs"
if [ $cache -eq 1 ] if [ $cache -eq 1 ]
then then
ynh_replace_string "__MEDIA_CACHE__" "true" "$final_path/$app/config/prod.secret.exs" ynh_replace_string --match_string="__MEDIA_CACHE__" --replace_string="true" --target_file="$final_path/$app/config/prod.secret.exs"
else else
ynh_replace_string "__MEDIA_CACHE__" "false" "$final_path/$app/config/prod.secret.exs" ynh_replace_string --match_string="__MEDIA_CACHE__" --replace_string="false" --target_file="$final_path/$app/config/prod.secret.exs"
fi fi
# Set registrations open/closed # Set registrations open/closed
if [ $registration -eq 1 ] if [ $registration -eq 1 ]
then then
ynh_replace_string "__REG__" "true" "$final_path/$app/config/prod.secret.exs" ynh_replace_string --match_string="__REG__" --replace_string="true" --target_file="$final_path/$app/config/prod.secret.exs"
else else
ynh_replace_string "__REG__" "false" "$final_path/$app/config/prod.secret.exs" ynh_replace_string --match_string="__REG__" --replace_string="false" --target_file="$final_path/$app/config/prod.secret.exs"
fi fi
#================================================= #=================================================
@ -208,7 +195,7 @@ pushd $final_path/$app
#Generate key pair #Generate key pair
sudo -u "$app" MIX_ENV=prod mix web_push.gen.keypair >> "config/prod.secret.exs" sudo -u "$app" MIX_ENV=prod mix web_push.gen.keypair >> "config/prod.secret.exs"
ynh_replace_string "administrator@example.com" "$admin_email" "$final_path/$app/config/prod.secret.exs" ynh_replace_string --match_string="administrator@example.com" --replace_string="$admin_email" --target_file="$final_path/$app/config/prod.secret.exs"
#Create uploads dir #Create uploads dir
mkdir uploads mkdir uploads
@ -217,7 +204,7 @@ popd
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
#================================================= #=================================================
ynh_print_info "Configuring a systemd service ..." ynh_print_info --message="Configuring a systemd service..."
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_add_systemd_config ynh_add_systemd_config
@ -227,7 +214,7 @@ ynh_add_systemd_config
#================================================= #=================================================
# Calculate and store the config file checksum into the app settings # Calculate and store the config file checksum into the app settings
ynh_store_file_checksum "$final_path/$app/config/prod.secret.exs" ynh_store_file_checksum --file="$final_path/$app/config/prod.secret.exs"
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
@ -241,7 +228,7 @@ chown -R "$app":"$app" "$final_path"
#================================================= #=================================================
# SETUP LOGROTATE # SETUP LOGROTATE
#================================================= #=================================================
ynh_print_info "Configuring log rotation ..." ynh_print_info --message="Configuring log rotation..."
# Use logrotate to manage application logfile(s) # Use logrotate to manage application logfile(s)
ynh_use_logrotate ynh_use_logrotate
@ -254,33 +241,34 @@ ynh_use_logrotate
# if using yunohost version 3.2 or more in the 'manifest.json', a description can be added # if using yunohost version 3.2 or more in the 'manifest.json', a description can be added
yunohost service add $app --description "$app daemon for Pleroma" --log "/var/log/$app/$app.log" yunohost service add $app --description "$app daemon for Pleroma" --log "/var/log/$app/$app.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_print_info --message="Starting a systemd service..."
ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Running Pleroma.Web.Endpoint"
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT
#================================================= #=================================================
ynh_print_info "Configuring SSOwat ..." ynh_print_info --message="Configuring SSOwat..."
# Make app public if necessary # Make app public if necessary
if [ $is_public -eq 1 ] if [ $is_public -eq 1 ]
then then
# 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=$app --key=unprotected_uris --value="/"
fi fi
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_print_info "Reloading nginx web server..." ynh_print_info --message="Reloading nginx web server..."
systemctl reload nginx ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# START SERVICE
#=================================================
ynh_systemd_action --action=start --service_name=$app --log_path=systemd --line_match="Running Pleroma.Web.Endpoint"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_print_info "Installation of $app completed" ynh_print_info --message="Installation of $app completed"

View file

@ -7,21 +7,21 @@
#================================================= #=================================================
source _common.sh source _common.sh
source ynh_systemd_action
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_print_info "Loading installation settings..." ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
port=$(ynh_app_setting_get $app port) port=$(ynh_app_setting_get --app=$app --key=port)
db_name=$(ynh_app_setting_get $app db_name) db_name=$(ynh_app_setting_get --app=$app --key=db_name)
final_path=$(ynh_app_setting_get $app final_path) db_user=$db_name
cache=$(ynh_app_setting_get "$app" cache) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
cache=$(ynh_app_setting_get --app=$app --key=cache)
#================================================= #=================================================
# STANDARD REMOVE # STANDARD REMOVE
@ -30,22 +30,16 @@ cache=$(ynh_app_setting_get "$app" cache)
#================================================= #=================================================
# Remove a service from the admin panel, added by `yunohost service add` # Remove a service from the admin panel, added by `yunohost service add`
if yunohost service status | grep -q $app if yunohost service status $app >/dev/null 2>&1
then then
ynh_print_info "Removing $app service" ynh_print_info --message="Removing $app service..."
yunohost service remove $app yunohost service remove $app
fi fi
#=================================================
# STOP SERVICE
#=================================================
ynh_systemd_action --action=stop --service_name=$app
#================================================= #=================================================
# STOP AND REMOVE SERVICE # STOP AND REMOVE SERVICE
#================================================= #=================================================
ynh_print_info "Stopping and removing the systemd service" ynh_print_info --message="Stopping and removing the systemd service..."
# Remove the dedicated systemd config # Remove the dedicated systemd config
ynh_remove_systemd_config ynh_remove_systemd_config
@ -53,18 +47,15 @@ ynh_remove_systemd_config
#================================================= #=================================================
# REMOVE THE POSTGRESQL DATABASE # REMOVE THE POSTGRESQL DATABASE
#================================================= #=================================================
ynh_print_info "Removing the PostgreSQL database" ynh_print_info --message="Removing the PostgreSQL database..."
ynh_psql_execute_as_root "\connect $db_name
SELECT pg_terminate_backend (pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '$db_name';"
# 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_user=$db_user --db_name=$db_name
#================================================= #=================================================
# REMOVE DEPENDENCIES # REMOVE DEPENDENCIES
#================================================= #=================================================
ynh_print_info "Removing dependencies" ynh_print_info --message="Removing dependencies..."
# Remove metapackage and its dependencies # Remove metapackage and its dependencies
ynh_remove_app_dependencies ynh_remove_app_dependencies
@ -72,24 +63,24 @@ ynh_remove_app_dependencies
#================================================= #=================================================
# REMOVE APP MAIN DIR # REMOVE APP MAIN DIR
#================================================= #=================================================
ynh_print_info "Removing app main directory" ynh_print_info --message="Removing app main directory..."
# Remove the app directory securely # Remove the app directory securely
ynh_secure_remove "$final_path" ynh_secure_remove --file="$final_path"
#================================================= #=================================================
# REMOVE NGINX CONFIGURATION # REMOVE NGINX CONFIGURATION
#================================================= #=================================================
ynh_print_info "Removing nginx web server configuration" ynh_print_info --message="Removing nginx web server configuration..."
# Remove the dedicated nginx config # Remove the dedicated nginx config
ynh_remove_nginx_config ynh_remove_nginx_config
ynh_secure_remove "/etc/nginx/conf.d/$app-cache.conf" ynh_secure_remove --file="/etc/nginx/conf.d/$app-cache.conf"
#================================================= #=================================================
# REMOVE LOGROTATE CONFIGURATION # REMOVE LOGROTATE CONFIGURATION
#================================================= #=================================================
ynh_print_info "Removing logrotate configuration" ynh_print_info --message="Removing logrotate configuration..."
# Remove the app-specific logrotate config # Remove the app-specific logrotate config
ynh_remove_logrotate ynh_remove_logrotate
@ -97,11 +88,11 @@ ynh_remove_logrotate
#================================================= #=================================================
# CLOSE A PORT # CLOSE A PORT
#================================================= #=================================================
ynh_print_info "Close ports" ynh_print_info --message="Closing ports"
if yunohost firewall list | grep -q "\- $port$" if yunohost firewall list | grep -q "\- $port$"
then then
ynh_print_info "Closing port $port" ynh_print_info --message="Closing port $port..."
ynh_exec_warn_less yunohost firewall disallow TCP $port ynh_exec_warn_less yunohost firewall disallow TCP $port
fi fi
@ -122,13 +113,13 @@ ynh_secure_remove "/var/log/$app/"
#================================================= #=================================================
# REMOVE DEDICATED USER # REMOVE DEDICATED USER
#================================================= #=================================================
ynh_print_info "Removing the dedicated system user" ynh_print_info --message="Removing the dedicated system user..."
# Delete a system user # Delete a system user
ynh_system_user_delete $app ynh_system_user_delete --username=$app
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_print_info "Removal of $app completed" ynh_print_info --message="Removal of $app completed"

View file

@ -7,8 +7,7 @@
#================================================= #=================================================
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source ../settings/scripts/ynh_systemd_action source ../settings/scripts/ynh_add_extra_apt_repos__3
source ../settings/scripts/ynh_add_secure_repos__3
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
@ -24,28 +23,28 @@ ynh_abort_if_errors
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_print_info "Loading settings..." ynh_print_info --message="Loading settings..."
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get $app path) path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get $app final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
port=$(ynh_app_setting_get $app port) db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_name=$(ynh_app_setting_get $app db_name) db_user=$db_name
db_pwd=$(ynh_app_setting_get $app db_pwd) db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd)
cache=$(ynh_app_setting_get $app cache) port=$(ynh_app_setting_get --app=$app --key=port)
cache=$(ynh_app_setting_get --app=$app --key=cache)
#================================================= #=================================================
# CHECK IF THE APP CAN BE RESTORED # CHECK IF THE APP CAN BE RESTORED
#================================================= #=================================================
ynh_print_info "Validating restoration parameters..." ynh_print_info --message="Validating restoration parameters..."
ynh_webpath_available $domain $path_url \ ynh_webpath_available --domain=$domain --path_url=$path_url \
|| ynh_die "Path not available: ${domain}${path_url}" || ynh_die --message="Path not available: ${domain}${path_url}"
test ! -d $final_path \ test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path " || ynh_die --message="There is already a directory: $final_path "
#================================================= #=================================================
# STANDARD RESTORATION STEPS # STANDARD RESTORATION STEPS
@ -53,26 +52,26 @@ test ! -d $final_path \
# RESTORE THE NGINX CONFIGURATION # RESTORE THE NGINX CONFIGURATION
#================================================= #=================================================
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
if [ $cache -eq 1 ] if [ $cache -eq 1 ]
then then
ynh_restore_file "/etc/nginx/conf.d/$app-cache.conf" ynh_restore_file --origin_path="/etc/nginx/conf.d/$app-cache.conf"
fi fi
#================================================= #=================================================
# RESTORE THE APP MAIN DIR # RESTORE THE APP MAIN DIR
#================================================= #=================================================
ynh_print_info "Restoring the app main directory..." ynh_print_info --message="Restoring the app main directory..."
ynh_restore_file "$final_path" ynh_restore_file --origin_path="$final_path"
#================================================= #=================================================
# RECREATE THE DEDICATED USER # RECREATE THE DEDICATED USER
#================================================= #=================================================
ynh_print_info "Recreating the dedicated system user..." ynh_print_info --message="Recreating the dedicated system user..."
# Create the dedicated user (if not existing) # Create the dedicated user (if not existing)
ynh_system_user_create "$app" "$final_path" ynh_system_user_create --username=$app --home_dir="$final_path"
#================================================= #=================================================
# RESTORE USER RIGHTS # RESTORE USER RIGHTS
@ -86,45 +85,34 @@ chown -R "$app":"$app" "$final_path"
#================================================= #=================================================
# REINSTALL DEPENDENCIES # REINSTALL DEPENDENCIES
#================================================= #=================================================
ynh_print_info "Reinstalling dependencies..." ynh_print_info --message="Reinstalling dependencies..."
# Define and install dependencies # Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies ynh_install_app_dependencies $pkg_dependencies
#=================================================
# REINSTALL EXTRA DEPENDENCIES
#=================================================
ynh_print_info "Reinstalling extra dependencies ..."
lsb_name="$(lsb_release --codename --short)" lsb_name="$(lsb_release --codename --short)"
ynh_install_extra_app_dependencies --repo="deb http://packages.erlang-solutions.com/debian $lsb_name contrib" --package="$extra_pkg_dependencies" --key='https://packages.erlang-solutions.com/debian/erlang_solutions.asc' ynh_install_extra_app_dependencies --repo="deb http://packages.erlang-solutions.com/debian $lsb_name contrib" --package="$extra_pkg_dependencies" --key='https://packages.erlang-solutions.com/debian/erlang_solutions.asc'
#================================================= #=================================================
# RESTORE THE POSTGRESQL DATABASE # RESTORE THE POSTGRESQL DATABASE
#================================================= #=================================================
ynh_print_info "Restoring the PostgreSQL database..." ynh_print_info --message="Restoring the PostgreSQL database..."
ynh_psql_test_if_first_run ynh_psql_test_if_first_run
ynh_psql_create_user "$app" "$db_pwd" ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_psql_execute_as_root "CREATE DATABASE $db_name ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 OWNER $db_name;" ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS unaccent;" --database=$db_name
ynh_psql_execute_as_root "\connect $db_name ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name
CREATE EXTENSION IF NOT EXISTS unaccent;" ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS citext;" --database=$db_name
ynh_psql_execute_as_root "\connect $db_name ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";" --database=$db_name
CREATE EXTENSION IF NOT EXISTS pg_trgm;" ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name"
ynh_psql_execute_as_root "\connect $db_name
CREATE EXTENSION IF NOT EXISTS citext;"
ynh_psql_execute_as_root "\connect $db_name
CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";"
ynh_psql_execute_file_as_root ./db.sql "$db_name"
#================================================= #=================================================
# RESTORE SYSTEMD # RESTORE SYSTEMD
#================================================= #=================================================
ynh_print_info "Restoring the systemd configuration..." ynh_print_info --message="Restoring the systemd configuration..."
ynh_restore_file "/etc/systemd/system/$app.service" ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service systemctl enable $app.service
systemctl daemon-reload
#================================================= #=================================================
# ADVERTISE SERVICE IN ADMIN PANEL # ADVERTISE SERVICE IN ADMIN PANEL
@ -132,29 +120,30 @@ systemctl daemon-reload
yunohost service add $app --description "$app daemon for Pleroma" --log "/var/log/$app/$app.log" yunohost service add $app --description "$app daemon for Pleroma" --log "/var/log/$app/$app.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_print_info --message="Starting a systemd service..."
ynh_systemd_action --action=start --service_name=$app --log_path=systemd --line_match="Running Pleroma.Web.Endpoint"
#================================================= #=================================================
# RESTORE THE LOGROTATE CONFIGURATION # RESTORE THE LOGROTATE CONFIGURATION
#================================================= #=================================================
ynh_restore_file "/etc/logrotate.d/$app" ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
#================================================= #=================================================
# RELOAD NGINX AND PHP-FPM # RELOAD NGINX AND PHP-FPM
#================================================= #=================================================
ynh_print_info "Reloading nginx web server..." ynh_print_info --message="Reloading nginx web server..."
systemctl reload nginx ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# START SERVICE
#=================================================
ynh_systemd_action --action=start --service_name=$app --log_path=systemd --line_match="Running Pleroma.Web.Endpoint"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_print_info "Restoration completed for $app" ynh_print_info --message="Restoration completed for $app"

View file

@ -7,88 +7,92 @@
#================================================= #=================================================
source _common.sh source _common.sh
source ynh_systemd_action source ynh_add_extra_apt_repos__3
source ynh_add_secure_repos__3
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_print_info "Loading installation settings..." ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get $app path) path_url=$(ynh_app_setting_get --app=$app --key=path)
admin=$(ynh_app_setting_get $app admin) admin=$(ynh_app_setting_get --app=$app --key=admin)
is_public=$(ynh_app_setting_get $app is_public) is_public=$(ynh_app_setting_get --app=$app --key=is_public)
final_path=$(ynh_app_setting_get $app final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get "$app" db_name) db_name=$(ynh_app_setting_get --app=$app --key=db_name)
admin_email=$(ynh_app_setting_get "$app" admin_email) admin_email=$(ynh_app_setting_get --app=$app --key=admin_email)
random_key=$(ynh_app_setting_get "$app" random_key) random_key=$(ynh_app_setting_get --app=$app --key=random_key)
name=$(ynh_app_setting_get "$app" name) name=$(ynh_app_setting_get --app=$app --key=name)
port=$(ynh_app_setting_get "$app" port) port=$(ynh_app_setting_get --app=$app --key=port)
db_pwd=$(ynh_app_setting_get "$app" db_pwd) db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd)
cache=$(ynh_app_setting_get "$app" cache) cache=$(ynh_app_setting_get --app=$app --key=cache)
size=$(ynh_app_setting_get "$app" size) size=$(ynh_app_setting_get --app=$app --key=size)
registration=$(ynh_app_setting_get "$app" registration) registration=$(ynh_app_setting_get --app=$app --key=registration)
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#================================================= #=================================================
# ENSURE DOWNWARD COMPATIBILITY # ENSURE DOWNWARD COMPATIBILITY
#================================================= #=================================================
ynh_print_info "Ensuring downward compatibility..." ynh_print_info --message="Ensuring downward compatibility..."
# Fix is_public as a boolean value # Fix is_public as a boolean value
if [ "$is_public" = "Yes" ]; then if [ "$is_public" = "Yes" ]; then
ynh_app_setting_set $app is_public 1 ynh_app_setting_set --app=$app --key=is_public --value=1
is_public=1 is_public=1
elif [ "$is_public" = "No" ]; then elif [ "$is_public" = "No" ]; then
ynh_app_setting_set $app is_public 0 ynh_app_setting_set --app=$app --key=is_public --value=0
is_public=0 is_public=0
fi fi
# If db_name doesn't exist, create it # If db_name doesn't exist, create it
if [ -z $db_name ]; then if [ -z "$db_name" ]; then
db_name=$(ynh_sanitize_dbid $app) db_name=$(ynh_sanitize_dbid --db_name=$app)
ynh_app_setting_set $app db_name $db_name ynh_app_setting_set --app=$app --key=db_name --value=$db_name
fi fi
# If final_path doesn't exist, create it # If final_path doesn't exist, create it
if [ -z $final_path ]; then if [ -z "$final_path" ]; then
final_path=/var/www/$app final_path=/var/www/$app
ynh_app_setting_set $app final_path $final_path ynh_app_setting_set --app=$app --key=final_path --value=$final_path
fi fi
#Switch variables name #Switch variables name
psql_db=$(ynh_app_setting_get "$app" psql_db) psql_db=$(ynh_app_setting_get --app=$app --key=psql_db)
if [ -n "$psql_db" ] if [ -n "$psql_db" ]
then then
db_name=$(ynh_app_setting_get "$app" psql_db) db_name=$(ynh_app_setting_get --app=$app --key=psql_db)
db_pwd=$(ynh_app_setting_get "$app" psqlpwd) db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
ynh_app_setting_set "$app" db_name "$db_name" ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_app_setting_set "$app" db_pwd "$db_pwd" ynh_app_setting_set --app=$app --key=db_pwd --value=$db_pwd
ynh_app_setting_delete "$app" psql_db ynh_app_setting_delete --app=$app --key=psql_db
ynh_app_setting_delete "$app" psqlpwd ynh_app_setting_delete --app=$app --key=psqlpwd
fi fi
#Close a port #Close a port
if yunohost firewall list | grep -q "\- $port$" if yunohost firewall list | grep -q "\- $port$"
then then
echo "Close port $port" >&2 ynh_print_info --message="Closing port $port..."
yunohost firewall disallow TCP $port 2>&1 ynh_exec_warn_less yunohost firewall disallow TCP $port
fi fi
# Remove old repository # Remove old repository
ynh_secure_remove "/etc/apt/sources.list.d/erlang-solutions.list" ynh_secure_remove --file="/etc/apt/sources.list.d/erlang-solutions.list"
apt-key del A14F4FCA apt-key del A14F4FCA
#================================================= #=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#================================================= #=================================================
ynh_print_info "Backing up the app before upgrading (may take a while)..." ynh_print_info --message="Backing up the app before upgrading (may take a while)..."
# Backup the current version of the app # Backup the current version of the app
ynh_backup_before_upgrade ynh_backup_before_upgrade
@ -100,72 +104,72 @@ ynh_clean_setup () {
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
#=================================================
# STOP SERVICE
#=================================================
ynh_systemd_action --action=stop --service_name=$app
#================================================= #=================================================
# CHECK THE PATH # CHECK THE PATH
#================================================= #=================================================
# Normalize the URL path syntax # Normalize the URL path syntax
path_url=$(ynh_normalize_url_path $path_url) path_url=$(ynh_normalize_url_path --path_url=$path_url)
#================================================= #=================================================
# STANDARD UPGRADE STEPS # STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_print_info --message="Stopping a systemd service..."
ynh_systemd_action --service_name=$app --action="stop"
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
ynh_print_info "Upgrading source files..."
# Download, check integrity, uncompress and patch the source from app.src if [ "$upgrade_type" == "UPGRADE_APP" ]
ynh_setup_source "$final_path/$app" then
ynh_print_info --message="Upgrading source files..."
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path/$app"
fi
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
ynh_print_info "Upgrading nginx web server configuration..." ynh_print_info --message="Upgrading nginx web server configuration..."
# Create a dedicated nginx config # Create a dedicated nginx config
ynh_add_nginx_config ynh_add_nginx_config
ynh_secure_remove /etc/nginx/conf.d/$app-cache.conf ynh_secure_remove --file="/etc/nginx/conf.d/$app-cache.conf"
if [ $cache -eq 1 ] if [ $cache -eq 1 ]
then then
cp -rf "../conf/cache.conf" "/etc/nginx/conf.d/$app-cache.conf" cp -rf "../conf/cache.conf" "/etc/nginx/conf.d/$app-cache.conf"
ynh_replace_string "{APP}" "$app" "/etc/nginx/conf.d/$app-cache.conf" ynh_replace_string --match_string="{APP}" --replace_string="$app" --target_file="/etc/nginx/conf.d/$app-cache.conf"
ynh_replace_string "__SIZE__" "$size" "/etc/nginx/conf.d/$app-cache.conf" ynh_replace_string --match_string="__SIZE__" --replace_string="$size" --target_file="/etc/nginx/conf.d/$app-cache.conf"
ynh_store_file_checksum "/etc/nginx/conf.d/$app-cache.conf" ynh_store_file_checksum --file="/etc/nginx/conf.d/$app-cache.conf"
ynh_replace_string "{APP}" "$app" "../conf/media.conf" ynh_replace_string --match_string="{APP}" --replace_string="$app" --target_file="../conf/media.conf"
ynh_replace_string "__PORT__" "$port" "../conf/media.conf" ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/media.conf"
sudo su -c "cat ../conf/media.conf >> /etc/nginx/conf.d/$domain.d/$app.conf" sudo su -c "cat ../conf/media.conf >> /etc/nginx/conf.d/$domain.d/$app.conf"
ynh_store_file_checksum "/etc/nginx/conf.d/$domain.d/$app.conf" ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf"
fi fi
#================================================= #=================================================
# UPGRADE DEPENDENCIES # UPGRADE DEPENDENCIES
#================================================= #=================================================
ynh_print_info "Upgrading dependencies..." ynh_print_info --message="Upgrading dependencies..."
ynh_install_app_dependencies $pkg_dependencies ynh_install_app_dependencies $pkg_dependencies
#=================================================
# INSTALL EXTRA DEPENDENCIES
#=================================================
ynh_print_info "Installing extra dependencies ..."
lsb_name="$(lsb_release --codename --short)" lsb_name="$(lsb_release --codename --short)"
ynh_install_extra_app_dependencies --repo="deb http://packages.erlang-solutions.com/debian $lsb_name contrib" --package="$extra_pkg_dependencies" --key='https://packages.erlang-solutions.com/debian/erlang_solutions.asc' ynh_install_extra_app_dependencies --repo="deb http://packages.erlang-solutions.com/debian $lsb_name contrib" --package="$extra_pkg_dependencies" --key='https://packages.erlang-solutions.com/debian/erlang_solutions.asc'
#================================================= #=================================================
# CREATE DEDICATED USER # CREATE DEDICATED USER
#================================================= #=================================================
ynh_print_info "Making sure dedicated system user exists..." ynh_print_info --message="Making sure dedicated system user exists..."
# Create a dedicated user (if not existing) # Create a dedicated user (if not existing)
ynh_system_user_create "$app" "$final_path" ynh_system_user_create --username=$app --home_dir="$final_path"
#================================================= #=================================================
# SPECIFIC UPGRADE # SPECIFIC UPGRADE
@ -175,27 +179,27 @@ ynh_system_user_create "$app" "$final_path"
cp -f ../conf/generated_config.exs "$final_path/$app/config/prod.secret.exs" cp -f ../conf/generated_config.exs "$final_path/$app/config/prod.secret.exs"
ynh_replace_string "__DOMAIN__" "$domain" "$final_path/$app/config/prod.secret.exs" ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/$app/config/prod.secret.exs"
ynh_replace_string "__KEY__" "$random_key" "$final_path/$app/config/prod.secret.exs" ynh_replace_string --match_string="__KEY__" --replace_string="$random_key" --target_file="$final_path/$app/config/prod.secret.exs"
ynh_replace_string "__INSTANCE_NAME__" "$name" "$final_path/$app/config/prod.secret.exs" ynh_replace_string --match_string="__INSTANCE_NAME__" --replace_string="$name" --target_file="$final_path/$app/config/prod.secret.exs"
ynh_replace_string "__DB_NAME__" "$db_name" "$final_path/$app/config/prod.secret.exs" ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$final_path/$app/config/prod.secret.exs"
ynh_replace_string "__DB_PWD__" "$db_pwd" "$final_path/$app/config/prod.secret.exs" ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$final_path/$app/config/prod.secret.exs"
ynh_replace_string "__ADMIN_EMAIL__" "$admin_email" "$final_path/$app/config/prod.secret.exs" ynh_replace_string --match_string="__ADMIN_EMAIL__" --replace_string="$admin_email" --target_file="$final_path/$app/config/prod.secret.exs"
ynh_replace_string "__PORT__" "$port" "$final_path/$app/config/prod.secret.exs" ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$final_path/$app/config/prod.secret.exs"
if [ $cache -eq 1 ] if [ $cache -eq 1 ]
then then
ynh_replace_string "__MEDIA_CACHE__" "true" "$final_path/$app/config/prod.secret.exs" ynh_replace_string --match_string="__MEDIA_CACHE__" --replace_string="true" --target_file="$final_path/$app/config/prod.secret.exs"
else else
ynh_replace_string "__MEDIA_CACHE__" "false" "$final_path/$app/config/prod.secret.exs" ynh_replace_string --match_string="__MEDIA_CACHE__" --replace_string="false" --target_file="$final_path/$app/config/prod.secret.exs"
fi fi
# Set registrations open/closed # Set registrations open/closed
if [ $registration -eq 1 ] if [ $registration -eq 1 ]
then then
ynh_replace_string "__REG__" "true" "$final_path/$app/config/prod.secret.exs" ynh_replace_string --match_string="__REG__" --replace_string="true" --target_file="$final_path/$app/config/prod.secret.exs"
else else
ynh_replace_string "__REG__" "false" "$final_path/$app/config/prod.secret.exs" ynh_replace_string --match_string="__REG__" --replace_string="false" --target_file="$final_path/$app/config/prod.secret.exs"
fi fi
#================================================= #=================================================
@ -210,17 +214,21 @@ pushd $final_path/$app
#Generate key pair #Generate key pair
sudo -u "$app" MIX_ENV=prod mix web_push.gen.keypair >> "config/prod.secret.exs" sudo -u "$app" MIX_ENV=prod mix web_push.gen.keypair >> "config/prod.secret.exs"
ynh_replace_string "administrator@example.com" "$admin_email" "$final_path/$app/config/prod.secret.exs" ynh_replace_string --match_string="administrator@example.com" --replace_string="$admin_email" --target_file="$final_path/$app/config/prod.secret.exs"
popd popd
ynh_backup_if_checksum_is_different "$final_path/$app/config/prod.secret.exs" #=================================================
# STORE THE CONFIG FILE CHECKSUM
#=================================================
ynh_backup_if_checksum_is_different --file="$final_path/$app/config/prod.secret.exs"
# Recalculate and store the checksum of the file for the next upgrade. # Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum "$final_path/$app/config/prod.secret.exs" ynh_store_file_checksum --file="$final_path/$app/config/prod.secret.exs"
#================================================= #=================================================
# SETUP LOGROTATE # SETUP LOGROTATE
#================================================= #=================================================
ynh_print_info "Upgrading logrotate configuration..." ynh_print_info --message="Upgrading logrotate configuration..."
# Use logrotate to manage app-specific logfile(s) # Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append ynh_use_logrotate --non-append
@ -228,7 +236,7 @@ ynh_use_logrotate --non-append
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
#================================================= #=================================================
ynh_print_info "Upgrading systemd configuration..." ynh_print_info --message="Upgrading systemd configuration..."
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_add_systemd_config ynh_add_systemd_config
@ -245,31 +253,32 @@ chown -R "$app":"$app" "$final_path"
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT
#================================================= #=================================================
ynh_print_info "Upgrading SSOwat configuration..." ynh_print_info --message="Upgrading SSOwat configuration..."
# Make app public if necessary # Make app public if necessary
if [ $is_public -eq 1 ] if [ $is_public -eq 1 ]
then then
# 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=$app --key=unprotected_uris --value="/"
fi fi
#=================================================
# RELOAD NGINX
#=================================================
ynh_print_info "Reloading nginx web server..."
systemctl reload nginx
#================================================= #=================================================
# START SERVICE # START SERVICE
#================================================= #=================================================
ynh_print_info --message="Starting a systemd service..."
ynh_systemd_action --action=start --service_name=$app --log_path=systemd --line_match="Running Pleroma.Web.Endpoint" ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Running Pleroma.Web.Endpoint"
sleep 10 sleep 10
#=================================================
# RELOAD NGINX
#=================================================
ynh_print_info --message="Reloading nginx web server..."
ynh_systemd_action --service_name=nginx --action=reload
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_print_info "Upgrade of $app completed" ynh_print_info --message="Upgrade of $app completed"

View file

@ -1,89 +0,0 @@
#!/bin/bash
# Start (or other actions) a service, print a log in case of failure and optionnaly wait until the service is completely started
#
# usage: ynh_systemd_action [-n service_name] [-a action] [ [-l "line to match"] [-p log_path] [-t timeout] [-e length] ]
# | arg: -n, --service_name= - Name of the service to reload. Default : $app
# | arg: -a, --action= - Action to perform with systemctl. Default: start
# | arg: -l, --line_match= - Line to match - The line to find in the log to attest the service have finished to boot.
# If not defined it don't wait until the service is completely started.
# | arg: -p, --log_path= - Log file - Path to the log file. Default : /var/log/$app/$app.log
# | arg: -t, --timeout= - Timeout - The maximum time to wait before ending the watching. Default : 300 seconds.
# | arg: -e, --length= - Length of the error log : Default : 20
ynh_systemd_action() {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [n]=service_name= [a]=action= [l]=line_match= [p]=log_path= [t]=timeout= [e]=length= )
local service_name
local action
local line_match
local length
local log_path
local timeout
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
local service_name="${service_name:-$app}"
local action=${action:-start}
local log_path="${log_path:-/var/log/$service_name/$service_name.log}"
local length=${length:-20}
local timeout=${timeout:-300}
# Start to read the log
if [[ -n "${line_match:-}" ]]
then
local templog="$(mktemp)"
# Following the starting of the app in its log
if [ "$log_path" == "systemd" ] ; then
# Read the systemd journal
journalctl -u $service_name -f --since=-45 > "$templog" &
else
# Read the specified log file
tail -F -n0 "$log_path" > "$templog" &
fi
# Get the PID of the tail command
local pid_tail=$!
fi
echo "${action^} the service $service_name" >&2
systemctl $action $service_name \
|| ( journalctl --lines=$length -u $service_name >&2 \
; test -n "$log_path" && echo "--" && tail --lines=$length "$log_path" >&2 \
; false )
# Start the timeout and try to find line_match
if [[ -n "${line_match:-}" ]]
then
local i=0
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 --quiet "$line_match" "$templog"
then
echo "The service $service_name has correctly started." >&2
break
fi
echo -n "." >&2
sleep 1
done
if [ $i -eq $timeout ]
then
echo "The service $service_name didn't fully started before the timeout." >&2
journalctl --lines=$length -u $service_name >&2
test -n "$log_path" && echo "--" && tail --lines=$length "$log_path" >&2
fi
echo ""
ynh_clean_check_starting
fi
}
# Clean temporary process and file used by ynh_check_starting
# (usually used in ynh_clean_setup scripts)
#
# usage: ynh_clean_check_starting
ynh_clean_check_starting () {
# Stop the execution of tail.
kill -s 15 $pid_tail 2>&1
ynh_secure_remove "$templog" 2>&1
}