zegl / mysql-master-ha

Automatically exported from code.google.com/p/mysql-master-ha
0 stars 0 forks source link

masterha_manager needs to be good daemon #42

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
i write script for starting/stopping masterha_manager as service in 
system(ubuntu)

you advice use nohup or daemontools.
http://code.google.com/p/mysql-master-ha/wiki/Runnning_Background
i decide using nohup

my script looks very simple still

#############
#############
#############
#!/bin/bash

RETVAL=0

do_start() {
        echo "Starting"
        nohup masterha_manager --conf=/etc/mha_manager/app1.cnf < /dev/null > /home/mha4mysql/app1.log 2>&1 &
        RETVAL=$?
        echo
        return $RETVAL
}

do_stop() {
        echo "Stopping"
        masterha_stop --conf=/etc/mha_manager/app1.cnf
        RETVAL=$?
        echo
        return $RETVAL
}

do_stop_force() {
        echo "Stopping"
        masterha_stop --abort --conf=/etc/mha_manager/app1.cnf
        RETVAL=$?
        echo
        return $RETVAL
}

case $* in

start)
        do_start
        ;;

stop)
        do_stop
        ;;

stop_force)
        do_stop_force
        ;;

*)
        echo "usage: $0 {start|stop|restart}" >&2

        exit 1
        ;;
esac

exit $RETVAL
#############
#############
#############

when i start masterha_manager, i cannot know it starts good or not. 
Usually when any daemon starts, it does all checks, then forks and return 0 as 
state that all is good. Or other numer when there is an error. 
It gives important information about successfull of start
If i start masterha_manager i cannot get any status code, because it doesnt 
fork and work in one thread. If i start it with nohup i receive 0. Its nohup 
status. Nohup says that it start good and nothing more. It can stop with error 
little while, becouse masterha_manager will make checks and find any error.

I would want to get return code from masterha_manager, but cannot now with 
nohup.

i think masterha_manager should be able to start as normal daemon with fork. It 
should make checks all and fork only when all is good. And when it forks it'd 
return 0. In other cases, when any checks were failed, it shouldnt fork and 
must return error code.

or how can i write service script?

ps: same thing with masterha_stop: it returns 0 always. Even it cannot find 
mha_manager process - it writes about it but anyway return 0;
for example

root@:/home/mha4mysql# ./mha4mysql.servise stop
Stopping
MHA Manager is not running on app1(2:NOT_RUNNING).

root@:/home/mha4mysql# echo $?
0

Original issue reported on code.google.com by obric...@balakam.com on 4 Dec 2012 at 2:04

GoogleCodeExporter commented 9 years ago
For checking MHA status codes, there is a utility script masterha_check_status. 
I think this will help.

$ masterha_check_status --conf=mha_test.cnf
mha_test is stopped(2:NOT_RUNNING).
$ echo ?
2

Original comment by Yoshinor...@gmail.com on 5 Dec 2012 at 12:59

GoogleCodeExporter commented 9 years ago
You can run it with a guardian process like supervisor or cluster like 
pacemaker to start it automatically.

Original comment by m.je...@gmail.com on 5 Feb 2013 at 8:05

GoogleCodeExporter commented 9 years ago
Very good project .. thanks a lot 

Created a init scrip for ubuntu and works well ...

###### Put this under /etc/init.d/ ########
####### Name it as mhamanager ( Any name is ok :-) ##########
###### Grant the execution privilege ##############
####### Script Starts #################
#! /bin/sh
. /lib/lsb/init-functions
name="mhamanager"
#mhamanager_conf=/etc/app1.cnf  Configuration file for the MHA MANAGER
#mhamanager_log=/var/log/masterha/app1/app1.log  Log file location for the MHA 
manager
pid_file="/var/run/$name.pid"

start () {
command_ls=`nohup masterha_manager --conf=/etc/app1.cnf < /dev/null >> 
/var/log/masterha/app1/app1.log 2>&1 &`
ps -ef | grep -i "masterha_manager" | grep -v grep | awk '{print $2}' > 
$pid_file

log_daemon_msg "Starting $name"
}
stop () {
log_daemon_msg "Stopping $name"
start-stop-daemon --stop --quiet --oknodo --pidfile "$pid_file"
}
status () {
log_daemon_msg "Status of $name"
status_of_proc -p $pid_file "$name"
}
case $1 in
start)
if status; then exit 0; fi
start
status && exit 0 || exit $?
;;
stop)
stop
;;
reload)
stop
start
;;
restart)
stop
start
;;
status)
status && exit 0 || exit $?
;;
*)
echo "Usage: $0 {start|stop|restart|reload|status}"
exit 1
;;
esac
exit 0
######### Script Ends ################

Original comment by sj...@win2ix.ca on 25 Feb 2013 at 11:19