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

Merge pull request #150 from YunoHost-Apps/example_ynh

Example ynh
This commit is contained in:
yalh76 2020-02-26 19:44:06 +01:00 committed by GitHub
commit e262825c35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 149 additions and 121 deletions

View file

@ -17,7 +17,12 @@
setup_private=1
setup_public=1
upgrade=1
upgrade=1 from_commit=280ba0d4a9ebb9d8948e0db97200dbcb89b6c323
# 1.3.1
upgrade=1 from_commit=22ca62492ce32d22ac710758bca4e3be0534566c
# 1.4.1
upgrade=1 from_commit=33620aacc6f6e2ac003ae6bd2de57dc5d74a5343
# 2.0.0
upgrade=1 from_commit=032acd21b36030c9c1680d882d54c8011439e83c
backup_restore=1
multi_instance=1
# This test is no longer necessary since the version 2.7 (PR: https://github.com/YunoHost/yunohost/pull/304), you can still do it if your app could be installed with this version.

View file

@ -1,11 +1,12 @@
# Bypass PeerTube for performance reasons. Could be removed
location ~ ^/client/(.*\.(js|css|woff2|otf|ttf|woff|eot))$ {
# Bypass PeerTube for performance reasons. Could be removed
location ~ ^/client/(.*\.(js|css|woff2|otf|ttf|woff|eot))$ {
add_header Cache-Control "public, max-age=31536000, immutable";
alias __FINALPATH__/client/dist/$1;
}
# Bypass PeerTube for performance reasons. Could be removed
location ~ ^/static/(thumbnails|avatars)/ {
}
# Bypass PeerTube for performance reasons. Could be removed
location ~ ^/static/(thumbnails|avatars)/ {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
@ -27,9 +28,9 @@
rewrite ^/static/(thumbnails|avatars)/(.*)$ /$1/$2 break;
try_files $uri /;
}
}
location / {
location / {
if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent;
}
@ -56,10 +57,10 @@
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
}
}
# Bypass PeerTube for performance reasons. Could be removed
location ~ ^/static/(webseed|redundancy)/ {
# Bypass PeerTube for performance reasons. Could be removed
location ~ ^/static/(webseed|redundancy)/ {
# Clients usually have 4 simultaneous webseed connections, so the real limit is 3MB/s per client
limit_rate 800k;
@ -88,12 +89,10 @@
rewrite ^/static/redundancy/(.*)$ /redundancy/$1 break;
try_files $uri /;
}
}
# Websocket tracker
location /tracker/socket {
# Websocket tracker
location /tracker/socket {
# Peers send a message to the tracker every 15 minutes
# Don't close the websocket before this time
proxy_read_timeout 1200s;
@ -103,7 +102,7 @@
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass http://localhost:__PORT__;
}
}
location /socket.io {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@ -115,7 +114,4 @@ location /socket.io {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}

View file

@ -13,6 +13,7 @@ source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_print_info --message="Managing script failure..."
ynh_clean_setup () {
ynh_clean_check_starting
@ -38,7 +39,7 @@ db_name=$(ynh_app_setting_get --app=$app --key=psql_db)
#=================================================
ynh_print_info --message="Stopping a systemd service..."
ynh_systemd_action --service_name=$app --action="stop"
ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd"
#=================================================
# BACKUP THE APP MAIN DIR

View file

@ -14,6 +14,7 @@ source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_print_info --message="Managing script failure..."
ynh_clean_setup () {
ynh_clean_check_starting
@ -24,6 +25,7 @@ ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
ynh_print_info --message="Retrieving arguments from the manifest..."
domain=$YNH_APP_ARG_DOMAIN
path_url="/"
@ -61,7 +63,7 @@ ynh_app_setting_set --app=$app --key=is_public --value=$is_public
#=================================================
ynh_print_info --message="Configuring firewall..."
# Find a free port
# Find an available port
port=$(ynh_find_port --port=9000)
ynh_app_setting_set --app=$app --key=port --value=$port
@ -132,7 +134,7 @@ ynh_system_user_create --username=$app --home_dir=$final_path
#=================================================
# CREATE THE DATA DIRECTORY
#=================================================
ynh_print_info --message="Create the data directory..."
ynh_print_info --message="Creating the data directory..."
# Define app's data directory
datadir="/home/yunohost.app/${app}/storage"
@ -146,6 +148,7 @@ chown -R "$app":"$app" "$datadir"
#=================================================
# MODIFY A CONFIG FILE
#=================================================
ynh_print_info --message="Modifying a config file..."
cp ../conf/production.yaml "$final_path/config/production.yaml"
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/config/production.yaml"
@ -161,6 +164,7 @@ cp ../conf/local-production.json "$final_path/config/local-production.json"
#=================================================
# FIX NGINX DOMAIN CONFIGURATION
#=================================================
ynh_print_info --message="Fixing nginx domain configuration..."
cp -R ../conf/nginx_regen_conf.hook /usr/share/yunohost/hooks/conf_regen/15-nginx_$app
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="/usr/share/yunohost/hooks/conf_regen/15-nginx_$app"
@ -169,6 +173,7 @@ yunohost tools regen-conf nginx
#=================================================
# STORE THE CHECKSUM OF THE CONFIG FILE
#=================================================
ynh_print_info --message="Storing the config file checksum..."
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum --file="$final_path/config/production.yaml"
@ -177,6 +182,7 @@ ynh_store_file_checksum --file="$final_path/config/local-production.json"
#=================================================
# BUILD YARN DEPENDENCIES
#=================================================
ynh_print_info --message="Building yarn dependencies..."
chown -R "$app":"$app" $final_path
@ -188,6 +194,7 @@ popd
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_print_info --message="Configuring a systemd service..."
ynh_replace_string --match_string="__ENV_PATH__" --replace_string="$PATH" --target_file="../conf/systemd.service"
# Create a dedicated systemd config
@ -198,6 +205,7 @@ ynh_add_systemd_config
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
ynh_print_info --message="Securing files and directories..."
# Set permissions to app files
chown -R "$app":"$app" $final_path
@ -211,10 +219,10 @@ ynh_print_info --message="Configuring log rotation..."
ynh_use_logrotate --logfile="/home/yunohost.app/${app}/storage/logs/peertube.log"
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_print_info --message="Integrating service in YunoHost..."
# 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 Peertube" --log "/home/yunohost.app/${app}/storage/logs/peertube.log"
#=================================================
@ -222,6 +230,7 @@ yunohost service add $app --description "$app daemon for Peertube" --log "/home/
#=================================================
ynh_print_info --message="Starting a systemd service..."
# Start a systemd service
#ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Server listening on localhost"
#=================================================

View file

@ -27,11 +27,12 @@ admin_email=$(ynh_app_setting_get --app=$app --key=admin_email)
#=================================================
# STANDARD REMOVE
#=================================================
# REMOVE SERVICE FROM ADMIN PANEL
# REMOVE SERVICE INTEGRATION IN YUNOHOST
#=================================================
ynh_print_info --message="Removing service integration in YunoHost..."
# Remove a service from the admin panel, added by `yunohost service add`
if ynh_exec_warn_less yunohost service status $app >/dev/null 2>&1
# Remove the service from the list of services known by Yunohost (added from `yunohost service add`)
if ynh_exec_warn_less yunohost service status $app >/dev/null
then
ynh_print_info --message="Removing $app service..."
yunohost service remove $app
@ -89,6 +90,7 @@ ynh_remove_logrotate
#=================================================
# CLOSE A PORT
#=================================================
ynh_print_info --message="Closing a port..."
if yunohost firewall list | grep -q "\- $port$"
then
@ -101,6 +103,7 @@ fi
#=================================================
# RESTORE ORIGINAL NGINX DOMAIN CONFIGURATION
#=================================================
ynh_print_info --message="Restoring original nginx domain configuration..."
ynh_secure_remove --file="/usr/share/yunohost/hooks/conf_regen/15-nginx_$app"
yunohost tools regen-conf nginx

View file

@ -13,6 +13,7 @@ source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_print_info --message="Managing script failure..."
ynh_clean_setup () {
ynh_clean_check_starting
@ -50,6 +51,7 @@ test ! -d $final_path \
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_print_info --message="Restoring the nginx configuration..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
@ -71,6 +73,7 @@ ynh_system_user_create --username=$app --home_dir=$final_path
#=================================================
# RESTORE USER RIGHTS
#=================================================
ynh_print_info --message="Restoring user rights..."
# Set right permissions
if [ ! -d "/home/yunohost.app/$app" ]; then
@ -104,6 +107,7 @@ ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ st
#=================================================
# FIX NGINX DOMAIN CONFIGURATION
#=================================================
ynh_print_info --message="Fixing nginx domain configuration..."
ynh_restore_file --origin_path="/usr/share/yunohost/hooks/conf_regen/15-nginx_$app"
yunohost tools regen-conf nginx
@ -126,8 +130,9 @@ ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_print_info --message="Integrating service in YunoHost..."
yunohost service add $app --description "$app daemon for Peertube" --log "/home/yunohost.app/${app}/storage/logs/peertube.log"
@ -141,6 +146,7 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --l
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
ynh_print_info --message="Restoring the logrotate configuration..."
ynh_restore_file --origin_path="/etc/logrotate.d/$app"

View file

@ -29,6 +29,7 @@ db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
#=================================================
# CHECK VERSION
#=================================================
ynh_print_info --message="Checking version..."
upgrade_type=$(ynh_check_app_version_changed)
@ -88,7 +89,7 @@ ynh_abort_if_errors
#=================================================
ynh_print_info --message="Stopping a systemd service..."
ynh_systemd_action --service_name=$app --action="stop"
ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
@ -102,8 +103,11 @@ then
tmpdir="$(mktemp -d)"
# Backup the config file in the temp dir
cp -a "$final_path/config/local-production.json" "$tmpdir/local-production.json"
cp -a "$final_path/config/production.yaml" "$tmpdir/production.yaml"
if [ -s "$final_path/config/local-production.json" ]
then
cp -a "$final_path/config/local-production.json" "$tmpdir/local-production.json"
fi
# Remove the app directory securely
ynh_secure_remove --file="$final_path"
@ -166,14 +170,15 @@ ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ st
#=================================================
ynh_print_info --message="Making sure dedicated system user exists..."
# Create a system user
ynh_system_user_create "$app"
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app
#=================================================
# SPECIFIC UPGRADE
#=================================================
# MODIFY A CONFIG FILE
#=================================================
ynh_print_info --message="Modifying a config file..."
ynh_backup_if_checksum_is_different --file="$final_path/config/local-production.json"
ynh_backup_if_checksum_is_different --file="$final_path/config/production.yaml"
@ -193,6 +198,7 @@ ynh_store_file_checksum --file="$final_path/config/production.yaml"
#=================================================
# FIX NGINX DOMAIN CONFIGURATION
#=================================================
ynh_print_info --message="Fixing nginx domain configuration..."
cp -R ../conf/nginx_regen_conf.hook /usr/share/yunohost/hooks/conf_regen/15-nginx_$app
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="/usr/share/yunohost/hooks/conf_regen/15-nginx_$app"
@ -201,6 +207,7 @@ yunohost tools regen-conf nginx
#=================================================
# BUILD YARN DEPENDENCIES
#=================================================
ynh_print_info --message="Building yarn dependencies..."
chown -R "$app":"$app" $final_path
@ -231,6 +238,7 @@ ynh_add_systemd_config
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
ynh_print_info --message="Securing files and directories..."
# Set permissions on app files
chown -R "$app":"$app" "$final_path"
@ -251,7 +259,7 @@ fi
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_print_info --message="Start $app service..."
ynh_print_info --message="Starting a systemd service..."
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Server listening on localhost"