Return code incorrect when garbd is already running

Bug #1308103 reported by jmrenouard
12
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Galera
Fix Released
Undecided
Yan Zhang
Percona XtraDB Cluster moved to https://jira.percona.com/projects/PXC
Status tracked in 5.6
5.5
Fix Released
Low
Unassigned
5.6
Fix Released
Low
Unassigned

Bug Description

Context:
SysV init.d script: /etc/init.d/garb
Garbd is already running and started correctly.

Observed result:
service garb start
echo $?
0

Awaited result:
When garbd is already started, return code shouldn't return 0.
0 means success
If garbd is already running so trying to start garbd is expected to fail and return an non-zero return code.

Solution: return 3 instead of 0

--- garbd_origin 2014-04-15 16:48:20.115360380 +0200
+++ garb 2014-04-15 16:49:24.866360234 +0200
@@ -97,7 +97,7 @@

        if [ -r $PIDFILE ]; then
                log_failure "$prog is already running with PID $(cat ${PIDFILE})"
- return 0
+ return 3
        fi

        [ -x $prog ] || return 5

Revision history for this message
jmrenouard (jmrenouard) wrote :

I have found a similar bug around stop function in this file: garb

function stop return 0 if garbd is not started. stop function did not successed stopping an non running program so non zero return code is better.

Best regards,

Yan Zhang (yan.zhang)
Changed in galera:
status: New → Confirmed
assignee: nobody → Yan Zhang (yan.zhang)
Yan Zhang (yan.zhang)
Changed in galera:
milestone: none → 25.3.6
status: Confirmed → Fix Committed
Revision history for this message
Przemek (pmalkowski) wrote :

First of all, it does NOT seem that this is a correct practice in Linux to exit with '3' when using start on running service. See these examples:

[root@percona3 ~]# cat /etc/issue
CentOS release 6.5 (Final)

[root@percona3 ~]# service postfix status
master (pid 1278) is running...
[root@percona3 ~]# service postfix start
[root@percona3 ~]# echo $?
0
[root@percona3 ~]# service postfix status
master (pid 1278) is running...

[root@percona3 ~]# service crond status
crond (pid 1330) is running...
[root@percona3 ~]# service crond start
[root@percona3 ~]# echo $?
0

root@vagrant-debian-wheezy:~# cat /etc/issue
Debian GNU/Linux 7 \n \l

root@vagrant-debian-wheezy:~# service cron status
cron is running.
root@vagrant-debian-wheezy:~# service cron start
Starting periodic command scheduler: cron.
root@vagrant-debian-wheezy:~# echo $?
0

Also according to these documents, exit code 0 is a proper one in case on a start attempt when the service is already started:
http://refspecs.linuxbase.org/LSB_3.1.1/LSB-Core-generic/LSB-Core-generic/iniscrptact.html
http://fedoraproject.org/wiki/Packaging:SysVInitScript#Exit_Codes_for_non-Status_Actions

Exit code 3 is proper only for a "service xxx status" command when service is not running.

Revision history for this message
Przemek (pmalkowski) wrote :

Now it seems that the garb init script does wrong thing in both 3.x and 2.x versions:

[root@percona3 ~]# rpm -qa|grep -i garb
Percona-XtraDB-Cluster-garbd-2-2.11-1.2675.rhel6.x86_64
[root@percona3 ~]# ps -ef|grep garb
root 8868 8413 0 14:56 pts/0 00:00:00 grep garb
[root@percona3 ~]# service garb status
garbd is stopped
[root@percona3 ~]# echo $?
3
[root@percona3 ~]# service garb start
Starting /usr/bin/garbd: [FAILED]
[root@percona3 ~]# echo $?
0
[root@percona3 ~]# service garb status
garbd (pid 8905) is running...
[root@percona3 ~]# service garb start
/usr/bin/garbd is already running with PID [FAILED]
[root@percona3 ~]# echo $?
3

---------
[root@percona3 ~]# rpm -qa|grep -i garb
Percona-XtraDB-Cluster-garbd-3-3.7-1.3254.rhel6.x86_64
[root@percona3 ~]# service garb status
garbd is stopped
[root@percona3 ~]# echo $?
3
[root@percona3 ~]# service garb start
Starting /usr/bin/garbd: [ OK ]

[root@percona3 ~]# service garb status
garbd (pid 8641) is running...
[root@percona3 ~]# echo $?
0
[root@percona3 ~]# service garb start
/usr/bin/garbd is already running with PID 8641 [FAILED]
[root@percona3 ~]# echo $?
3

See also: lp:1367956

Changed in galera:
status: Fix Committed → Fix Released
Revision history for this message
Shahriyar Rzayev (rzayev-sehriyar) wrote :

Percona now uses JIRA for bug reports so this bug report is migrated to: https://jira.percona.com/browse/PXC-1145

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.