Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply example_ynh #104

Merged
merged 1 commit into from May 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 3 additions & 6 deletions check_process
@@ -1,7 +1,7 @@
;; Nom du test
;; Test complet
; Manifest
domain="domain.tld" (DOMAIN)
path="/path" (PATH)
domain="domain.tld"
path="/path"
; Checks
pkg_linter=1
setup_sub_dir=1
Expand All @@ -17,6 +17,3 @@
Email=
Notification=none
;;; Upgrade options
; commit=
name=
manifest_arg=domain=DOMAIN&path=PATH
1 change: 1 addition & 0 deletions conf/app.src
Expand Up @@ -4,3 +4,4 @@ SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=
SOURCE_EXTRACT=true
7 changes: 5 additions & 2 deletions conf/nginx.conf
Expand Up @@ -11,15 +11,18 @@ location __PATH__/ {

index index.php;

# Common parameter to increase upload size limit in conjunction with dedicated php-fpm file
#client_max_body_size 50M;

try_files $uri $uri/ index.php;
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass unix:/var/run/php/php__PHPVERSION__-fpm-__NAME__.sock;

fastcgi_index index.php;
include fastcgi_params;
fastcgi_param REMOTE_USER $remote_user;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param REMOTE_USER $remote_user;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $request_filename;
}

Expand Down
4 changes: 3 additions & 1 deletion conf/systemd.service
Expand Up @@ -3,9 +3,11 @@ Description=News feed reader and aggregator
After=network.target mysql.service

[Service]
Type=simple
User=__APP__
Group=__APP__
ExecStart=/usr/bin/php __FINALPATH__/update_daemon2.php
WorkingDirectory=__FINALPATH__/
ExecStart=/usr/bin/php__PHPVERSION__ __FINALPATH__/update_daemon2.php
Restart=always
RestartSec=10

Expand Down
15 changes: 0 additions & 15 deletions scripts/_common.sh
Expand Up @@ -49,18 +49,3 @@ ynh_smart_mktemp () {

echo "$(mktemp --directory --tmpdir="$tmpdir")"
}

#=================================================

# Execute a command as another user
# usage: ynh_exec_as USER COMMAND [ARG ...]
ynh_exec_as() {
local USER=$1
shift 1

if [[ $USER = $(whoami) ]]; then
eval "$@"
else
sudo -u "$USER" "$@"
fi
}
5 changes: 4 additions & 1 deletion scripts/backup
@@ -1,9 +1,12 @@
#!/bin/bash

#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================

# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers

Expand All @@ -23,8 +26,8 @@ app=$YNH_APP_INSTANCE_NAME

final_path=$(ynh_app_setting_get --app=$app --key=final_path)
domain=$(ynh_app_setting_get --app=$app --key=domain)
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)

#=================================================
# DECLARE DATA AND CONF FILES TO BACKUP
Expand Down
63 changes: 33 additions & 30 deletions scripts/install
Expand Up @@ -31,7 +31,7 @@ app=$YNH_APP_INSTANCE_NAME
ynh_script_progression --message="Validating installation parameters..." --weight=1

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"

# Register (book) web path
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
Expand All @@ -46,14 +46,23 @@ ynh_app_setting_set --app=$app --key=path --value=$path_url

#=================================================
# STANDARD MODIFICATIONS
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..." --weight=2

# Create a system user
ynh_system_user_create --username=$app --home_dir=$final_path

#=================================================
# CREATE A MYSQL DATABASE
#=================================================
ynh_script_progression --message="Creating a MySQL database..." --weight=2

db_name=$(ynh_sanitize_dbid $app)
db_name=$(ynh_sanitize_dbid --db_name=$app)
db_user=$db_name
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_mysql_setup_db --db_user=$db_name --db_name=$db_name
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)

#=================================================
Expand All @@ -65,6 +74,10 @@ ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"

chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"

#=================================================
# NGINX CONFIGURATION
#=================================================
Expand All @@ -73,14 +86,6 @@ ynh_script_progression --message="Configuring NGINX web server..." --weight=2
# Create a dedicated NGINX config
ynh_add_nginx_config

#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..." --weight=2

# Create a system user
ynh_system_user_create --username=$app

#=================================================
# PHP-FPM CONFIGURATION
#=================================================
Expand All @@ -93,28 +98,25 @@ phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
#=================================================
# SPECIFIC SETUP
#=================================================
# CONFIGURE TTRSS
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring ttrss..." --weight=1
ynh_script_progression --message="Adding a configuration file..." --weight=1

domain_path=https://$domain$path_url

ynh_add_config --template="../conf/config.php" --destination="$final_path/config.php"

chmod 400 "$final_path/config.php"
chown $app:$app "$final_path/config.php"

#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..." --weight=2

# Create a dedicated systemd config
ynh_add_systemd_config

