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

Adding ynh_systemd_action helper

This commit is contained in:
yalh76 2019-02-01 21:13:30 +01:00
parent b12e47c52a
commit 6d3347948a
11 changed files with 220 additions and 24 deletions

View file

@ -13,7 +13,7 @@ Can be run as Single User Blog or Multi User Instance.
Each User can be limited from 1 to unlimited blogs.
**Shipped version:** v0.8.0
**Shipped version:** v0.8.1
## Licence

View file

@ -1,5 +1,5 @@
SOURCE_URL=https://github.com/writeas/writefreely/releases/download/v0.8.0/writefreely_0.8.0_linux_amd64.tar.gz
SOURCE_SUM=ed1020692bdb96e3d3fc52605d089f26153edfb5dc2822b4da03fcc351c1e841
SOURCE_URL=https://github.com/writeas/writefreely/releases/download/v0.8.1/writefreely_0.8.1_linux_amd64.tar.gz
SOURCE_SUM=97fe8d2098f86eaa4a294e1d5845dafe7079e5502070ba3929f78abfbf9be371
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=false

View file

@ -6,7 +6,7 @@
"en": "Write Freely is free and open source software for starting a minimalist, federated blog — or an entire community.",
"fr": "Write Freely est un logiciel gratuit et à code source ouvert permettant de créer un blog fédéré minimaliste ou une communauté entière."
},
"version": "0.8.0~ynh2",
"version": "0.8.1~ynh1",
"url": "https://writefreely.org",
"license": "free",
"maintainer": {

View file

@ -7,15 +7,25 @@
#=================================================
source ../settings/scripts/_common.sh
source ../settings/scripts/detect_arch
source /usr/share/yunohost/helpers
#=================================================
# MANAGE APPLICATION NOT COMPATIBLE WITH ARM
#=================================================
if [ $architecture = "arm" ]
then
ynh_die "WriteFreely not available on Arm"
fi
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script.
true
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors

View file

@ -6,9 +6,19 @@
# IMPORT GENERIC HELPERS
#=================================================
source detect_arch
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE APPLICATION NOT COMPATIBLE WITH ARM
#=================================================
if [ $architecture = "arm" ]
then
ynh_die "WriteFreely not available on Arm"
fi
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
@ -90,18 +100,27 @@ fi
#=================================================
# SPECIFIC MODIFICATIONS
#=================================================
# ...
# STOP SERVICE
#=================================================
# Stop writefreely for modification
yunohost service stop "$app"
ynh_systemd_action --action=stop --service_name=$app
#=================================================
# MODIFY A CONFIG FILE
#=================================================
ynh_replace_string "host =.*" "host =https://$new_domain$new_path" "$final_path/config.ini"
# Start writefreely after modification
yunohost service start $app
#=================================================
# START SERVICE
#=================================================
### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
ynh_systemd_action --action=start --service_name=$app
#=================================================
# STORE THE CONFIG FILE CHECKSUM
#=================================================
fy the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it.
ynh_backup_if_checksum_is_different "$final_path/config.ini"
# Recalculate and store the checksum of the file for the next upgrade.

12
scripts/detect_arch Normal file
View file

@ -0,0 +1,12 @@
#!/bin/bash
if [ -n "$(uname -m | grep 64)" ]; then
architecture="x86-64"
elif [ -n "$(uname -m | grep 86)" ]; then
architecture="i386"
elif [ -n "$(uname -m | grep arm)" ]; then
architecture="arm"
else
ynh_die "Unable to detect your achitecture, please open a bug describing \
your hardware and the result of the command \"uname -m\"." 1
fi

View file

@ -7,25 +7,30 @@
#=================================================
source _common.sh
source detect_arch
source ynh_systemd_action
source /usr/share/yunohost/helpers
#=================================================
# MANAGE APPLICATION NOT COMPATIBLE WITH ARM
#=================================================
if [ $architecture = "arm" ]
then
ynh_die "WriteFreely not available on Arm"
fi
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script.
true
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
arch=$(uname -m)
if [[ $arch == arm* ]]
then
ynh_die "WriteFreely not available on Arm"
fi
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
@ -362,4 +367,10 @@ systemctl reload nginx
# START SERVICE
#=================================================
yunohost service start $app
ynh_systemd_action --action=start --service_name=$app
#=================================================
# CLEAN TEMPORARY PROCESS AND FILE USED BY ynh_check_starting
#=================================================
ynh_clean_check_starting

View file

@ -6,9 +6,20 @@
# IMPORT GENERIC HELPERS
#=================================================
source detect_arch
source _common.sh
source ynh_systemd_action
source /usr/share/yunohost/helpers
#=================================================
# MANAGE APPLICATION NOT COMPATIBLE WITH ARM
#=================================================
if [ $architecture = "arm" ]
then
ynh_die "WriteFreely not available on Arm"
fi
#=================================================
# LOAD SETTINGS
#=================================================
@ -116,3 +127,9 @@ ynh_secure_remove "/var/log/$app/"
# Delete a system user
ynh_system_user_delete $app
#=================================================
# CLEAN TEMPORARY PROCESS AND FILE USED BY ynh_check_starting
#=================================================
ynh_clean_check_starting

View file

@ -7,15 +7,26 @@
#=================================================
source ../settings/scripts/_common.sh
source ../settings/scripts/detect_arch
source ../settings/scripts/ynh_systemd_action
source /usr/share/yunohost/helpers
#=================================================
# MANAGE APPLICATION NOT COMPATIBLE WITH ARM
#=================================================
if [ $architecture = "arm" ]
then
ynh_die "WriteFreely not available on Arm"
fi
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
#### Remove this function if there's nothing to clean before calling the remove script.
true
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
@ -129,4 +140,10 @@ systemctl reload nginx
# START SERVICE
#=================================================
yunohost service start $app
ynh_systemd_action --action=start --service_name=$app
#=================================================
# CLEAN TEMPORARY PROCESS AND FILE USED BY ynh_check_starting
#=================================================
ynh_clean_check_starting

View file

@ -7,8 +7,19 @@
#=================================================
source _common.sh
source detect_arch
source ynh_systemd_action
source /usr/share/yunohost/helpers
#=================================================
# MANAGE APPLICATION NOT COMPATIBLE WITH ARM
#=================================================
if [ $architecture = "arm" ]
then
ynh_die "WriteFreely not available on Arm"
fi
#=================================================
# LOAD SETTINGS
#=================================================
@ -58,12 +69,16 @@ ynh_backup_before_upgrade
ynh_clean_setup () {
# restore it if the upgrade fails
ynh_restore_upgradebackup
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
# Stop writefreely for upgrade
yunohost service stop "$app"
#=================================================
# STOP SERVICE
#=================================================
ynh_systemd_action --action=stop --service_name=$app
#=================================================
# CHECK THE PATH
@ -178,4 +193,10 @@ systemctl reload nginx
# START SERVICE
#=================================================
yunohost service start $app
ynh_systemd_action --action=start --service_name=$app
#=================================================
# CLEAN TEMPORARY PROCESS AND FILE USED BY ynh_check_starting
#=================================================
ynh_clean_check_starting

View file

@ -0,0 +1,89 @@
#!/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
}