On Mon, Mar 07, 2016 at 06:37:49PM +0400, Sergey Vojtovich wrote:
> Existence of pid-file is a sure sign that there's mysqld running, the only
> exception is mysqld crash. What do you think about skipping this check?
> 
> I'd also suggest to turn things around and check for pid-file first and then
> just run "MYADMIN flush-logs" allowing it to return error in case of failure.

Yep. Switched the order for this one. But mysqladmin does not return 1
when it fails to connect. Did some additional testing. For now I put it
back to the way it was in the original logrotate and just check if
stdout/stderr of the command is null.
This probably merits a second bug report.
diff --git a/mariadb-server-10.0.mysql-server.logrotate.orig b/mariadb-server-10.0.mysql-server.logrotate
index 52f1292..30d8bec 100644
--- a/mariadb-server-10.0.mysql-server.logrotate.orig
+++ b/mariadb-server-10.0.mysql-server.logrotate
@@ -14,14 +14,11 @@
 
 		# If this fails, check debian.conf!
 		MYADMIN="/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf"
-		if [ -z "`$MYADMIN ping 2>/dev/null`" ]; then
-		  # Really no mysqld or in incorrect authentication in /etc/mysql/debian.cnf user?
-		  # If this occurs and is not a error please report a bug.
-		  if ps cax | grep -q mysqld; then
- 		    exit 1
-		  fi
-		else
-		  $MYADMIN flush-logs
+		PID=$(my_print_defaults mysqld | grep -oP "pid-file=\K[^$]+")
+		if [ -r $PID ]; then
+		  # If the pid-file exists and the process is mysqld it should be able to flush the logs
+		  [ "$(ps -p $(cat $PID) -o comm=)" = "mysqld" -a -n "$($MYADMIN flush-logs 2>&1)" ] && exit 1 
 		fi
+		exit 0
 	endscript
 }

Attachment: signature.asc
Description: Digital signature

Reply via email to