1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/distbin_ynh.git synced 2024-09-03 18:26:10 +02:00

Applu example_ynh

This commit is contained in:
yalh76 2019-12-29 17:43:56 +01:00
parent 60112062ba
commit cc0c9d0df1
6 changed files with 77 additions and 38 deletions

View file

@ -32,6 +32,13 @@ domain=$(ynh_app_setting_get --app=$app --key=domain)
#=================================================
# STANDARD BACKUP STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_print_info --message="Stopping a systemd service..."
ynh_systemd_action --service_name=$app --action="stop" --log_path=systemd --line_match="Stopped Distbin Service"
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
@ -62,6 +69,13 @@ ynh_print_info --message="Backing up systemd configuration..."
ynh_backup --src_path="/etc/systemd/system/$app.service"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --time --weight=1
ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Started Distbin Service"
#=================================================
# END OF SCRIPT
#=================================================

View file

@ -35,6 +35,23 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd)
port=$(ynh_app_setting_get --app=$app --key=port)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before changing its url (may take a while)..." --time --weight=1
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
# restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# CHECK WHICH PARTS SHOULD BE CHANGED
#=================================================
@ -58,7 +75,7 @@ fi
#=================================================
ynh_print_info --message="Stopping a systemd service..."
ynh_systemd_action --service_name=$app --action=stop --log_path=systemd --line_match="Stopped Distbin Service"
ynh_systemd_action --service_name=$app --action="stop" --log_path=systemd --line_match="Stopped Distbin Service"
#=================================================
# MODIFY URL IN NGINX CONF
@ -96,6 +113,9 @@ fi
#=================================================
ynh_print_info --message="Modifying config file..."
config="$final_path/.env"
ynh_backup_if_checksum_is_different --file="$config"
# Change the URL in the configuration file
if [ "$new_path" == "/" ]
@ -105,16 +125,16 @@ else
new_domain_uri="$new_domain$new_path"
fi
ynh_replace_string --match_string="EXTERNAL_URL=.*" --replace_string="EXTERNAL_URL=https://$new_domain_uri/" --target_file="$final_path/.env"
ynh_replace_string --match_string="EXTERNAL_URL=.*" --replace_string="EXTERNAL_URL=https://$new_domain_uri/" --target_file="$config"
#=================================================
# STORE THE CONFIG FILE CHECKSUM
#=================================================
ynh_print_info --message="Storing the config file checksum..."
ynh_backup_if_checksum_is_different --file="$final_path/.env"
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum --file="$final_path/.env"
ynh_store_file_checksum --file="$config"
#=================================================
# GENERIC FINALISATION
@ -131,7 +151,7 @@ sleep 10
#=================================================
ynh_print_info --message="Reloading nginx web server..."
systemctl reload nginx
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT

View file

@ -56,10 +56,17 @@ 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=8095)
ynh_app_setting_set --app=$app --key=port --value=$port
# Optional: Expose this port publicly
# (N.B. : you only need to do this if the app actually needs to expose the port publicly.
# If you do this and the app doesn't actually need you are CREATING SECURITY HOLES IN THE SERVER !)
# Open the port
# ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port
#=================================================
# INSTALL DEPENDENCIES
#=================================================
@ -143,7 +150,8 @@ ynh_add_systemd_config
#=================================================
ynh_print_info --message="Modifying a config file..."
cp "../conf/.env" "$final_path/.env"
config="$final_path/.env"
cp "../conf/.env" "$config"
if [ "$path_url" == "/" ]
then
@ -152,10 +160,10 @@ else
domain_uri="$domain$path_url"
fi
ynh_replace_string --match_string="__NODEJS_PATH__" --replace_string="$nodejs_path" --target_file="$final_path/.env"
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$final_path/.env"
ynh_replace_string --match_string="__DOMAIN_URI__" --replace_string="$domain_uri" --target_file="$final_path/.env"
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$final_path/.env"
ynh_replace_string --match_string="__NODEJS_PATH__" --replace_string="$nodejs_path" --target_file="$config"
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config"
ynh_replace_string --match_string="__DOMAIN_URI__" --replace_string="$domain_uri" --target_file="$config"
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$config"
#=================================================
# STORE THE CONFIG FILE CHECKSUM
@ -163,7 +171,7 @@ ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path"
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/.env"
ynh_store_file_checksum --file="$config"
#=================================================
# GENERIC FINALIZATION
@ -184,12 +192,10 @@ ynh_print_info --message="Configuring log rotation..."
ynh_use_logrotate
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_print_info --message="Advertising service in admin panel..."
ynh_print_info --message="Integrate service in YunoHost..."
#yunohost service add $app --log "/var/log/$app/$app.log"
# 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 distbin" --log "/var/log/$app/$app.log"
#=================================================
@ -197,7 +203,8 @@ yunohost service add $app --description "$app daemon for distbin" --log "/var/lo
#=================================================
ynh_print_info --message="Starting a systemd service..."
ynh_systemd_action --service_name=$app --action=start --log_path=systemd --line_match="Started Distbin Service"
# Start a systemd service
ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Started Distbin Service"
sleep 10
#=================================================

