mirror of
https://github.com/YunoHost-Apps/gogs_ynh.git
synced 2024-09-03 20:36:23 +02:00
Use ynh_check_starting to wait until the service is started
This commit is contained in:
parent
c7f76147ff
commit
f62931350d
1 changed files with 50 additions and 0 deletions
|
@ -8,3 +8,53 @@ ynh_delete_file_checksum () {
|
||||||
local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_'
|
local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_'
|
||||||
ynh_app_setting_delete $app $checksum_setting_name
|
ynh_app_setting_delete $app $checksum_setting_name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Start or restart a service and follow its booting
|
||||||
|
#
|
||||||
|
# usage: ynh_check_starting "Line to match" [Log file] [Timeout] [Service name]
|
||||||
|
#
|
||||||
|
# | arg: Line to match - The line to find in the log to attest the service have finished to boot.
|
||||||
|
# | arg: Log file - The log file to watch
|
||||||
|
# | arg: Service name
|
||||||
|
# /var/log/$app/$app.log will be used if no other log is defined.
|
||||||
|
# | arg: Timeout - The maximum time to wait before ending the watching. Defaut 300 seconds.
|
||||||
|
ynh_check_starting () {
|
||||||
|
local line_to_match="$1"
|
||||||
|
local service_name="${4:-$app}"
|
||||||
|
local app_log="${2:-/var/log/$service_name/$service_name.log}"
|
||||||
|
local timeout=${3:-300}
|
||||||
|
|
||||||
|
ynh_clean_check_starting () {
|
||||||
|
# Stop the execution of tail.
|
||||||
|
kill -s 15 $pid_tail 2>&1
|
||||||
|
ynh_secure_remove "$templog" 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "Starting of $service_name" >&2
|
||||||
|
systemctl restart $service_name
|
||||||
|
local templog="$(mktemp)"
|
||||||
|
# Following the starting of the app in its log
|
||||||
|
tail -F -n1 "$app_log" > "$templog" &
|
||||||
|
# Get the PID of the tail command
|
||||||
|
local pid_tail=$!
|
||||||
|
|
||||||
|
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_to_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
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
ynh_clean_check_starting
|
||||||
|
}
|
Loading…
Reference in a new issue