mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
helpers2.1: ynh_systemd_action: rename --service_name to --service to be consistent with other commands
This commit is contained in:
parent
1b2d13f96a
commit
2a6a8af0f7
5 changed files with 24 additions and 24 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_name=fail2ban --action=reload --line_match="(Started|Reloaded) Fail2Ban Service" --log_path=systemd
|
ynh_systemd_action --service=fail2ban --action=reload --line_match="(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
|
||||||
|
@ -122,5 +122,5 @@ ignoreregex =
|
||||||
ynh_remove_fail2ban_config() {
|
ynh_remove_fail2ban_config() {
|
||||||
ynh_safe_rm --target="/etc/fail2ban/jail.d/$app.conf"
|
ynh_safe_rm --target="/etc/fail2ban/jail.d/$app.conf"
|
||||||
ynh_safe_rm --target="/etc/fail2ban/filter.d/$app.conf"
|
ynh_safe_rm --target="/etc/fail2ban/filter.d/$app.conf"
|
||||||
ynh_systemd_action --service_name=fail2ban --action=reload
|
ynh_systemd_action --service=fail2ban --action=reload
|
||||||
}
|
}
|
||||||
|
|
|
@ -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_name=$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 --line_match="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"
|
||||||
|
|
|
@ -30,7 +30,7 @@ ynh_add_nginx_config() {
|
||||||
|
|
||||||
ynh_store_file_checksum --file="$finalnginxconf"
|
ynh_store_file_checksum --file="$finalnginxconf"
|
||||||
|
|
||||||
ynh_systemd_action --service_name=nginx --action=reload
|
ynh_systemd_action --service=nginx --action=reload
|
||||||
}
|
}
|
||||||
|
|
||||||
# Remove the dedicated nginx config
|
# Remove the dedicated nginx config
|
||||||
|
@ -40,7 +40,7 @@ ynh_add_nginx_config() {
|
||||||
# Requires YunoHost version 2.7.2 or higher.
|
# Requires YunoHost version 2.7.2 or higher.
|
||||||
ynh_remove_nginx_config() {
|
ynh_remove_nginx_config() {
|
||||||
ynh_safe_rm --target="/etc/nginx/conf.d/$domain.d/$app.conf"
|
ynh_safe_rm --target="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
ynh_systemd_action --service_name=nginx --action=reload
|
ynh_systemd_action --service=nginx --action=reload
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -130,7 +130,7 @@ pm.process_idle_timeout = 10s
|
||||||
ynh_safe_rm --target="$finalphpconf"
|
ynh_safe_rm --target="$finalphpconf"
|
||||||
ynh_die --message="The new configuration broke php-fpm?"
|
ynh_die --message="The new configuration broke php-fpm?"
|
||||||
fi
|
fi
|
||||||
ynh_systemd_action --service_name=$fpm_service --action=reload
|
ynh_systemd_action --service=$fpm_service --action=reload
|
||||||
}
|
}
|
||||||
|
|
||||||
# Remove the dedicated PHP-FPM config
|
# Remove the dedicated PHP-FPM config
|
||||||
|
@ -143,7 +143,7 @@ ynh_remove_fpm_config() {
|
||||||
local fpm_service=$(ynh_app_setting_get --key=fpm_service)
|
local fpm_service=$(ynh_app_setting_get --key=fpm_service)
|
||||||
|
|
||||||
ynh_safe_rm --target="$fpm_config_dir/pool.d/$app.conf"
|
ynh_safe_rm --target="$fpm_config_dir/pool.d/$app.conf"
|
||||||
ynh_systemd_action --service_name=$fpm_service --action=reload
|
ynh_systemd_action --service=$fpm_service --action=reload
|
||||||
}
|
}
|
||||||
|
|
||||||
# Define the values to configure PHP-FPM
|
# Define the values to configure PHP-FPM
|
||||||
|
|
|
@ -44,7 +44,7 @@ ynh_remove_systemd_config() {
|
||||||
|
|
||||||
local finalsystemdconf="/etc/systemd/system/$service.service"
|
local finalsystemdconf="/etc/systemd/system/$service.service"
|
||||||
if [ -e "$finalsystemdconf" ]; then
|
if [ -e "$finalsystemdconf" ]; then
|
||||||
ynh_systemd_action --service_name=$service --action=stop
|
ynh_systemd_action --service=$service --action=stop
|
||||||
systemctl disable $service --quiet
|
systemctl disable $service --quiet
|
||||||
ynh_safe_rm --target="$finalsystemdconf"
|
ynh_safe_rm --target="$finalsystemdconf"
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
|
@ -53,8 +53,8 @@ ynh_remove_systemd_config() {
|
||||||
|
|
||||||
# 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_name=service_name] [--action=action] [ [--line_match="line to match"] [--log_path=log_path] [--timeout=300] [--length=20] ]
|
# usage: ynh_systemd_action [--service=service] [--action=action] [ [--line_match="line to match"] [--log_path=log_path] [--timeout=300] [--length=20] ]
|
||||||
# | arg: -n, --service_name= - 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: -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: -p, --log_path= - Log file - Path to the log file. Default : `/var/log/$app/$app.log`
|
||||||
|
@ -64,24 +64,24 @@ ynh_remove_systemd_config() {
|
||||||
# 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_name= [a]=action= [l]=line_match= [p]=log_path= [t]=timeout= [e]=length=)
|
local -A args_array=([n]=service= [a]=action= [l]=line_match= [p]=log_path= [t]=timeout= [e]=length=)
|
||||||
local service_name
|
local service
|
||||||
local action
|
local action
|
||||||
local line_match
|
local line_match
|
||||||
local length
|
local length
|
||||||
local log_path
|
local log_path
|
||||||
local timeout
|
local timeout
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
service_name="${service_name:-$app}"
|
service="${service:-$app}"
|
||||||
action=${action:-start}
|
action=${action:-start}
|
||||||
line_match=${line_match:-}
|
line_match=${line_match:-}
|
||||||
length=${length:-20}
|
length=${length:-20}
|
||||||
log_path="${log_path:-/var/log/$service_name/$service_name.log}"
|
log_path="${log_path:-/var/log/$service/$service.log}"
|
||||||
timeout=${timeout:-300}
|
timeout=${timeout:-300}
|
||||||
# ===========================================
|
# ===========================================
|
||||||
|
|
||||||
# Manage case of service already stopped
|
# Manage case of service already stopped
|
||||||
if [ "$action" == "stop" ] && ! systemctl is-active --quiet $service_name; then
|
if [ "$action" == "stop" ] && ! systemctl is-active --quiet $service; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ ynh_systemd_action() {
|
||||||
# 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
|
||||||
# Read the systemd journal
|
# Read the systemd journal
|
||||||
journalctl --unit=$service_name --follow --since=-0 --quiet >"$templog" &
|
journalctl --unit=$service --follow --since=-0 --quiet >"$templog" &
|
||||||
# Get the PID of the journalctl command
|
# Get the PID of the journalctl command
|
||||||
local pid_tail=$!
|
local pid_tail=$!
|
||||||
else
|
else
|
||||||
|
@ -110,9 +110,9 @@ ynh_systemd_action() {
|
||||||
local time_start="$(date --utc --rfc-3339=seconds | cut -d+ -f1) UTC"
|
local time_start="$(date --utc --rfc-3339=seconds | cut -d+ -f1) UTC"
|
||||||
|
|
||||||
# If the service fails to perform the action
|
# If the service fails to perform the action
|
||||||
if ! systemctl $action $service_name; then
|
if ! systemctl $action $service; then
|
||||||
# Show syslog for this service
|
# Show syslog for this service
|
||||||
journalctl --quiet --no-hostname --no-pager --lines=$length --unit=$service_name >&2
|
journalctl --quiet --no-hostname --no-pager --lines=$length --unit=$service >&2
|
||||||
# If a log is specified for this service, show also the content of this log
|
# If a log is specified for this service, show also the content of this log
|
||||||
if [ -e "$log_path" ]; then
|
if [ -e "$log_path" ]; then
|
||||||
tail --lines=$length "$log_path" >&2
|
tail --lines=$length "$log_path" >&2
|
||||||
|
@ -130,13 +130,13 @@ 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_name --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 "$line_match"; then
|
||||||
ynh_print_info --message="The service $service_name 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 "$line_match" "$templog"; then
|
||||||
ynh_print_info --message="The service $service_name has correctly executed the action ${action}."
|
ynh_print_info --message="The service $service has correctly executed the action ${action}."
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -158,9 +158,9 @@ ynh_systemd_action() {
|
||||||
echo "" >&2
|
echo "" >&2
|
||||||
fi
|
fi
|
||||||
if [ $i -eq $timeout ]; then
|
if [ $i -eq $timeout ]; then
|
||||||
ynh_print_warn --message="The service $service_name didn't fully executed the action ${action} before the timeout."
|
ynh_print_warn --message="The service $service didn't fully executed the action ${action} before the timeout."
|
||||||
ynh_print_warn --message="Please find here an extract of the end of the log of the service $service_name:"
|
ynh_print_warn --message="Please find here an extract of the end of the log of the service $service:"
|
||||||
journalctl --quiet --no-hostname --no-pager --lines=$length --unit=$service_name >&2
|
journalctl --quiet --no-hostname --no-pager --lines=$length --unit=$service >&2
|
||||||
if [ -e "$log_path" ]; then
|
if [ -e "$log_path" ]; then
|
||||||
ynh_print_warn --message="\-\-\-"
|
ynh_print_warn --message="\-\-\-"
|
||||||
tail --lines=$length "$log_path" >&2
|
tail --lines=$length "$log_path" >&2
|
||||||
|
|
Loading…
Add table
Reference in a new issue