mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
helpers2.1: ynh_systemd_action '--line_match' -> '--wait_until'
This commit is contained in:
parent
218bf107fb
commit
11e2b6d63c
3 changed files with 12 additions and 12 deletions
|
@ -105,7 +105,7 @@ ignoreregex =
|
||||||
chown -R "$app:$app" "/var/log/$app"
|
chown -R "$app:$app" "/var/log/$app"
|
||||||
chmod -R u=rwX,g=rX,o= "/var/log/$app"
|
chmod -R u=rwX,g=rX,o= "/var/log/$app"
|
||||||
|
|
||||||
ynh_systemd_action --service=fail2ban --action=reload --line_match="(Started|Reloaded) Fail2Ban Service" --log_path=systemd
|
ynh_systemd_action --service=fail2ban --action=reload --wait_until="(Started|Reloaded) Fail2Ban Service" --log_path=systemd
|
||||||
|
|
||||||
local fail2ban_error="$(journalctl --no-hostname --unit=fail2ban | tail --lines=50 | grep "WARNING.*$app.*")"
|
local fail2ban_error="$(journalctl --no-hostname --unit=fail2ban | tail --lines=50 | grep "WARNING.*$app.*")"
|
||||||
if [[ -n "$fail2ban_error" ]]; then
|
if [[ -n "$fail2ban_error" ]]; then
|
||||||
|
|
|
@ -241,7 +241,7 @@ ynh_install_mongo() {
|
||||||
# Make sure MongoDB is started and enabled
|
# Make sure MongoDB is started and enabled
|
||||||
systemctl enable $mongodb_servicename --quiet
|
systemctl enable $mongodb_servicename --quiet
|
||||||
systemctl daemon-reload --quiet
|
systemctl daemon-reload --quiet
|
||||||
ynh_systemd_action --service=$mongodb_servicename --action=restart --line_match="aiting for connections" --log_path="/var/log/mongodb/$mongodb_servicename.log"
|
ynh_systemd_action --service=$mongodb_servicename --action=restart --wait_until="aiting for connections" --log_path="/var/log/mongodb/$mongodb_servicename.log"
|
||||||
|
|
||||||
# Integrate MongoDB service in YunoHost
|
# Integrate MongoDB service in YunoHost
|
||||||
yunohost service add $mongodb_servicename --description="MongoDB daemon" --log="/var/log/mongodb/$mongodb_servicename.log"
|
yunohost service add $mongodb_servicename --description="MongoDB daemon" --log="/var/log/mongodb/$mongodb_servicename.log"
|
||||||
|
|
|
@ -53,10 +53,10 @@ ynh_config_remove_systemd() {
|
||||||
|
|
||||||
# Start (or other actions) a service, print a log in case of failure and optionnaly wait until the service is completely started
|
# 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 [--service=service] [--action=action] [ [--line_match="line to match"] [--log_path=log_path] [--timeout=300] [--length=20] ]
|
# usage: ynh_systemd_action [--service=service] [--action=action] [ [--wait_until="line to match"] [--log_path=log_path] [--timeout=300] [--length=20] ]
|
||||||
# | arg: -n, --service= - Name of the service to start. Default : `$app`
|
# | arg: -n, --service= - Name of the service to start. Default : `$app`
|
||||||
# | arg: -a, --action= - Action to perform with systemctl. Default: start
|
# | 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: -w, --wait_until= - The pattern to find in the log to attest the service is effectively fully started.
|
||||||
# | arg: -p, --log_path= - Log file - Path to the log file. Default : `/var/log/$app/$app.log`
|
# | 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: -t, --timeout= - Timeout - The maximum time to wait before ending the watching. Default : 300 seconds.
|
||||||
# | arg: -e, --length= - Length of the error log displayed for debugging : Default : 20
|
# | arg: -e, --length= - Length of the error log displayed for debugging : Default : 20
|
||||||
|
@ -64,17 +64,17 @@ ynh_config_remove_systemd() {
|
||||||
# Requires YunoHost version 3.5.0 or higher.
|
# Requires YunoHost version 3.5.0 or higher.
|
||||||
ynh_systemd_action() {
|
ynh_systemd_action() {
|
||||||
# ============ Argument parsing =============
|
# ============ Argument parsing =============
|
||||||
local -A args_array=([n]=service= [a]=action= [l]=line_match= [p]=log_path= [t]=timeout= [e]=length=)
|
local -A args_array=([n]=service= [a]=action= [w]=wait_until= [p]=log_path= [t]=timeout= [e]=length=)
|
||||||
local service
|
local service
|
||||||
local action
|
local action
|
||||||
local line_match
|
local wait_until
|
||||||
local length
|
local length
|
||||||
local log_path
|
local log_path
|
||||||
local timeout
|
local timeout
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
service="${service:-$app}"
|
service="${service:-$app}"
|
||||||
action=${action:-start}
|
action=${action:-start}
|
||||||
line_match=${line_match:-}
|
wait_until=${wait_until:-}
|
||||||
length=${length:-20}
|
length=${length:-20}
|
||||||
log_path="${log_path:-/var/log/$service/$service.log}"
|
log_path="${log_path:-/var/log/$service/$service.log}"
|
||||||
timeout=${timeout:-300}
|
timeout=${timeout:-300}
|
||||||
|
@ -86,7 +86,7 @@ ynh_systemd_action() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Start to read the log
|
# Start to read the log
|
||||||
if [[ -n "$line_match" ]]; then
|
if [[ -n "$wait_until" ]]; then
|
||||||
local templog="$(mktemp)"
|
local templog="$(mktemp)"
|
||||||
# Following the starting of the app in its log
|
# Following the starting of the app in its log
|
||||||
if [ "$log_path" == "systemd" ]; then
|
if [ "$log_path" == "systemd" ]; then
|
||||||
|
@ -121,8 +121,8 @@ ynh_systemd_action() {
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Start the timeout and try to find line_match
|
# Start the timeout and try to find wait_until
|
||||||
if [[ -n "${line_match:-}" ]]; then
|
if [[ -n "${wait_until:-}" ]]; then
|
||||||
set +x
|
set +x
|
||||||
local i=0
|
local i=0
|
||||||
local starttime=$(date +%s)
|
local starttime=$(date +%s)
|
||||||
|
@ -130,12 +130,12 @@ ynh_systemd_action() {
|
||||||
# Read the log until the sentence is found, that means the app finished to start. Or run until the timeout
|
# Read the log until the sentence is found, that means the app finished to start. Or run until the timeout
|
||||||
if [ "$log_path" == "systemd" ]; then
|
if [ "$log_path" == "systemd" ]; then
|
||||||
# For systemd services, we in fact dont rely on the templog, which for some reason is not reliable, but instead re-read journalctl every iteration, starting at the timestamp where we triggered the action
|
# For systemd services, we in fact dont rely on the templog, which for some reason is not reliable, but instead re-read journalctl every iteration, starting at the timestamp where we triggered the action
|
||||||
if journalctl --unit=$service --since="$time_start" --quiet --no-pager --no-hostname | grep --extended-regexp --quiet "$line_match"; then
|
if journalctl --unit=$service --since="$time_start" --quiet --no-pager --no-hostname | grep --extended-regexp --quiet "$wait_until"; then
|
||||||
ynh_print_info --message="The service $service has correctly executed the action ${action}."
|
ynh_print_info --message="The service $service has correctly executed the action ${action}."
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if grep --extended-regexp --quiet "$line_match" "$templog"; then
|
if grep --extended-regexp --quiet "$wait_until" "$templog"; then
|
||||||
ynh_print_info --message="The service $service has correctly executed the action ${action}."
|
ynh_print_info --message="The service $service has correctly executed the action ${action}."
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Add table
Reference in a new issue