diff --git a/.circleci/config.yml b/.circleci/config.yml index fad233f18..145a9bab5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -84,6 +84,10 @@ jobs: - run: name: Kill servers command: sudo pkill etserver + - run: + name: Debug info/logs if failed + when: on_fail + command: ls -la /tmp/et*; sudo awk 'FNR==1 {print "XXXXXX", FILENAME, "XXXXXX"}{print}' /tmp/et* workflows: version: 2 diff --git a/etc/et.cfg b/etc/et.cfg index 812adafdb..44a901ba2 100644 --- a/etc/et.cfg +++ b/etc/et.cfg @@ -9,4 +9,5 @@ port = 2022 verbose = 0 silent = 0 logsize = 20971520 +logdirectory = /tmp telemetry = 1 diff --git a/src/terminal/TerminalClientMain.cpp b/src/terminal/TerminalClientMain.cpp index bbd716f57..0823a923f 100644 --- a/src/terminal/TerminalClientMain.cpp +++ b/src/terminal/TerminalClientMain.cpp @@ -88,11 +88,13 @@ int main(int argc, char** argv) { ("v,verbose", "Enable verbose logging", cxxopts::value()->default_value("0")) // ("k,keepalive", "Client keepalive duration in seconds", - cxxopts::value()) // - ("logtostdout", "Write log to stdout") // - ("silent", "Disable logging") // - ("N,no-terminal", "Do not create a terminal") // - ("f,forward-ssh-agent", "Forward ssh-agent socket") // + cxxopts::value()) // + ("l,logdir", "Base directory for log files.", + cxxopts::value()->default_value(tmpDir)) // + ("logtostdout", "Write log to stdout") // + ("silent", "Disable logging") // + ("N,no-terminal", "Do not create a terminal") // + ("f,forward-ssh-agent", "Forward ssh-agent socket") // ("ssh-socket", "The ssh-agent socket to forward", cxxopts::value()) // ("telemetry", @@ -124,8 +126,8 @@ int main(int argc, char** argv) { defaultConf.setGlobally(el::ConfigurationType::Enabled, "false"); } - LogHandler::setupLogFiles(&defaultConf, tmpDir, "etclient", - result.count("logtostdout"), + LogHandler::setupLogFiles(&defaultConf, result["logdir"].as(), + "etclient", result.count("logtostdout"), !result.count("logtostdout")); el::Loggers::reconfigureLogger("default", defaultConf); diff --git a/src/terminal/TerminalMain.cpp b/src/terminal/TerminalMain.cpp index 553fbe000..df02ea014 100644 --- a/src/terminal/TerminalMain.cpp +++ b/src/terminal/TerminalMain.cpp @@ -48,7 +48,9 @@ int main(int argc, char** argv) { // Not used by etterminal but easylogging uses this flag under the hood ("v,verbose", "Enable verbose logging", cxxopts::value()->default_value("0")) // - ("logtostdout", "Write log to stdout") // + ("l,logdir", "Base directory for log files.", + cxxopts::value()->default_value(GetTempDirectory())) // + ("logtostdout", "Write log to stdout") // ("serverfifo", "If set, connects to the etserver instance listening on the matching " "fifo name", // @@ -138,7 +140,7 @@ int main(int argc, char** argv) { string username = string(ssh_get_local_username()); if (result.count("jump")) { // etserver with --jump cannot write to the default log file(root) - LogHandler::setupLogFiles(&defaultConf, GetTempDirectory(), + LogHandler::setupLogFiles(&defaultConf, result["logdir"].as(), ("etjump-" + username + "-" + id), result.count("logtostdout"), false); // Reconfigure default logger to apply settings above @@ -167,7 +169,7 @@ int main(int argc, char** argv) { } // etserver with --idpasskey cannot write to the default log file(root) - LogHandler::setupLogFiles(&defaultConf, GetTempDirectory(), + LogHandler::setupLogFiles(&defaultConf, result["logdir"].as(), ("etterminal-" + username + "-" + id), result.count("logtostdout"), false); diff --git a/src/terminal/TerminalServerMain.cpp b/src/terminal/TerminalServerMain.cpp index a7fb326cc..2aac3a8d5 100644 --- a/src/terminal/TerminalServerMain.cpp +++ b/src/terminal/TerminalServerMain.cpp @@ -37,7 +37,9 @@ int main(int argc, char **argv) { ("daemon", "Daemonize the server") // ("cfgfile", "Location of the config file", cxxopts::value()->default_value("")) // - ("logtostdout", "log to stdout") // + ("l,logdir", "Base directory for log files.", + cxxopts::value()) // + ("logtostdout", "log to stdout") // ("pidfile", "Location of the pid file", cxxopts::value()->default_value( "/var/run/etserver.pid")) // @@ -77,6 +79,7 @@ int main(int argc, char **argv) { int port = 0; string bindIp = ""; + string logDirectory = GetTempDirectory(); bool telemetry = true; if (result.count("cfgfile")) { // Load the config file @@ -120,6 +123,7 @@ int main(int argc, char **argv) { if (silent && atoi(silent) != 0) { defaultConf.setGlobally(el::ConfigurationType::Enabled, "false"); } + // read log file size limit const char *logsize = ini.GetValue("Debug", "logsize", NULL); if (logsize && atoi(logsize) != 0) { @@ -127,6 +131,11 @@ int main(int argc, char **argv) { maxlogsize = string(logsize); } + // log file directory (TODO path validation and trailing slash cleanup) + const char *logdir = ini.GetValue("Debug", "logdirectory", NULL); + if (logdir) { + logDirectory = string(logdir); + } } else { STFATAL << "Invalid config file: " << cfgfilename; } @@ -149,6 +158,10 @@ int main(int argc, char **argv) { telemetry = result["telemetry"].as(); } + if (result.count("logdir")) { + logDirectory = result["logdir"].as(); + } + GOOGLE_PROTOBUF_VERIFY_VERSION; srand(1); @@ -157,7 +170,7 @@ int main(int argc, char **argv) { } // Set log file for etserver process here. - LogHandler::setupLogFiles(&defaultConf, GetTempDirectory(), "etserver", + LogHandler::setupLogFiles(&defaultConf, logDirectory, "etserver", result.count("logtostdout"), !result.count("logtostdout"), maxlogsize); // Reconfigure default logger to apply settings above