mirror of
https://github.com/samba-team/samba.git
synced 2025-02-12 21:58:10 +03:00
merge from tridge
(This used to be ctdb commit 54136ff841459184d44acc314bff3d36c2868391)
This commit is contained in:
commit
31fe67c068
@ -51,7 +51,7 @@ CTDB_SERVER_OBJ = server/ctdbd.o server/ctdb_daemon.o server/ctdb_lockwait.o \
|
||||
server/ctdb_control.o server/ctdb_call.o server/ctdb_ltdb_server.o \
|
||||
server/ctdb_traverse.o server/eventscript.o server/ctdb_takeover.o \
|
||||
server/ctdb_serverids.o server/ctdb_persistent.o \
|
||||
server/ctdb_keepalive.o \
|
||||
server/ctdb_keepalive.o server/ctdb_logging.o \
|
||||
$(CTDB_CLIENT_OBJ) $(CTDB_TCP_OBJ) @INFINIBAND_WRAPPER_OBJ@
|
||||
|
||||
TEST_BINS=bin/ctdb_bench bin/ctdb_fetch bin/ctdb_store bin/ctdb_randrec bin/ctdb_persistent bin/rb_test \
|
||||
|
@ -42,7 +42,7 @@ case $cmd in
|
||||
varname=`echo $v | cut -d= -f1`
|
||||
value=`echo $v | cut -d= -f2`
|
||||
ctdb setvar $varname $value || exit 1
|
||||
echo "`date` Set $varname to $value"
|
||||
echo "Set $varname to $value"
|
||||
done || exit 1
|
||||
;;
|
||||
|
||||
|
@ -16,7 +16,7 @@ shift
|
||||
}
|
||||
|
||||
[ ! -f "$CTDB_PUBLIC_ADDRESSES" ] && {
|
||||
echo "`date` No public addresses file found. Nothing to do for 10.interfaces"
|
||||
echo "No public addresses file found. Nothing to do for 10.interfaces"
|
||||
exit 0
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@ case $cmd in
|
||||
[ -z "$_IP_HELD" ] || {
|
||||
_IFACE=`echo $_IP_HELD | sed -e "s/.*\s//"`
|
||||
_NM=`echo $_IP_HELD | sed -e "s/.*$_IP\///" -e "s/\s.*//"`
|
||||
echo "`date` Removing public address $_IP/$_NM from device $_IFACE"
|
||||
echo "Removing public address $_IP/$_NM from device $_IFACE"
|
||||
/sbin/ip addr del $_IP/$_NM dev $_IFACE
|
||||
}
|
||||
done
|
||||
@ -45,7 +45,7 @@ case $cmd in
|
||||
# called when ctdbd wants to claim an IP address
|
||||
takeip)
|
||||
if [ $# != 3 ]; then
|
||||
echo "`date` must supply interface, IP and maskbits"
|
||||
echo "must supply interface, IP and maskbits"
|
||||
exit 1
|
||||
fi
|
||||
iface=$1
|
||||
@ -54,11 +54,11 @@ case $cmd in
|
||||
|
||||
# we make sure the interface is up first
|
||||
/sbin/ip link set $iface up || {
|
||||
echo "`/bin/date` Failed to bringup interface $iface"
|
||||
echo "Failed to bringup interface $iface"
|
||||
exit 1
|
||||
}
|
||||
/sbin/ip addr add $ip/$maskbits dev $iface || {
|
||||
echo "`/bin/date` Failed to add $ip/$maskbits on dev $iface"
|
||||
echo "Failed to add $ip/$maskbits on dev $iface"
|
||||
exit 1
|
||||
}
|
||||
# cope with the script being killed while we have the interface blocked
|
||||
@ -73,7 +73,7 @@ case $cmd in
|
||||
# called when ctdbd wants to release an IP address
|
||||
releaseip)
|
||||
if [ $# != 3 ]; then
|
||||
echo "`/bin/date` must supply interface, IP and maskbits"
|
||||
echo "must supply interface, IP and maskbits"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@ -108,16 +108,16 @@ case $cmd in
|
||||
[ -z "$secondaries" ] || {
|
||||
for i in $secondaries; do
|
||||
if /sbin/ip addr list dev $iface | grep "inet $i" > /dev/null; then
|
||||
echo "`date` kept secondary $i on dev $iface"
|
||||
echo "kept secondary $i on dev $iface"
|
||||
else
|
||||
echo "`date` re-adding secondary address $i to dev $iface"
|
||||
echo "re-adding secondary address $i to dev $iface"
|
||||
/sbin/ip addr add $i dev $iface || failed=1
|
||||
fi
|
||||
done
|
||||
}
|
||||
/sbin/iptables -D INPUT -i $iface -d $ip -j DROP
|
||||
[ $failed = 0 ] || {
|
||||
echo "`/bin/date` Failed to del $ip on dev $iface"
|
||||
echo "Failed to del $ip on dev $iface"
|
||||
exit 1
|
||||
}
|
||||
|
||||
@ -148,13 +148,13 @@ case $cmd in
|
||||
for IFACE in $INTERFACES ; do
|
||||
if [ `echo $IFACE | grep '^bond*'` ] ; then
|
||||
grep '^MII Status: up' /proc/net/bonding/$IFACE > /dev/null || {
|
||||
echo "`date` ERROR: public network interface $IFACE is down"
|
||||
echo "ERROR: public network interface $IFACE is down"
|
||||
exit 1
|
||||
}
|
||||
else
|
||||
[ -z "$IFACE" ] || {
|
||||
/usr/sbin/ethtool $IFACE | grep 'Link detected: yes' > /dev/null || {
|
||||
echo "`date` ERROR: No link on the public network interface $IFACE"
|
||||
echo "ERROR: No link on the public network interface $IFACE"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ shift
|
||||
periodic_cleanup() {
|
||||
# running smbstatus scrubs any dead entries from the connections
|
||||
# and sessionid database
|
||||
echo "`date` Running periodic cleanup of samba databases"
|
||||
echo "Running periodic cleanup of samba databases"
|
||||
smbstatus -n > /dev/null 2>&1 &
|
||||
}
|
||||
|
||||
@ -105,7 +105,7 @@ case $cmd in
|
||||
}
|
||||
|
||||
testparm -s 2>&1 | egrep '^WARNING|^ERROR|^Unknown' && {
|
||||
echo "`date` ERROR: testparm shows smb.conf is not clean"
|
||||
echo "ERROR: testparm shows smb.conf is not clean"
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ case $cmd in
|
||||
# mount needs special handling since it is sometimes not started
|
||||
# correctly on RHEL5
|
||||
rpcinfo -u localhost 100005 1 > /dev/null || {
|
||||
echo "`date` ERROR: MOUNTD is not running. Trying to restart it."
|
||||
echo "ERROR: MOUNTD is not running. Trying to restart it."
|
||||
RPCMOUNTDOPTS=""
|
||||
[ -n "$MOUNTD_PORT" ] && RPCMOUNTDOPTS="$RPCMOUNTDOPTS -p $MOUNTD_PORT"
|
||||
killall -q -9 rpc.mountd
|
||||
|
@ -31,7 +31,7 @@ case $cmd in
|
||||
dip=`echo $dest | cut -d: -f1`
|
||||
dport=`echo $dest | cut -d: -f2`
|
||||
# send three, in case of lost packets
|
||||
echo "`date` Sending NFS tickle ack for $ip to $dip:$dport"
|
||||
echo "Sending NFS tickle ack for $ip to $dip:$dport"
|
||||
for i in `seq 1 3`; do
|
||||
ctdb tickle $dip:$dport $ip:2049
|
||||
done
|
||||
|
@ -38,7 +38,7 @@ ctdb_wait_command() {
|
||||
wait_cmd="$2"
|
||||
[ -z "$wait_cmd" ] && return;
|
||||
all_ok=0
|
||||
echo "`/bin/date` Waiting for service $service_name to start"
|
||||
echo "Waiting for service $service_name to start"
|
||||
while [ $all_ok -eq 0 ]; do
|
||||
$wait_cmd > /dev/null 2>&1 && all_ok=1
|
||||
ctdb status > /dev/null 2>&1 || {
|
||||
@ -47,7 +47,7 @@ ctdb_wait_command() {
|
||||
}
|
||||
[ $all_ok -eq 1 ] || sleep 1
|
||||
done
|
||||
echo "`/bin/date` Local service $service_name is up"
|
||||
echo "Local service $service_name is up"
|
||||
}
|
||||
|
||||
|
||||
@ -61,7 +61,7 @@ ctdb_wait_tcp_ports() {
|
||||
wait_ports="$*"
|
||||
[ -z "$wait_ports" ] && return;
|
||||
all_ok=0
|
||||
echo "`/bin/date` Waiting for tcp service $service_name to start"
|
||||
echo "Waiting for tcp service $service_name to start"
|
||||
while [ $all_ok -eq 0 ]; do
|
||||
all_ok=1
|
||||
for p in $wait_ports; do
|
||||
@ -72,7 +72,7 @@ ctdb_wait_tcp_ports() {
|
||||
elif [ -x /usr/bin/netstat ]; then
|
||||
(/usr/bin/netstat -a -n | egrep "0.0.0.0:$p\s*LISTEN" > /dev/null) || all_ok=0
|
||||
else
|
||||
echo "`date` - No tool to check tcp ports availabe. can not check in ctdb_wait_tcp_ports"
|
||||
echo "No tool to check tcp ports availabe. can not check in ctdb_wait_tcp_ports"
|
||||
return
|
||||
fi
|
||||
done
|
||||
@ -82,7 +82,7 @@ ctdb_wait_tcp_ports() {
|
||||
exit 1
|
||||
}
|
||||
done
|
||||
echo "`/bin/date` Local tcp services for $service_name are up"
|
||||
echo "Local tcp services for $service_name are up"
|
||||
}
|
||||
|
||||
|
||||
@ -97,7 +97,7 @@ ctdb_wait_directories() {
|
||||
wait_dirs="$*"
|
||||
[ -z "$wait_dirs" ] && return;
|
||||
all_ok=0
|
||||
echo "`/bin/date` Waiting for local directories for $service_name"
|
||||
echo "Waiting for local directories for $service_name"
|
||||
while [ $all_ok -eq 0 ]; do
|
||||
all_ok=1
|
||||
for d in $wait_dirs; do
|
||||
@ -109,7 +109,7 @@ ctdb_wait_directories() {
|
||||
exit 1
|
||||
}
|
||||
done
|
||||
echo "`/bin/date` Local directories for $service_name are available"
|
||||
echo "Local directories for $service_name are available"
|
||||
}
|
||||
|
||||
|
||||
@ -123,7 +123,7 @@ ctdb_check_rpc() {
|
||||
prognum="$2"
|
||||
version="$3"
|
||||
rpcinfo -u localhost $prognum $version > /dev/null || {
|
||||
echo "`date` ERROR: $service_name not responding to rpc requests"
|
||||
echo "ERROR: $service_name not responding to rpc requests"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
@ -139,7 +139,7 @@ ctdb_check_directories() {
|
||||
[ -z "$wait_dirs" ] && return;
|
||||
for d in $wait_dirs; do
|
||||
[ -d $d ] || {
|
||||
echo "`date` ERROR: $service_name directory $d not available"
|
||||
echo "ERROR: $service_name directory $d not available"
|
||||
exit 1
|
||||
}
|
||||
done
|
||||
@ -164,7 +164,7 @@ ctdb_check_tcp_ports() {
|
||||
(/usr/bin/netstat -a -n | egrep "0.0.0.0:$p .*LISTEN" > /dev/null ) || all_ok=0
|
||||
fi
|
||||
[ $all_ok -eq 1 ] || {
|
||||
echo "`date` ERROR: $service_name tcp port $p is not responding"
|
||||
echo "ERROR: $service_name tcp port $p is not responding"
|
||||
exit 1
|
||||
}
|
||||
done
|
||||
@ -179,7 +179,7 @@ ctdb_check_command() {
|
||||
wait_cmd="$2"
|
||||
[ -z "$wait_cmd" ] && return;
|
||||
$wait_cmd > /dev/null 2>&1 || {
|
||||
echo "`date` ERROR: $service_name - $wait_cmd returned error"
|
||||
echo "ERROR: $service_name - $wait_cmd returned error"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
@ -200,12 +200,12 @@ kill_tcp_connections() {
|
||||
destip=`echo $dest | cut -d: -f1`
|
||||
destport=`echo $dest | cut -d: -f2`
|
||||
ctdb killtcp $srcip:$srcport $destip:$destport >/dev/null 2>&1 || _failed=1
|
||||
echo "`date` Killing TCP connection $srcip:$srcport $destip:$destport"
|
||||
echo "Killing TCP connection $srcip:$srcport $destip:$destport"
|
||||
_killcount=`expr $_killcount + 1`
|
||||
done < $connfile
|
||||
/bin/rm -f $connfile
|
||||
[ $_failed = 0 ] || {
|
||||
echo "`date` Failed to send killtcp control"
|
||||
echo "Failed to send killtcp control"
|
||||
return;
|
||||
}
|
||||
[ $_killcount -gt 0 ] || {
|
||||
@ -216,10 +216,10 @@ kill_tcp_connections() {
|
||||
sleep 1
|
||||
_count=`expr $_count + 1`
|
||||
[ $_count -gt 3 ] && {
|
||||
echo "`date` Timed out killing tcp connections for IP $_IP"
|
||||
echo "Timed out killing tcp connections for IP $_IP"
|
||||
return;
|
||||
}
|
||||
done
|
||||
echo "`date` killed $_killcount TCP connections to released IP $_IP"
|
||||
echo "killed $_killcount TCP connections to released IP $_IP"
|
||||
}
|
||||
|
||||
|
@ -407,7 +407,7 @@ uint32_t *ctdb_get_connected_nodes(struct ctdb_context *ctdb,
|
||||
|
||||
int ctdb_statistics_reset(struct ctdb_context *ctdb, uint32_t destnode);
|
||||
|
||||
int ctdb_set_logfile(struct ctdb_context *ctdb, const char *logfile);
|
||||
int ctdb_set_logfile(struct ctdb_context *ctdb, const char *logfile, bool use_syslog);
|
||||
|
||||
typedef int (*ctdb_traverse_func)(struct ctdb_context *, TDB_DATA, TDB_DATA, void *);
|
||||
int ctdb_traverse(struct ctdb_db_context *ctdb_db, ctdb_traverse_func fn, void *private_data);
|
||||
|
@ -369,6 +369,7 @@ struct ctdb_context {
|
||||
bool done_startup;
|
||||
const char *node_ip;
|
||||
struct ctdb_monitor_state *monitor;
|
||||
struct ctdb_log_state *log;
|
||||
};
|
||||
|
||||
struct ctdb_db_context {
|
||||
@ -1213,5 +1214,6 @@ int32_t ctdb_control_delete_record(struct ctdb_context *ctdb, TDB_DATA indata);
|
||||
void ctdb_block_signal(int signum);
|
||||
void ctdb_unblock_signal(int signum);
|
||||
int32_t ctdb_monitoring_mode(struct ctdb_context *ctdb);
|
||||
int ctdb_set_child_logging(struct ctdb_context *ctdb);
|
||||
|
||||
#endif
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
void do_debug_v(const char *format, va_list ap)
|
||||
static void _do_debug_v(const char *format, va_list ap)
|
||||
{
|
||||
struct timeval t;
|
||||
char *s = NULL;
|
||||
@ -41,6 +41,9 @@ void do_debug_v(const char *format, va_list ap)
|
||||
free(s);
|
||||
}
|
||||
|
||||
/* default logging function */
|
||||
void (*do_debug_v)(const char *, va_list ap) = _do_debug_v;
|
||||
|
||||
void do_debug(const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
@ -49,3 +52,4 @@ void do_debug(const char *format, ...)
|
||||
do_debug_v(format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
|
@ -17,5 +17,5 @@
|
||||
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
void do_debug_v(const char *format, va_list ap);
|
||||
void (*do_debug_v)(const char *, va_list ap);
|
||||
void do_debug(const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
|
||||
|
@ -656,6 +656,8 @@ int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork)
|
||||
|
||||
ctdb->ev = event_context_init(NULL);
|
||||
|
||||
ctdb_set_child_logging(ctdb);
|
||||
|
||||
/* force initial recovery for election */
|
||||
ctdb->recovery_mode = CTDB_RECOVERY_ACTIVE;
|
||||
|
||||
|
174
ctdb/server/ctdb_logging.c
Normal file
174
ctdb/server/ctdb_logging.c
Normal file
@ -0,0 +1,174 @@
|
||||
/*
|
||||
ctdb logging code
|
||||
|
||||
Copyright (C) Andrew Tridgell 2008
|
||||
|
||||
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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
#include "lib/events/events.h"
|
||||
#include "../include/ctdb_private.h"
|
||||
#include "system/syslog.h"
|
||||
#include "system/time.h"
|
||||
#include "system/filesys.h"
|
||||
|
||||
struct ctdb_log_state {
|
||||
char *logfile;
|
||||
int fd, pfd;
|
||||
char buf[1024];
|
||||
uint16_t buf_used;
|
||||
bool use_syslog;
|
||||
};
|
||||
|
||||
/* we need this global to eep the DEBUG() syntax */
|
||||
static struct ctdb_log_state *log_state;
|
||||
|
||||
/*
|
||||
syslog logging function
|
||||
*/
|
||||
static void ctdb_syslog_log(const char *format, va_list ap)
|
||||
{
|
||||
vsyslog(LOG_NOTICE, format, ap);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
log file logging function
|
||||
*/
|
||||
static void ctdb_logfile_log(const char *format, va_list ap)
|
||||
{
|
||||
struct timeval t;
|
||||
char *s = NULL;
|
||||
struct tm *tm;
|
||||
char tbuf[100];
|
||||
|
||||
vasprintf(&s, format, ap);
|
||||
|
||||
t = timeval_current();
|
||||
tm = localtime(&t.tv_sec);
|
||||
|
||||
strftime(tbuf,sizeof(tbuf)-1,"%Y/%m/%d %H:%M:%S", tm);
|
||||
|
||||
dprintf(log_state->fd, "%s.%06u [%5u]: %s",
|
||||
tbuf, (unsigned)t.tv_usec, (unsigned)getpid(), s);
|
||||
free(s);
|
||||
}
|
||||
|
||||
/*
|
||||
choose the logfile location
|
||||
*/
|
||||
int ctdb_set_logfile(struct ctdb_context *ctdb, const char *logfile, bool use_syslog)
|
||||
{
|
||||
ctdb->log = talloc_zero(ctdb, struct ctdb_log_state);
|
||||
|
||||
log_state = ctdb->log;
|
||||
|
||||
if (use_syslog) {
|
||||
do_debug_v = ctdb_syslog_log;
|
||||
ctdb->log->use_syslog = true;
|
||||
} else if (logfile == NULL || strcmp(logfile, "-") == 0) {
|
||||
do_debug_v = ctdb_logfile_log;
|
||||
ctdb->log->fd = 1;
|
||||
/* also catch stderr of subcommands to stdout */
|
||||
dup2(1, 2);
|
||||
} else {
|
||||
do_debug_v = ctdb_logfile_log;
|
||||
ctdb->log->logfile = talloc_strdup(ctdb, logfile);
|
||||
|
||||
ctdb->log->fd = open(logfile, O_WRONLY|O_APPEND|O_CREAT, 0666);
|
||||
if (ctdb->log->fd == -1) {
|
||||
printf("Failed to open logfile %s\n", ctdb->logfile);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
called when log data comes in from a child process
|
||||
*/
|
||||
static void ctdb_log_handler(struct event_context *ev, struct fd_event *fde,
|
||||
uint16_t flags, void *private)
|
||||
{
|
||||
struct ctdb_context *ctdb = talloc_get_type(private, struct ctdb_context);
|
||||
ssize_t n;
|
||||
char *p;
|
||||
|
||||
if (!(flags & EVENT_FD_READ)) {
|
||||
return;
|
||||
}
|
||||
|
||||
n = read(ctdb->log->pfd, &ctdb->log->buf[ctdb->log->buf_used],
|
||||
sizeof(ctdb->log->buf) - ctdb->log->buf_used);
|
||||
if (n > 0) {
|
||||
ctdb->log->buf_used += n;
|
||||
}
|
||||
|
||||
if (ctdb->log->buf_used == sizeof(ctdb->log->buf)) {
|
||||
do_debug("%*.*s\n", ctdb->log->buf_used, ctdb->log->buf_used, ctdb->log->buf);
|
||||
ctdb->log->buf_used = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
p = memchr(ctdb->log->buf, '\n', ctdb->log->buf_used);
|
||||
if (!p) {
|
||||
return;
|
||||
}
|
||||
|
||||
n = (p - ctdb->log->buf)+1;
|
||||
do_debug("%*.*s", n, n, ctdb->log->buf);
|
||||
memmove(ctdb->log->buf, ctdb->log->buf+n, sizeof(ctdb->log->buf) - n);
|
||||
ctdb->log->buf_used -= n;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
setup for logging of child process stdout
|
||||
*/
|
||||
int ctdb_set_child_logging(struct ctdb_context *ctdb)
|
||||
{
|
||||
int p[2];
|
||||
|
||||
if (ctdb->log->fd == 1) {
|
||||
/* not needed for stdout logging */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* setup a pipe to catch IO from subprocesses */
|
||||
if (pipe(p) != 0) {
|
||||
DEBUG(0,(__location__ " Failed to setup for child logging pipe\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
event_add_fd(ctdb->ev, ctdb, p[0], EVENT_FD_READ,
|
||||
ctdb_log_handler, ctdb);
|
||||
set_close_on_exec(p[0]);
|
||||
ctdb->log->pfd = p[0];
|
||||
|
||||
close(1);
|
||||
close(2);
|
||||
if (p[1] != 1) {
|
||||
dup2(p[1], 1);
|
||||
close(p[1]);
|
||||
}
|
||||
/* also catch stderr of subcommands to the log */
|
||||
dup2(1, 2);
|
||||
|
||||
return 0;
|
||||
}
|
@ -2508,6 +2508,11 @@ int ctdb_start_recoverd(struct ctdb_context *ctdb)
|
||||
|
||||
srandom(getpid() ^ time(NULL));
|
||||
|
||||
/* the recovery daemon does not need to be realtime */
|
||||
if (ctdb->do_setsched) {
|
||||
ctdb_restore_scheduler(ctdb);
|
||||
}
|
||||
|
||||
/* initialise ctdb */
|
||||
ret = ctdb_socket_connect(ctdb);
|
||||
if (ret != 0) {
|
||||
|
@ -60,32 +60,6 @@ int ctdb_set_recovery_lock_file(struct ctdb_context *ctdb, const char *file)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
choose the logfile location
|
||||
*/
|
||||
int ctdb_set_logfile(struct ctdb_context *ctdb, const char *logfile)
|
||||
{
|
||||
ctdb->logfile = talloc_strdup(ctdb, logfile);
|
||||
if (ctdb->logfile != NULL && strcmp(logfile, "-") != 0) {
|
||||
int fd;
|
||||
fd = open(ctdb->logfile, O_WRONLY|O_APPEND|O_CREAT, 0666);
|
||||
if (fd == -1) {
|
||||
printf("Failed to open logfile %s\n", ctdb->logfile);
|
||||
abort();
|
||||
}
|
||||
close(1);
|
||||
close(2);
|
||||
if (fd != 1) {
|
||||
dup2(fd, 1);
|
||||
close(fd);
|
||||
}
|
||||
/* also catch stderr of subcommands to the log file */
|
||||
dup2(1, 2);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
set the directory for the local databases
|
||||
*/
|
||||
|
@ -40,6 +40,7 @@ static struct {
|
||||
const char *single_public_ip;
|
||||
const char *node_ip;
|
||||
int no_setsched;
|
||||
int use_syslog;
|
||||
} options = {
|
||||
.nlist = ETCDIR "/ctdb/nodes",
|
||||
.transport = "tcp",
|
||||
@ -106,6 +107,7 @@ int main(int argc, const char *argv[])
|
||||
{ "dbdir-persistent", 0, POPT_ARG_STRING, &options.db_dir_persistent, 0, "directory for persistent tdb files", NULL },
|
||||
{ "reclock", 0, POPT_ARG_STRING, &options.recovery_lock_file, 0, "location of recovery lock file", "filename" },
|
||||
{ "nosetsched", 0, POPT_ARG_NONE, &options.no_setsched, 0, "disable setscheduler SCHED_FIFO call", NULL },
|
||||
{ "syslog", 0, POPT_ARG_NONE, &options.use_syslog, 0, "log messages to syslog", NULL },
|
||||
POPT_TABLEEND
|
||||
};
|
||||
int opt, ret;
|
||||
@ -145,9 +147,10 @@ int main(int argc, const char *argv[])
|
||||
|
||||
ctdb = ctdb_cmdline_init(ev);
|
||||
|
||||
ret = ctdb_set_logfile(ctdb, options.logfile);
|
||||
ret = ctdb_set_logfile(ctdb, options.logfile, options.use_syslog);
|
||||
if (ret == -1) {
|
||||
printf("ctdb_set_logfile to %s failed - %s\n", options.logfile, ctdb_errstr(ctdb));
|
||||
printf("ctdb_set_logfile to %s failed - %s\n",
|
||||
options.use_syslog?"syslog":options.logfile, ctdb_errstr(ctdb));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@ -261,14 +264,6 @@ int main(int argc, const char *argv[])
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* useful default logfile */
|
||||
if (ctdb->logfile == NULL) {
|
||||
char *name = talloc_asprintf(ctdb, "%s/log.ctdb.pnn%u",
|
||||
VARDIR, ctdb->pnn);
|
||||
ctdb_set_logfile(ctdb, name);
|
||||
talloc_free(name);
|
||||
}
|
||||
|
||||
ctdb->do_setsched = !options.no_setsched;
|
||||
|
||||
/* setup a environment variable for the event scripts to use to find the
|
||||
|
@ -6,11 +6,12 @@ shift
|
||||
|
||||
case $cmd in
|
||||
monitor)
|
||||
echo "`date` monitor event"
|
||||
echo "monitor event"
|
||||
echo "monitor event stderr" >&2
|
||||
exit 0
|
||||
;;
|
||||
startup)
|
||||
echo "`date` ctdb startup event"
|
||||
echo "ctdb startup event"
|
||||
exit 0;
|
||||
;;
|
||||
|
||||
@ -25,7 +26,7 @@ case $cmd in
|
||||
|
||||
[ `id -u` = 0 ] && {
|
||||
/sbin/ip addr add $ip/$maskbits dev $iface || {
|
||||
echo "`/bin/date` Failed to add $ip/$maskbits on dev $iface"
|
||||
echo "Failed to add $ip/$maskbits on dev $iface"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
@ -37,7 +38,7 @@ case $cmd in
|
||||
# called when ctdbd wants to release an IP address
|
||||
releaseip)
|
||||
if [ $# != 3 ]; then
|
||||
echo "`/bin/date` must supply interface, IP and maskbits"
|
||||
echo "must supply interface, IP and maskbits"
|
||||
exit 1
|
||||
fi
|
||||
iface=$1
|
||||
@ -45,24 +46,24 @@ case $cmd in
|
||||
maskbits=$3
|
||||
[ `id -u` = 0 ] && {
|
||||
/sbin/ip addr del $ip/$maskbits dev $iface || {
|
||||
echo "`/bin/date` Failed to del $ip on dev $iface"
|
||||
echo "Failed to del $ip on dev $iface"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
echo "`date` ctdb takeip event for $1 $2 $3"
|
||||
echo "ctdb takeip event for $1 $2 $3"
|
||||
exit 0
|
||||
;;
|
||||
|
||||
recovered)
|
||||
echo "`date` ctdb recovered event"
|
||||
echo "ctdb recovered event"
|
||||
exit 0
|
||||
;;
|
||||
|
||||
shutdown)
|
||||
echo "`date` ctdb shutdown event"
|
||||
echo "ctdb shutdown event"
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "`/bin/date` Invalid command $cmd"
|
||||
echo "Invalid command $cmd"
|
||||
exit 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user