はじめに
なんなの?
「記事のタイトルに悩んでじゃあこれで」と決まったものです。
もちろん映画のアレとは完全に無関係です。
概要
そぷらのさん@気まま気ままでがんばらない @soprano1125
FreeBSD な環境で coredns 動かしてるとsyslog のタグになぜか daemon になってるのが導入当初から気になってたけどその謎がついさっきわかって「お〜ま〜え〜!!!」ってなってるwwwwwこれは某所へ下書きして誕生日ネタにするかアドベントカレンダーネタにするか(チョットマテイ
午後9:44 · 2025年10月2日
そんなわけで2025年の FreeBSD アドベントカレンダー送りになりました!
(そんな誕生日ネタはこちらでどうぞ!)
2025-10-02T21:31:43 127.0.0.1 daemon[6990] maxprocs: Leaving GOMAXPROCS=2: CPU quota undefined
2025-10-02T21:31:43 127.0.0.1 daemon[6990] .:18053 on ::1
2025-10-02T21:31:43 127.0.0.1 daemon[6990] .:18053 on fe80::1%lo0
2025-10-02T21:31:43 127.0.0.1 daemon[6990] .:18053 on 127.0.0.1
2025-10-02T21:31:43 127.0.0.1 daemon[6990] CoreDNS-1.12.3
2025-10-02T21:31:43 127.0.0.1 daemon[6990] freebsd/amd64, go1.23.12,
2025-10-02T21:35:11 127.0.0.1 daemon[6990] [INFO] SIGTERM: Shutting down servers then terminating
FreeBSD な環境で CoreDNS を導入して以降ずっと気になっていたのですが、「最近別件の調査をしていてふと見たら log ディレクトリ内の容量が妙に増えてきたので調べていたら coredns.log というファイルが肥大化していて別件の調査を一旦止めてこっちの調査を始めてみた」というのが今回の経緯です。
あ、その別件の用事はなんやかんやで解決しましたw
調べてみる
「大概こういうのは rc スクリプト周りでなんやかんやある」とばあちゃんが夢枕に立って言われたような気がしたのでそこを調べてみます。
[root@incl-001 ~]# cat /usr/local/etc/rc.d/coredns
#!/bin/sh
# PROVIDE: coredns
# REQUIRE: DAEMON NETWORKING
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf.local, /etc/rc.conf or
# /etc/rc.conf.d/coredns to enable this service:
#
# coredns_enable (bool): Set to NO by default.
# Set it to "YES" to enable coredns.
# coredns_config (str): Set to $PREFIX/etc/coredns/Corefile by default.
# Path to configuration file.
# coredns_cpu_cap (str): Set to "100" by default.
# CPU cap.
# coredns_listen_port (str): Set to "53" by default.
# Port to bind to.
. /etc/rc.subr
name=coredns
rcvar=coredns_enable
start_precmd="${name}_precmd"
load_rc_config $name
: ${coredns_enable:="NO"}
: ${coredns_config:="/usr/local/etc/coredns/Corefile"}
: ${coredns_listen_port:="53"}
pidfile="/var/run/${name}.pid"
logfile="/var/log/${name}.log"
command="/usr/sbin/daemon"
procname="/usr/local/bin/${name}"
coredns_args="-conf ${coredns_config} -dns.port ${coredns_listen_port}"
command_args="-o ${logfile} -m 3 -s "info" -l "daemon" -p ${pidfile} /usr/bin/env ${procname} ${coredns_args}"
coredns_precmd()
{
/usr/bin/install -d -m 0755 /usr/local/etc/coredns && \
cfg_dir=$(dirname "${coredns_config}") && cd "$cfg_dir"
}
run_rc_command "$1"
[root@incl-001 ~]#
そういえばじっくり見たことなかったなぁ rc スクリプトを眺めてみるとどうも coredns コマンドを直接動かさず daemon コマンドに任せて動かしているようです。 なるほど、だから daemon になってたのか!
てっきり「CoreDNS が syslog に吐き出すときタグを daemon にしてるのかねぇ???」とばかり思ってました。
The・どうにかする
理由がわかれば早速どうにかするために daemon コマンドを調べてみます。
[root@incl-001 ~]# man daemon > /tmp/man.txt
[root@incl-001 ~]# cat /tmp/man.txt
DAEMON(8) FreeBSD System Manager's Manual DAEMON(8)
NAME
daemon – run detached from the controlling terminal
SYNOPSIS
daemon [-cfHrS] [-p child_pidfile] [-P supervisor_pidfile] [-t title]
[-u user] [-m output_mask] [-o output_file] [-s syslog_priority]
[-T syslog_tag] [-l syslog_facility] [-R restart_delay_seconds]
command arguments ...
DESCRIPTION
The daemon utility detaches itself from the controlling terminal and
executes the program specified by its arguments. Privileges may be
lowered to the specified user. The output of the daemonized process may
be redirected to syslog and to a log file.
The options are as follows:
-c, --change-dir
Change the current working directory to the root (“/”).
-f, --close-fds
Redirect standard input, standard output and standard error to
/dev/null. When this option is used together with any of the
options related to file or syslog output, the standard file
descriptors are first redirected to /dev/null, then stdout and/or
stderr is redirected to a file or to syslog as specified by the
other options.
-H, --sighup
Close output_file and re-open it when signal SIGHUP is received,
for interoperability with newsyslog(1) and similar log rotation /
archival mechanisms. If --output-file is not specified, this
flag is ignored.
-l, --syslog-facility syslog_facility
These facilities are accepted: auth, authpriv, console, cron,
daemon, ftp, kern, lpr, mail, news, ntp, security, syslog, user,
uucp, and local facilities from local0 to local7. The default is
daemon.
-m, --output-mask output_mask
Redirect output from the child process stdout (1), stderr (2), or
both (3). This value specifies what is sent to syslog and the
log file. The default is 3.
-o, --output-file output_file
Append output from the daemonized process to output_file. If the
file does not exist, it is created with permissions 0600. When
this option is used together with options --change-dir and
--sighup the absolute path needs to be provided to ensure daemon
can re-open the file after a SIGHUP.
-P, --supervisor-pidfile supervisor_pidfile
Write the ID of the daemon process into the supervisor_pidfile
using the pidfile(3) functionality. The program is executed in a
spawned child process while the daemon waits until it terminates
to keep the supervisor_pidfile locked and removes it after the
process exits. The supervisor_pidfile owner is the user who runs
the daemon regardless of whether the --user option is used or
not.
-p, --child-pidfile child_pidfile
Write the ID of the created process into the child_pidfile using
the pidfile(3) functionality. The program is executed in a
spawned child process while the daemon waits until it terminates
to keep the child_pidfile locked and removes it after the process
exits. The child_pidfile owner is the user who runs the daemon
regardless of whether the --user option is used or not.
-R, --restart-delay restart_delay_seconds
Supervise and restart the program after the specified delay if it
has been terminated.
-r, --restart
Supervise and restart the program after a one-second delay if it
has been terminated.
-S, --syslog
Enable syslog output. This is implicitly applied if other syslog
parameters are provided. The default values are daemon, notice,
and daemon for facility, priority, and tag, respectively.
-s, --syslog-priority syslog_priority
These priorities are accepted: emerg, alert, crit, err, warning,
notice, info, and debug. The default is notice.
-T, --syslog-tag syslog_tag
Set the tag which is appended to all syslog messages. The
default is daemon.
-t, --title title
Set the title for the daemon process. The default is the
daemonized invocation.
-u, --user user
Login name of the user to execute the program under. Environment
variables HOME, USER, and SHELL are set accordingly. Requires
adequate superuser privileges.
If any of the options --child-pidfile, --output-mask, --restart,
--restart-delay, --supervisor-pidfile, --syslog, --syslog-facility
--syslog-priority, --syslog-tag, or --output, are specified, the program
is executed in a spawned child process. The daemon waits until it
terminates to keep the pid file(s) locked and removes them after the
process exits or restarts the program. In this case if the monitoring
daemon receives software termination signal (SIGTERM) it forwards it to
the spawned process. Normally it will cause the child to exit, remove
the pidfile(s) and then terminate.
If neither file or syslog output are selected, all output is redirected
to the daemon process and written to stdout. The --close-fds option may
be used to suppress the stdout output completely.
The --supervisor-pidfile option is useful combined with the --restart
option as supervisor_pidfile contains the ID of the supervisor not the
child. This is especially important if you use --restart in an rc script
as the --child-pidfile option will give you the child's ID to signal when
you attempt to stop the service, causing daemon to restart the child.
EXIT STATUS
The daemon utility exits 1 if an error is returned by the daemon(3)
library routine, 2 if child_pidfile or supervisor_pidfile is requested,
but cannot be opened, 3 if process is already running (pidfile exists and
is locked), 4 if syslog_priority is not accepted, 5 if syslog_facility is
not accepted, 6 if output_mask is not within the accepted range, 7 if
output_file cannot be opened for appending, and otherwise 0.
DIAGNOSTICS
If the command cannot be executed, an error message is printed to
standard error. The exact behavior depends on the logging parameters and
the --close-fds flag.
SEE ALSO
nohup(1), setregid(2), setreuid(2), daemon(3), exec(3), pidfile(3),
termios(4), tty(4)
HISTORY
The daemon utility first appeared in FreeBSD 4.7.
FreeBSD 14.3-RELEASE September 18, 2023 FreeBSD 14.3-RELEASE
man で見るとそれっぽい項目があったので rc スクリプトをそれっぽく書き直してサービスを再起動します。
[root@incl-001 rc.d]# diff coredns.orig coredns
37c37
< command_args="-o ${logfile} -m 3 -s "info" -l "daemon" -p ${pidfile} /usr/bin/env ${procname} ${coredns_args}"
---
> command_args="-m 3 -s "info" -l "daemon" -T ${name} -p ${pidfile} /usr/bin/env ${procname} ${coredns_args}"
[root@incl-001 rc.d]# service coredns restart
手を加えた箇所としては「タグを ${name} にしておいてログは syslog でしか履かせないようにした」程度しかしてません。
2025-10-02T21:35:12 127.0.0.1 coredns[7047] maxprocs: Leaving GOMAXPROCS=2: CPU quota undefined
2025-10-02T21:35:12 127.0.0.1 coredns[7047] .:18053 on ::1
2025-10-02T21:35:12 127.0.0.1 coredns[7047] .:18053 on fe80::1%lo0
2025-10-02T21:35:12 127.0.0.1 coredns[7047] .:18053 on 127.0.0.1
2025-10-02T21:35:12 127.0.0.1 coredns[7047] CoreDNS-1.12.3
2025-10-02T21:35:12 127.0.0.1 coredns[7047] freebsd/amd64, go1.23.12,
ヨシッ!!(
あとがき
「daemon」コマンドで回している rc スクリプトだったらちまちま手でいじればなんとかなりそうです。 「bugzilla に書け」と言われそうな予かn(ry
ちなみにここで使った「incl-001」は FreeBSD を使ってますが後日 Debian に置き換える予定です。
そぷらのさん@気まま気ままでがんばらない @soprano1125
実は最近「FreeBSD に入れた広告避けたい Unbound」で python-script を動かそうとすると module init でエラーになってくれるおかげで色々ごちゃごちゃやってみたら Debian に移せそうとわかって 6VM やるのかってなってる(^_^;)
午前11:36 · 2025年8月21日
実はこのついでに VM ホストで使っている「Proxmox 8系」から「Proxmox 9系」に上げたら FreeBSD ゲストのメモリ使用率が上限スレスレまであがってしまい困り果てたので Debian に置き換えたいんですが誕生日ネタにも書いたとおりノート PC のモニターのバックライトが(ry
そぷらのさん@気まま気ままでがんばらない @soprano1125
そういえばモニターのバックライトがアレの件で「いつかの VM 再構築作戦」をやらなきゃなのに VNC + iPad でやるのはちょっと画面サイズが小さすぎるのでどうしたm(ry
午前10:06 · 2025年11月25日