[packages/nginx] init: add configtest
Elan Ruusamäe
glen at pld-linux.org
Sun May 3 22:11:46 CEST 2015
the pretty common checkconfig() function body could be added to rc-scripts,
if we could standardize variable name used for the msg_ parameters:
show "Checking %s configuration" "$svname"
here it was $svname, but probably good one is $SERVICE_NAME?
On 03.05.2015 23:04, glen wrote:
> commit ab8302f087c7063d446b9dc074ff12c461c450ff
> Author: Elan Ruusamäe <glen at delfi.ee>
> Date: Sun May 3 23:02:12 2015 +0300
>
> init: add configtest
>
> nginx.init | 45 ++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 44 insertions(+), 1 deletion(-)
> ---
> diff --git a/nginx.init b/nginx.init
> index 2ef3143..38c75cd 100755
> --- a/nginx.init
> +++ b/nginx.init
> @@ -38,9 +38,46 @@ else
> exit 0
> fi
>
> +# configtest itself
> +# must return non-zero if check failed
> +# output is discarded if checkconfig is ran without details
> +configtest() {
> + $nginx -t -c $NGINX_CONF_FILE
> +}
> +
> +# wrapper for configtest
> +checkconfig() {
> + local details=${1:-0}
> +
> + if [ $details = 1 ]; then
> + # run config test and display report (status action)
> + show "Checking %s configuration" "$svname"; busy
> + local out
> + out=$(configtest 2>&1)
> + RETVAL=$?
> + if [ $RETVAL = 0 ]; then
> + ok
> + else
> + fail
> + fi
> + [ "$out" ] && echo >&2 "$out"
> + else
> + # run config test and abort with nice message if failed
> + # (for actions checking status before action).
> + configtest >/dev/null 2>&1
> + RETVAL=$?
> + if [ $RETVAL != 0 ]; then
> + show "Checking %s configuration" "$svname"; fail
> + nls 'Configuration test failed. See details with %s "checkconfig"' $0
> + exit $RETVAL
> + fi
> + fi
> +}
> +
--
glen
More information about the pld-devel-en
mailing list