bind9: logging to file doesn't work cause bind starts with -g option

Bug #1991719 reported by Benjamin Féron
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Ubuntu Docker Images
Fix Released
Low
Athos Ribeiro

Bug Description

Hi,

I use ubuntu/bind9:9.18-22.04_edge docker image and I can't set it for file logging.

Here is my logging conf :

+------------------------------------+
| # cat /etc/bind/named.conf.local
| [...]
| logging {
|  channel query {
|   file "/var/log/named/query.log";
|   severity info;
|   print-time yes;
|  };
|  category queries { query; };
| };
| [...]
+------------------------------------+

File /var/log/named/query.log is still empty...

Bind starts with -g option and I think it causes the issue :

+-----------------------------------------------+
| # ps ax|grep named
|       1 ? Ssl 0:00 /usr/sbin/named -u bind -g
+-----------------------------------------------+

I don't understand from where the -g option is set :

+----------------------------------+
| # cat /etc/default/named
| #
| # run resolvconf?
| RESOLVCONF=no
|
| # startup options for the server
| OPTIONS="-u bind"
+----------------------------------+

Can someone help me ?

Thanks

Benjamin Féron (befe)
description: updated
description: updated
description: updated
Benjamin Féron (befe)
description: updated
description: updated
Benjamin Féron (befe)
description: updated
Revision history for this message
Athos Ribeiro (athos-ribeiro) wrote :

Hello,

please check the entrypoint code at
https://git.launchpad.net/~ubuntu-docker-images/ubuntu-docker-images/+git/bind9/tree/docker-entrypoint.sh?h=9.18-22.04
(or at /usr/local/bin/entry-point.sh in your image) this is where the -g option comes from.

From that file, you will also notice that you should be able to either pass additional params to bind through CMD, or to even override the whole startup command by starting CMD with "named".

The reason it starts with the -g option is to make it simpler to run it in environments such as kubernetes.

Revision history for this message
Benjamin Féron (befe) wrote (last edit ):

Thank you for your response.

But unfortunatly I didn't succeed to override the startup command :

+---------------------------------------+
| $ cat docker-compose.yml
| [...]
| services:
| bind:
| image: ubuntu/bind9:9.18-22.04_edge
| command: named -u bind
| [...]
+----------------------------------------+
(in reality, indent is correct)

Bind still starts with -g option :

+-----------------------------------------------+
| # ps ax|grep named
| 1 ? Ssl 0:00 /usr/sbin/named -u bind -g
+-----------------------------------------------+

I missed something ?

Revision history for this message
Athos Ribeiro (athos-ribeiro) wrote :

Hello,

On a second read on that entrypoint file, I realized that

> From that file, you will also notice that you should be able to either pass additional params to bind through CMD, or to even override the whole startup command by starting CMD with "named"

Is not a correct statement. The correct one would be:

From that file, you will also notice that you should be able to either pass additional params to bind through CMD, by starting CMD with "named", or to completely override it, as long as it is not executing named.

In other words, you want to override your entrypoint.

Revision history for this message
Benjamin Féron (befe) wrote (last edit ):

Well, thank you very much.

Do you think this limitation could be bypassed in a future release ?
For instance, with an environment variable like DAEMONIZE or something else ?

Revision history for this message
Athos Ribeiro (athos-ribeiro) wrote :

The default behavior seems to be what users would usually want to deploy this image and be able to parse the logs in a distributed fashion. Do you have any suggestions?

Also, does is the entrypoint through the docker compose entrypoint attribute an issue or would not using it make things any better (how?)?

Revision history for this message
Benjamin Féron (befe) wrote :

I understand that the default behaviour should not be modified.

Indeed it would be easy to override the complete entrypoint but I think it's not really a good practice because if the original one is improved on future releases, these improvements will never be beneficial unless you verify the contents of the original file each time the container image is updated. I do not know if I'm clear.

Revision history for this message
Benjamin Féron (befe) wrote (last edit ):

A suggestion :

if [ "${DAEMONIZE}" != "yes" ]; then
        EXTRA_ARGS="-g ${EXTRA_ARGS}"
fi

exec $(command -v named) -u "${BIND9_USER}" ${EXTRA_ARGS}

Revision history for this message
Athos Ribeiro (athos-ribeiro) wrote :

That is clear enough and the suggestion is also nice. We may change the env var name since it may be confusing given the named manpage says that -f and -g "Run the server in the foreground (i.e. do not daemonize)".

Changed in ubuntu-docker-images:
status: New → Triaged
importance: Undecided → Low
assignee: nobody → Athos Ribeiro (athos-ribeiro)
Revision history for this message
Benjamin Féron (befe) wrote (last edit ):

Thank you very much for your interest

Revision history for this message
Benjamin Féron (befe) wrote (last edit ):

Maybe the env var should be NOFOREGROUND or NO_FOREGROUND but perhaps it also may be confusing...

Revision history for this message
Benjamin Féron (befe) wrote :

...or LOG_TO_FILE

Revision history for this message
Benjamin Féron (befe) wrote (last edit ):

I noticed that for this to work the "-f" option must be used instead of "-g". Without this, named doesn't start correctly. With "-f" option, file logging works well.

Revision history for this message
Benjamin Féron (befe) wrote :

if [ "${LOG_TO_FILE}" == "yes" ]; then
        EXTRA_ARGS="-f ${EXTRA_ARGS}"
else
        EXTRA_ARGS="-g ${EXTRA_ARGS}"
fi

Revision history for this message
Athos Ribeiro (athos-ribeiro) wrote :

Fix committed. This will be released in the next 22.10 image as soon as kinetic is out.

The new variable name is USE_CONFIG_FILE_LOGGING. If this is set (e.g., USE_CONFIG_FILE_LOGGING=1), the foreground param used to start named will be "-f", allowing the logging related data in named.conf to be used.

Thanks for the report!

Changed in ubuntu-docker-images:
status: Triaged → Fix Committed
Revision history for this message
Benjamin Féron (befe) wrote :

Perfect !

Thanks

Revision history for this message
Benjamin Féron (befe) wrote :

It works fine !
Thank you !

Revision history for this message
Benjamin Féron (befe) wrote (last edit ):

But documentation is not updated with new env var USE_CONFIG_FILE_LOGGING on page

https://hub.docker.com/r/ubuntu/bind9

Revision history for this message
Athos Ribeiro (athos-ribeiro) wrote :

Hi Benjamin,

Thanks for giving it a try and validating the change!

The docs update was submitted here: https://code.launchpad.net/~athos-ribeiro/ubuntu-docker-images/+git/templates/+merge/431241

I am waiting on reviews so we can push them.

Thanks for pointing this out, I will give it another ping so we can get the docs change landed soon.

Changed in ubuntu-docker-images:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.