diff --git a/conf/booth.conf.example b/conf/booth.conf.example index d1fffcb..32ead62 100644 --- a/conf/booth.conf.example +++ b/conf/booth.conf.example @@ -1,25 +1,25 @@ -# The booth configuration file is "/etc/sysconfig/booth". You need to +# The booth configuration file is "/etc/booth/booth.conf". You need to # prepare the same booth configuration file on each arbitrator and # each node in the cluster sites where the booth daemon can be launched. # Here is an example of the configuration file: # "transport" means which transport layer booth daemon will use. # Currently only "UDP" is supported. transport="UDP" # The port that booth daemons will use to talk to each other. port="6666" # The arbitrator IP. If you want to configure several arbitrators, # you need to configure each arbitrator with a separate line. arbitrator="147.2.207.14" # The site IP. The cluster site uses this IP to talk to other sites. # Like arbitrator, you need to configure each site with a separate line. site="147.4.215.19" site="147.18.2.1" # The ticket name, which corresponds to a set of resources which can be # fail-overed among different sites. ticket="ticketA" ticket="ticketB" diff --git a/script/lsb/booth-arbitrator b/script/lsb/booth-arbitrator index c26a815..b89c0b9 100755 --- a/script/lsb/booth-arbitrator +++ b/script/lsb/booth-arbitrator @@ -1,89 +1,87 @@ #!/bin/bash # # BOOTH daemon init script for LSB-compliant Linux distributions. # # booth-arbitrator BOOTH arbitrator daemon # # chkconfig: - 20 20 # processname: boothd # pidfile: /var/run/booth.pid # description: Cluster Ticket Registry ### BEGIN INIT INFO # Provides: booth # Required-Start: $network $syslog # Required-Stop: $network $syslog # Should-Start: # Should-Stop: # Default-Start: 3 5 # Default-Stop: 0 6 # Short-Description: start and stop BOOTH arbitrator daemon ### END INIT INFO prog="boothd" exec="/usr/sbin/$prog" type="arbitrator" lockfile="/var/run/booth.pid" -[ -f /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog - . /etc/rc.status internal_status() { checkproc $exec > /dev/null 2>&1 return $? } status() { if internal_status; then echo "Running" return 0 else echo "Stopped" return 7 fi } start() { [ -x $exec ] || exit 5 echo -n $"Starting BOOTH arbitrator daemon: " if ! internal_status; then startproc $exec $type fi rc_status -v } stop() { echo -n $"Stopping BOOTH arbitrator daemon: " killproc -p $lockfile $prog -TERM rc_status -v } wait_for_stop() { while [ -e $lockfile ]; do sleep .5 done } restart() { stop wait_for_stop start } case "$1" in start|stop|restart) $1 ;; reload|force-reload) restart ;; condrestart|try-restart) [ ! -f "$lockfile" ] || restart ;; status) status $prog ;; *) echo $"Usage: $0 {start|stop|restart|try-restart|condrestart|reload|force-reload|status}" exit 2 esac diff --git a/src/booth.h b/src/booth.h index ff19afe..269f631 100644 --- a/src/booth.h +++ b/src/booth.h @@ -1,83 +1,83 @@ /* * Copyright (C) 2011 Jiaju Zhang * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _BOOTH_H #define _BOOTH_H #include #include #include #define BOOTH_LOG_DUMP_SIZE (1024*1024) #define BOOTH_RUN_DIR "/var/run" #define BOOTH_LOG_DIR "/var/log" #define BOOTH_LOGFILE_NAME "booth.log" #define BOOTH_DEFAULT_LOCKFILE BOOTH_RUN_DIR "/booth.pid" -#define BOOTH_DEFAULT_CONF "/etc/sysconfig/booth" +#define BOOTH_DEFAULT_CONF "/etc/booth/booth.conf" #define DAEMON_NAME "booth" #define BOOTH_NAME_LEN 63 #define BOOTH_PATH_LEN 127 #define BOOTHC_SOCK_PATH "boothc_lock" #define BOOTH_PROTO_FAMILY AF_INET #define BOOTH_CMD_PORT 22075 #define BOOTHC_MAGIC 0x5F1BA08C #define BOOTHC_VERSION 0x00010000 #define BOOTHC_OPT_FORCE 0x00000001 struct boothc_header { uint32_t magic; uint32_t version; uint32_t cmd; uint32_t option; uint32_t expiry; uint32_t len; uint32_t result; }; typedef enum { BOOTHC_CMD_LIST = 1, BOOTHC_CMD_GRANT, BOOTHC_CMD_REVOKE, } cmd_request_t; typedef enum { BOOTHC_RLT_ASYNC = 1, BOOTHC_RLT_SYNC_SUCC, BOOTHC_RLT_SYNC_FAIL, BOOTHC_RLT_INVALID_ARG, BOOTHC_RLT_REMOTE_OP, } cmd_result_t; struct client { int fd; void *workfn; void *deadfn; }; int client_add(int fd, void (*workfn)(int ci), void (*deadfn)(int ci)); int do_read(int fd, void *buf, size_t count); int do_write(int fd, void *buf, size_t count); void process_connection(int ci); void safe_copy(char *dest, char *value, size_t buflen, const char *description); #endif /* _BOOTH_H */ diff --git a/test/boothrunner.py b/test/boothrunner.py index 7ea3d70..77ea73b 100755 --- a/test/boothrunner.py +++ b/test/boothrunner.py @@ -1,108 +1,108 @@ #!/usr/bin/python import os import subprocess import time import unittest class BoothRunner: - default_config_file = '/etc/sysconfig/booth' + default_config_file = '/etc/booth/booth.conf' default_lock_file = '/var/run/booth.pid' def __init__(self, boothd_path, mode, args): self.boothd_path = boothd_path self.args = [ mode ] self.final_args = args # will be appended to self.args self.mode = mode self.config_file = None self.lock_file = None def set_config_file_arg(self): self.args += [ '-c', self.config_file ] def set_config_file(self, config_file): self.config_file = config_file self.set_config_file_arg() def set_lock_file(self, lock_file): self.lock_file = lock_file self.args += [ '-l', self.lock_file ] def set_debug(self): self.args += [ '-D' ] def all_args(self): return [ self.boothd_path ] + self.args + self.final_args def show_output(self, stdout, stderr): if stdout: print "STDOUT:" print "------" print stdout, if stderr: print "STDERR:" print "------" print stderr, print "-" * 70 def subproc_completed_within(self, p, timeout): start = time.time() wait = 0.1 while True: if p.poll() is not None: return True elapsed = time.time() - start if elapsed + wait > timeout: wait = timeout - elapsed print "Waiting on %d for %.1fs ..." % (p.pid, wait) time.sleep(wait) elapsed = time.time() - start if elapsed >= timeout: return False wait *= 2 def lock_file_used(self): return self.lock_file or self.default_lock_file def config_file_used(self): return self.config_file or self.default_config_file def config_text_used(self): config_file = self.config_file_used() try: c = open(config_file) except: return None text = "".join(c.readlines()) c.close() text = text.replace('\t', '') text = text.replace('\n', '|\n') return text def show_args(self): print "\n" print "-" * 70 print "Running", ' '.join(self.all_args()) msg = "with config from %s" % self.config_file_used() config_text = self.config_text_used() if config_text is not None: msg += ": [%s]" % config_text print msg def run(self): p = subprocess.Popen(self.all_args(), stdout=subprocess.PIPE, stderr=subprocess.PIPE) if not p: raise RuntimeError, "failed to start subprocess" print "Started subprocess pid %d" % p.pid completed = self.subproc_completed_within(p, 2) if completed: (stdout, stderr) = p.communicate() self.show_output(stdout, stderr) return (p.pid, p.returncode, stdout, stderr) return (p.pid, None, None, None)