On Fri, 21 Jun 2019 17:37:02 +0800 zhenwei pi <pizhenwei@xxxxxxxxxxxxx> wrote: > On 6/21/19 5:31 PM, FUJITA Tomonori wrote: >> >> >> On Fri, Jun 21, 2019 at 4:24 PM zhenwei pi <pizhenwei@xxxxxxxxxxxxx> >> wrote: >> >> On 6/21/19 1:10 PM, FUJITA Tomonori wrote: >>> >>> >>> On Mon, Jun 3, 2019 at 10:22 AM zhenwei pi <pizhenwei@xxxxxxxxxxxxx> >>> wrote: >>> >>> Running tgtd as init process in a docker, command like this: >>> # docker run -it tgt:v2 /sbin/tgtd -f >>> We must run tgtd in foreground mode, because init process can not be >>> killed. And in this mode, wo can not get tgtd error log from syslog. >>> So support log file for tgtd foreground mode, command like this: >>> # docker run -it tgt:v2 /sbin/tgtd -f --log-file /var/log/tgtd.log >>> >>> Signed-off-by: zhenwei pi <pizhenwei@xxxxxxxxxxxxx> >>> --- >>> usr/log.c | 16 +++++++++++++++- >>> usr/log.h | 3 ++- >>> usr/tgtd.c | 15 ++++++++++++--- >>> 3 files changed, 29 insertions(+), 5 deletions(-) tgtd daemon can't >>> directly use syslog because writing to syslogd could be blocked. So >>> tgtd uses the own logging mechanism. >> zhenwei: If we want to run a single tgtd in docker, tgtd run as init >> process, it must run in foreground mode. Do you have any suggestion to >> get error log? >> >> >> Why do you need to run a single tgtd? > Make a container more clear. In fact, tgtd does not need a systemd ... Why not supervisord instead? If you really want to use tgtd as an initd process, how about the following? == diff --git a/usr/tgtd.c b/usr/tgtd.c index dd6e6f2..7e6853f 100644 --- a/usr/tgtd.c +++ b/usr/tgtd.c @@ -57,12 +57,13 @@ static struct option const long_options[] = { {"nr_iothreads", required_argument, 0, 't'}, {"pid-file", required_argument, 0, 'p'}, {"debug", required_argument, 0, 'd'}, + {"nodaemonize", no_argument, 0, 'D'}, {"version", no_argument, 0, 'V'}, {"help", no_argument, 0, 'h'}, {0, 0, 0, 0}, }; -static char *short_options = "fC:d:t:p:Vh"; +static char *short_options = "fDC:d:t:p:Vh"; static char *spare_args; static void usage(int status) @@ -76,6 +77,7 @@ static void usage(int status) printf("Linux SCSI Target framework daemon, version %s\n\n" "Usage: %s [OPTION]\n" "-f, --foreground make the program run in the foreground\n" + "-D, --nodaemonize make the program run in the foreground with logger\n" "-C, --control-port NNNN use port NNNN for the mgmt channel\n" "-t, --nr_iothreads NNNN specify the number of I/O threads\n" "-p, --pid-file filename specify the pid file\n" @@ -547,7 +549,7 @@ int main(int argc, char **argv) struct sigaction sa_old; struct sigaction sa_new; int err, ch, longindex, nr_lld = 0; - int is_daemon = 1, is_debug = 0; + int is_daemon = 1, is_debug = 0, use_logger = 1; int ret; char *pidfile = NULL; @@ -569,6 +571,10 @@ int main(int argc, char **argv) switch (ch) { case 'f': is_daemon = 0; + use_logger = 0; + break; + case 'D': + is_daemon = 0; break; case 'C': ret = str_to_int_ge(optarg, control_port, 0); @@ -625,7 +631,7 @@ int main(int argc, char **argv) if (err) exit(1); - err = log_init(program_name, LOG_SPACE_SIZE, is_daemon, is_debug); + err = log_init(program_name, LOG_SPACE_SIZE, use_logger, is_debug); if (err) exit(1);