From 44b55fad898716a5f2918a61ac4f7edc36ddb087 Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Tue, 25 Oct 2016 21:52:43 +0200 Subject: [PATCH] TT#5030 Provide all sync-db output also to syslog /var/log/ngcp/ngcpcfg.log might not contain error messages from ngcpcfg's sync-db script. This might be confusing when comparing output from the command line with the logged actions from ngcpcfg.log. As sync-db doesn't log all error messages to stderr anyway and we ignore exit code of the sync-db script as well (on purpose) let's just redirect stderr and stdout to the same file descriptor and then provide output to the console as well as syslog's ngcpcfg tag. Output before this change: | root@sp1:~# ngcpcfg commit "before" | 2016-10-25 22:12:20: Executing sync-db: | DBI connect('database=provisioning;host=localhost;port=3306','sipwise',...) failed: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) at /usr/share/ngcp-ngcpcfg/helper//sync-db line 70. | Error: Could not connect to database 'provisioning' at 'localhost:3306' as 'sipwise': Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) | 2016-10-25 22:12:20: OK: nothing to commit. | 2016-10-25 22:12:20: Synchronizing MySQL grants/credentials | Can't connect to MySQL database 'mysql': Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) at /usr/sbin/ngcp-sync-grants line 66. | root@sp1:~# tail -f /var/log/ngcp/ngcpcfg.log | [...] | Oct 25 22:12:20 sp1 (notice) ngcpcfg: Executing sync-db: | Oct 25 22:12:20 sp1 (notice) ngcpcfg: OK: nothing to commit. | Oct 25 22:12:20 sp1 (notice) ngcpcfg: Checking state of /etc files | Oct 25 22:12:20 sp1 (notice) ngcpcfg: OK: nothing to commit. | Oct 25 22:12:20 sp1 (notice) ngcpcfg: Synchronizing MySQL grants/credentials Output after this change gets applied: | root@sp1:~# ngcpcfg commit "after" | 2016-10-25 22:12:59: Executing sync-db: | DBI connect('database=provisioning;host=localhost;port=3306','sipwise',...) failed: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) at /usr/share/ngcp-ngcpcfg/helper//sync-db line 70. | Error: Could not connect to database 'provisioning' at 'localhost:3306' as 'sipwise': Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) | 2016-10-25 22:12:59: OK: nothing to commit. | 2016-10-25 22:12:59: Synchronizing MySQL grants/credentials | Can't connect to MySQL database 'mysql': Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) at /usr/sbin/ngcp-sync-grants line 66. | root@sp1:~# tail -f /var/log/ngcp/ngcpcfg.log | [...] | Oct 25 22:12:59 sp1 (notice) ngcpcfg: Executing sync-db: | Oct 25 22:12:59 sp1 (notice) ngcpcfg: DBI connect('database=provisioning;host=localhost;port=3306','sipwise',...) failed: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) at /usr/share/ngcp-ngcpcfg/helper//sync-db line 70. | Oct 25 22:12:59 sp1 (notice) ngcpcfg: Error: Could not connect to database 'provisioning' at 'localhost:3306' as 'sipwise': Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) | Oct 25 22:12:59 sp1 (notice) ngcpcfg: OK: nothing to commit. | Oct 25 22:12:59 sp1 (notice) ngcpcfg: Checking state of /etc files | Oct 25 22:12:59 sp1 (notice) ngcpcfg: OK: nothing to commit. | Oct 25 22:12:59 sp1 (notice) ngcpcfg: Synchronizing MySQL grants/credentials Change-Id: Iabb0c0ab24e212b79b0dfa85947cb274a161cc00 --- scripts/commit | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/commit b/scripts/commit index 411cfb1c..21f632c4 100755 --- a/scripts/commit +++ b/scripts/commit @@ -33,10 +33,10 @@ cd "$NGCPCTL_MAIN" if [ -z "${NO_DB_SYNC:-}" ] ; then if [ -f "${RTP_INTERFACES_CONFIG}" ] ; then log_info "Executing sync-db: " - "${HELPER}/sync-db" "$NGCPCTL_CONFIG" "$CONSTANTS_CONFIG" "$RTP_INTERFACES_CONFIG" | sed "s/^/$timestamp_replacementchars/" || true + "${HELPER}/sync-db" "$NGCPCTL_CONFIG" "$CONSTANTS_CONFIG" "$RTP_INTERFACES_CONFIG" 2>&1 | sed "s/^/$timestamp_replacementchars/" 2>&1 | tee >(logger -t ngcpcfg) || true else log_info "Executing sync-db: " - "${HELPER}/sync-db" "$NGCPCTL_CONFIG" "$CONSTANTS_CONFIG" | sed "s/^/$timestamp_replacementchars/" || true + "${HELPER}/sync-db" "$NGCPCTL_CONFIG" "$CONSTANTS_CONFIG" 2>&1 | sed "s/^/$timestamp_replacementchars/" 2>&1 | tee >(logger -t ngcpcfg) || true fi else log_debug "no-db-sync: skipping 'sync-db'"