Bug #55404 MEM: agent's initscript returns 1 even if agent already stopped
Submitted: 20 Jul 2010 15:07 Modified: 28 Jan 2011 22:44
Reporter: Leandro Morgado Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Enterprise Monitor: Installing Severity:S3 (Non-critical)
Version:Agent 2.2.1.1729 (probably all versions) OS:Linux
Assigned to: Mark Leith CPU Architecture:Any

[20 Jul 2010 15:07] Leandro Morgado
Description:
The LSB states:

Per http://refspecs.freestandards.org/LSB_4.0.0/LSB-Core-generic/LSB-Core-generic
/iniscrptact.html, stopping an already-stopped process is considered success and should return 0. 

However, "/etc/init.d/mysql-monitor-agent stop" returns 1 in this case.

[root@host ~]# /etc/init.d/mysql-monitor-agent stop
Shutting down MySQL Enterprise agent service......         [  OK  ]
[root@host ~]# echo $?
0
[root@host ~]# /etc/init.d/mysql-monitor-agent stop ; echo $?
MySQL Enterprise agent PID file could not be found!        [FAILED]
1

The mysqld server scripts are correct and here is an example:

[root@www ~]# /etc/init.d/mysql stop ; echo $?
Shutting down MySQL....                                    [  OK  ]
0
[root@www ~]# /etc/init.d/mysql stop ; echo $?
MySQL manager or server PID file could not be found!       [FAILED]
0

How to repeat:
Stop the agent then try to stop it again:

shell> /etc/init.d/mysql-monitor-agent stop ; echo $?
shell> /etc/init.d/mysql-monitor-agent stop ; echo $?

Suggested fix:
Return 0 if trying to stop and already stopped agent.
[21 Jul 2010 14:01] Leandro Morgado
Here is a patch that corrects the incorrect exit code when issuing stop on a non running agent. 

diff -u mysql-monitor-agent mysql-monitor-agent.bug55404 
--- mysql-monitor-agent	2010-07-21 15:59:32.000000000 +0200
+++ mysql-monitor-agent.bug55404	2010-07-21 16:00:07.000000000 +0200
@@ -259,7 +259,11 @@
       fi
     else
       log_failure_msg "$MERLIN_AGENT_PSERVICE PID file could not be found!"
-      exit 1
+      if [ "$1" = "stop" ]; then
+        exit 0
+      else
+        exit 1
+      fi
     fi
     ;;
   force
[2 Dec 2010 12:28] Enterprise Tools JIRA Robot
Mark Leith writes: 
Pushed to 2.3:

1987 Mark Leith	2010-12-02
     Bug#55404 / EM-4682 - MEM: agent's initscript returns 1 even if agent already stopped
     - Applying patch from Leandro Morgado

   modified:
     scripts/init.d/mysql-monitor-agent

And 2.2:

1952 Mark Leith	2010-12-02
     Bug#55404 / EM-4682 - MEM: agent's initscript returns 1 even if agent already stopped
     - Applying patch from Leandro Morgado

   modified:
     scripts/init.d/mysql-monitor-agent
[11 Jan 2011 16:51] Enterprise Tools JIRA Robot
Andy Bang writes: 
Fix is in build 2.3.2.2050.
[18 Jan 2011 14:22] Enterprise Tools JIRA Robot
Carsten Segieth writes: 
tested OK in 2.2.4.1761 and 2.3.2.2051
[28 Jan 2011 22:44] John Russell
Added to 2.3.2 and 2.2.4 change log:

The command /etc/init.d/mysql-monitor-agent stop incorrectly returned
the value 1 if the &merlin_agent; was already stopped. Now this
command returns a value of 0 in this case.