View file

@ -23,11 +23,11 @@ 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_print_info --message="Removing $app service..."
yunohost service remove $app
@ -87,7 +87,7 @@ fi
#=================================================
# SPECIFIC REMOVE
#=================================================
# REMOVE FILE
# REMOVE THE LOG FILES
#=================================================
# Remove the log files

View file

@ -8,7 +8,6 @@
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source ../settings/scripts/ynh_systemd_action
source /usr/share/yunohost/helpers
#=================================================
@ -99,10 +98,9 @@ ynh_print_info --message="Restoring the systemd configuration..."
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service
systemctl daemon-reload
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_print_info --message="Advertising service in admin panel..."
@ -113,7 +111,7 @@ yunohost service add $app --log "/var/log/$app/$app.log"
#=================================================
ynh_print_info --message="Starting a systemd service..."
ynh_systemd_action --service_name=$app --action=start --log_path=systemd --line_match="Started Distbin Service"
ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Started Distbin Service"
sleep 10
#=================================================

View file

@ -70,17 +70,16 @@ 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 --line_match="Stopped Distbin Service"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_print_info --message="Upgrading source files..."
# Download, check integrity, uncompress and patch the source from app.src#
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..." --time --weight=1
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"
@ -132,9 +131,9 @@ if [ -d "$DIRECTORY" ]; then
fi
#=================================================
# MAKE INSTALL
# MAKE UPGRADE
#=================================================
ynh_print_info --message="Making install..."
ynh_print_info --message="Making upgrade..."
chown -R "$app":"$app" "$final_path"
pushd $final_path
@ -153,8 +152,9 @@ popd
#=================================================
ynh_print_info --message="Modifying config file..."
ynh_backup_if_checksum_is_different --file="$final_path/.env"
cp "../conf/.env" "$final_path/.env"
config="$final_path/.env"
ynh_backup_if_checksum_is_different --file="$config"
cp -f "../conf/.env" "$config"
if [ "$path_url" == "/" ]
then
@ -163,10 +163,10 @@ else
domain_uri="$domain$path_url"
fi
ynh_replace_string --match_string="__NODEJS_PATH__" --replace_string="$nodejs_path" --target_file="$final_path/.env"
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$final_path/.env"
ynh_replace_string --match_string="__DOMAIN_URI__" --replace_string="$domain_uri" --target_file="$final_path/.env"
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$final_path/.env"
ynh_replace_string --match_string="__NODEJS_PATH__" --replace_string="$nodejs_path" --target_file="$config"
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config"
ynh_replace_string --match_string="__DOMAIN_URI__" --replace_string="$domain_uri" --target_file="$config"
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$config"
#=================================================
# STORE THE CONFIG FILE CHECKSUM
@ -174,7 +174,7 @@ ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path"
ynh_print_info --message="Storing the config file checksum..."
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum --file="$final_path/.env"
ynh_store_file_checksum --file="$config"
#=================================================
# SETUP LOGROTATE
@ -219,7 +219,7 @@ fi
#=================================================
ynh_print_info --message="Starting a systemd service..."
ynh_systemd_action --action=start --service_name=$app --log_path=systemd --line_match="Started Distbin Service"
ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Started Distbin Service"
sleep 10
#=================================================