#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================

# Set permissions to app files
chown -R root:$app $final_path
chown -R $app $final_path/{cache,feed-icons,lock}

#=================================================
# INITIALIZE DATABASE
#=================================================
Expand All @@ -125,26 +127,27 @@ ynh_mysql_connect_as --user="$db_name" --password="$db_pwd" --database="$db_name

ynh_exec_as $app php${phpversion} ${final_path}/update.php --update-schema

#=================================================
# START TTRSS IN BACKGROUND
#=================================================
ynh_script_progression --message="Starting ttrss..." --weight=1

ynh_systemd_action --service_name=$app --action=start

#=================================================
# GENERIC FINALIZATION
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1

yunohost service add $app --description="News feed reader and aggregator" --log="/var/log/$app/$app.log"

#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1

# Start a systemd service
ynh_systemd_action --service_name=$app --action="start"

#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Configuring SSOwat..." --weight=1
ynh_script_progression --message="Configuring permissions..." --weight=1

ynh_app_setting_set --app=$app --key=skipped_uris --value="/public.php,/api,/opml.php?op=publish"

Expand Down
11 changes: 6 additions & 5 deletions scripts/remove
Expand Up @@ -18,18 +18,19 @@ app=$YNH_APP_INSTANCE_NAME

domain=$(ynh_app_setting_get --app=$app --key=domain)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
final_path=$(ynh_app_setting_get --app=$app --key=final_path)

#=================================================
# STANDARD REMOVE
#=================================================
# REMOVE SERVICE FROM ADMIN PANEL
# REMOVE SERVICE INTEGRATION IN YUNOHOST
#=================================================

# Remove a service from the admin panel, added by `yunohost service add`
if 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_script_progression --message="Removing $app service..." --weight=2
ynh_script_progression --message="Removing $app service integration..."
yunohost service remove $app
fi

Expand All @@ -47,7 +48,7 @@ ynh_remove_systemd_config
ynh_script_progression --message="Removing the MySQL database..." --weight=4

# Remove a database if it exists, along with the associated user
ynh_mysql_remove_db --db_user=$db_name --db_name=$db_name
ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name

#=================================================
# REMOVE APP MAIN DIR
Expand Down
49 changes: 27 additions & 22 deletions scripts/restore
Expand Up @@ -6,6 +6,7 @@
# IMPORT GENERIC HELPERS
#=================================================

# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers

Expand All @@ -27,6 +28,7 @@ domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)

#=================================================
Expand All @@ -44,36 +46,33 @@ test ! -d $final_path \
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the NGINX configuration..."

ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"

#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..." --weight=2

ynh_restore_file --origin_path="$final_path"

#=================================================
# RECREATE THE DEDICATED USER
#=================================================
ynh_script_progression --message="Recreating the dedicated system user..." --weight=3

# Create the dedicated user (if not existing)
ynh_system_user_create --username=$app
ynh_system_user_create --username=$app --home_dir=$final_path

#=================================================
# RESTORE USER RIGHTS
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..." --weight=2

# Set permissions to app files
chown -R root:$app $final_path
chown -R $app $final_path/{cache,feed-icons,lock}
ynh_restore_file --origin_path="$final_path"

chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"

#=================================================
# RESTORE THE PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Reconfiguring PHP-FPM..." --weight=50
ynh_script_progression --message="Restoring the PHP-FPM configuration..." --weight=50

ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"

Expand All @@ -85,24 +84,30 @@ ynh_add_fpm_config --package="$extra_php_dependencies"
ynh_script_progression --message="Restoring the MySQL database..." --weight=5

db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
ynh_mysql_setup_db --db_user=$db_name --db_name=$db_name --db_pwd=$db_pwd
ynh_mysql_connect_as --user=$db_name --password=$db_pwd --database=$db_name < ./db.sql
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql

#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
# RESTORE SYSTEMD
#=================================================
ynh_script_progression --message="Restoring the systemd configuration..." --weight=2

ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service --quiet

#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1

yunohost service add $app --description="News feed reader and aggregator" --log="/var/log/$app/$app.log"

#=================================================
# RESTORE SYSTEMD
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Restoring the systemd configuration..." --weight=2
ynh_script_progression --message="Starting a systemd service..."

ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service --quiet
ynh_systemd_action --service_name=$app --action=start
ynh_systemd_action --service_name=$app --action="start"

#=================================================
# GENERIC FINALIZATION
Expand All @@ -111,7 +116,7 @@ ynh_systemd_action --service_name=$app --action=start
#=================================================
ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." --weight=2

ynh_systemd_action --service_name=php${phpversion}-fpm --action=reload
ynh_systemd_action --service_name=php$phpversion-fpm --action=reload
ynh_systemd_action --service_name=nginx --action=reload

#=================================================
Expand Down