Skip to content

Instantly share code, notes, and snippets.

@aoirint
Created February 8, 2023 14:35
Show Gist options
  • Save aoirint/137cff3217d5823b50f9ac056d6301e2 to your computer and use it in GitHub Desktop.
Save aoirint/137cff3217d5823b50f9ac056d6301e2 to your computer and use it in GitHub Desktop.
既存のentrypointを置き換えてubuntu/bind9のログを永続化するシェルスクリプト
#!/bin/bash
set -e
{
/usr/local/bin/docker-entrypoint.sh $@
} \
1> >(tee -a >(sed -u "s/^/[$(date -Ins)] /" >> /bind_logs/named_stdout.log) >&1) \
2> >(tee -a >(sed -u "s/^/[$(date -Ins)] /" >> /bind_logs/named_stderr.log) >&2)
@aoirint
Copy link
Author

aoirint commented Feb 8, 2023

services:
  bind9:
    image: ubuntu/bind9:9.18-22.04_beta
    entrypoint: "/docker-entrypoint.sh"
    volumes:
      - "./docker-entrypoint.sh:/docker-entrypoint.sh:ro"

こんな感じで

@aoirint
Copy link
Author

aoirint commented Feb 8, 2023

named_stderr.log

[2023-02-08T23:29:25,100600003+09:00] 08-Feb-2023 23:29:25.107 starting BIND 9.18.1-1ubuntu1.3-Ubuntu (Stable Release) <id:>
[2023-02-08T23:29:25,100600003+09:00] 08-Feb-2023 23:29:25.107 running on Linux x86_64 5.4.0-137-generic #154-Ubuntu SMP Thu Jan 5 17:03:22 UTC 2023
[2023-02-08T23:29:25,100600003+09:00] 08-Feb-2023 23:29:25.107 built with  '--build=x86_64-linux-gnu' '--prefix=/usr' '--includedir=${prefix}/include' '--mandir=${prefix}/share/man' '--infodir=${prefix}/share/info' '--sysconfdir=/etc' '--localstatedir=/var' '--disable-option-checking' '--disable-silent-rules' '--libdir=${prefix}/lib/x86_64-linux-gnu' '--runstatedir=/run' '--disable-maintainer-mode' '--disable-dependency-tracking' '--libdir=/usr/lib/x86_64-linux-gnu' '--sysconfdir=/etc/bind' '--with-python=python3' '--localstatedir=/' '--enable-threads' '--enable-largefile' '--with-libtool' '--enable-shared' '--disable-static' '--with-gost=no' '--with-openssl=/usr' '--with-gssapi=yes' '--with-libidn2' '--with-json-c' '--with-lmdb=/usr' '--with-gnu-ld' '--with-maxminddb' '--with-atf=no' '--enable-ipv6' '--enable-rrl' '--enable-filter-aaaa' '--disable-native-pkcs11' 'build_alias=x86_64-linux-gnu' 'CFLAGS=-g -O2 -ffile-prefix-map=/build/bind9-dnYB1i/bind9-9.18.1=. -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -fno-strict-aliasing -fno-delete-null-pointer-checks -DNO_VERSION_DATE -DDIG_SIGCHASE' 'LDFLAGS=-Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -Wl,-z,now' 'CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2'
[2023-02-08T23:29:25,100600003+09:00] 08-Feb-2023 23:29:25.107 running as: named -u bind -g
[2023-02-08T23:29:25,100600003+09:00] 08-Feb-2023 23:29:25.107 compiled by GCC 11.3.0
[2023-02-08T23:29:25,100600003+09:00] 08-Feb-2023 23:29:25.107 compiled with OpenSSL version: OpenSSL 3.0.2 15 Mar 2022
[2023-02-08T23:29:25,100600003+09:00] 08-Feb-2023 23:29:25.107 linked to OpenSSL version: OpenSSL 3.0.2 15 Mar 2022
[2023-02-08T23:29:25,100600003+09:00] 08-Feb-2023 23:29:25.107 compiled with libxml2 version: 2.9.13
[2023-02-08T23:29:25,100600003+09:00] 08-Feb-2023 23:29:25.107 linked to libxml2 version: 20913
[2023-02-08T23:29:25,100600003+09:00] 08-Feb-2023 23:29:25.107 compiled with json-c version: 0.15
[2023-02-08T23:29:25,100600003+09:00] 08-Feb-2023 23:29:25.107 linked to json-c version: 0.15
[2023-02-08T23:29:25,100600003+09:00] 08-Feb-2023 23:29:25.107 compiled with zlib version: 1.2.11
[2023-02-08T23:29:25,100600003+09:00] 08-Feb-2023 23:29:25.107 linked to zlib version: 1.2.11
[2023-02-08T23:29:25,100600003+09:00] 08-Feb-2023 23:29:25.107 ----------------------------------------------------
[2023-02-08T23:29:25,100600003+09:00] 08-Feb-2023 23:29:25.107 BIND 9 is maintained by Internet Systems Consortium,
[2023-02-08T23:29:25,100600003+09:00] 08-Feb-2023 23:29:25.107 Inc. (ISC), a non-profit 501(c)(3) public-benefit 
[2023-02-08T23:29:25,100600003+09:00] 08-Feb-2023 23:29:25.107 corporation.  Support and training for BIND 9 are 
[2023-02-08T23:29:25,100600003+09:00] 08-Feb-2023 23:29:25.107 available at https://www.isc.org/support
[2023-02-08T23:29:25,100600003+09:00] 08-Feb-2023 23:29:25.107 ----------------------------------------------------

named_stdout.log

[2023-02-08T23:33:30,104053049+09:00] Starting named...
[2023-02-08T23:33:30,104053049+09:00] exec /usr/sbin/named -u "bind" -g ""

@aoirint
Copy link
Author

aoirint commented Feb 8, 2023

Q. 秒以下と秒の区切りが,になっているのを.にできませんか?

GNU dateが区切りを,にすることが原因ですが、変更するオプションはありません。個人的には,にはなじみがないけれど、ISO 8601的には,の方が推奨らしい(ISO文書のAbstractにある例も.になってるけど、ほんとか??)。

ISO原典読むの5万くらいする(166 + 187 CHF = 353 CHF ~ 50000 JPY)らしいのでWikipediaで許して...(RFC 3339を読めばいいのかもしれないけど)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment