mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-10 21:19:59 +00:00
Die if --log, --pid, or --dest aren't accessible. Also die if po dir isn't accessible.
This commit is contained in:
49
bin/pt-stalk
49
bin/pt-stalk
@@ -102,8 +102,20 @@ parse_options() {
|
||||
local file="$1"
|
||||
shift
|
||||
|
||||
mkdir "$TMPDIR/po/" 2>/dev/null
|
||||
if [ ! -d "$TMPDIR/po/" ]; then
|
||||
mkdir "$TMPDIR/po/"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Cannot mkdir $TMPDIR/po/" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
rm -rf "$TMPDIR"/po/*
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Cannot rm -rf $TMPDIR/po/*" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
(
|
||||
export PO_DIR="$TMPDIR/po"
|
||||
cat "$file" | perl -ne '
|
||||
@@ -399,6 +411,9 @@ make_pid_file() {
|
||||
fi
|
||||
|
||||
echo "$pid" > "$file"
|
||||
if [ $? -ne 0 ]; then
|
||||
die "Cannot create or write PID file $file"
|
||||
fi
|
||||
}
|
||||
|
||||
remove_pid_file() {
|
||||
@@ -890,19 +905,30 @@ main() {
|
||||
# we don't know our own PID. See the usage of $! below.
|
||||
log "$0 started"
|
||||
|
||||
# Make a secure tmpdir.
|
||||
mk_tmpdir
|
||||
|
||||
# Make the collection dir exists.
|
||||
mkdir -p "$OPT_DEST" || die "Can't make the destination directory"
|
||||
test -d "$OPT_DEST" || die "$OPT_DEST isn't a directory"
|
||||
test -w "$OPT_DEST" || die "$OPT_DEST isn't writable"
|
||||
if [ ! -d "$OPT_DEST" ]; then
|
||||
mkdir -p "$OPT_DEST" || die "Cannot make --dest $OPT_DEST"
|
||||
fi
|
||||
# Check access to the --dest dir. By setting -x in the subshell,
|
||||
# if either command fails, the subshell will exit immediately and
|
||||
# $? will be non-zero.
|
||||
(
|
||||
set -e
|
||||
touch "$OPT_DEST/test"
|
||||
rm "$OPT_DEST/test"
|
||||
)
|
||||
if [ $? -ne 0 ]; then
|
||||
die "Cannot read and write files to --dest $OPT_DEST"
|
||||
fi
|
||||
|
||||
# Test if we have root; warn if not, but it isn't critical.
|
||||
if [ "$(id -u)" != "0" ]; then
|
||||
log 'Not running with root privileges!';
|
||||
fi
|
||||
|
||||
# Make a secure tmpdir.
|
||||
mk_tmpdir
|
||||
|
||||
# Set TRIGGER_FUNCTION based on --function.
|
||||
set_trg_func
|
||||
|
||||
@@ -948,6 +974,15 @@ if [ "$(basename "$0")" = "pt-stalk" ] \
|
||||
|| die "Cannot connect to MySQL. Check that MySQL is running and that the options after -- are correct."
|
||||
|
||||
if [ "$OPT_DAEMONIZE" = "yes" ]; then
|
||||
# Check access to the --log file.
|
||||
(
|
||||
set -e
|
||||
touch "$OPT_LOG"
|
||||
)
|
||||
if [ $? -ne 0 ]; then
|
||||
die "Cannot write to --log $OPT_LOG"
|
||||
fi
|
||||
|
||||
# The PID file will at first have our (parent) PID.
|
||||
# This is fine for ensuring that only one of us is
|
||||
# running, but it's not fine if the user wants to use
|
||||
|
@@ -57,6 +57,9 @@ make_pid_file() {
|
||||
|
||||
# PID file doesn't exist, or it does but its pid is stale.
|
||||
echo "$pid" > "$file"
|
||||
if [ $? -ne 0 ]; then
|
||||
die "Cannot create or write PID file $file"
|
||||
fi
|
||||
}
|
||||
|
||||
remove_pid_file() {
|
||||
|
@@ -111,8 +111,20 @@ parse_options() {
|
||||
# default=foo
|
||||
# That's the spec for --string-opt2. Each line is a key:value pair
|
||||
# from the option's POD line like "type: string; default: foo".
|
||||
mkdir "$TMPDIR/po/" 2>/dev/null
|
||||
if [ ! -d "$TMPDIR/po/" ]; then
|
||||
mkdir "$TMPDIR/po/"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Cannot mkdir $TMPDIR/po/" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
rm -rf "$TMPDIR"/po/*
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Cannot rm -rf $TMPDIR/po/*" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
(
|
||||
export PO_DIR="$TMPDIR/po"
|
||||
cat "$file" | perl -ne '
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
TESTS=7
|
||||
TESTS=9
|
||||
|
||||
TMPDIR="$TEST_TMPDIR"
|
||||
local file="$TMPDIR/pid-file"
|
||||
@@ -60,6 +60,22 @@ is \
|
||||
rm $file
|
||||
rm $TMPDIR/output
|
||||
|
||||
# ###########################################################################
|
||||
# Die if pid file can't be created.
|
||||
# ###########################################################################
|
||||
(
|
||||
make_pid_file "/root/pid" $$ >$TMPDIR/output 2>&1
|
||||
)
|
||||
|
||||
is \
|
||||
"$?" \
|
||||
"1" \
|
||||
"Exit 1 if PID file can't be created"
|
||||
|
||||
cmd_ok \
|
||||
"grep -q 'Cannot create or write PID file /root/pid' $TMPDIR/output" \
|
||||
"Error that PID file can't be created"
|
||||
|
||||
# ###########################################################################
|
||||
# Done.
|
||||
# ###########################################################################
|
||||
|
@@ -136,7 +136,7 @@ diag(`rm $dest/* 2>/dev/null`);
|
||||
my (undef, $uptime) = $dbh->selectrow_array("SHOW STATUS LIKE 'Uptime'");
|
||||
my $threshold = $uptime + 2;
|
||||
|
||||
$retval = system("$trunk/bin/pt-stalk --iterations 1 --dest $dest --variable Uptime --threshold $threshold --cycles 2 --run-time 2 -- --defaults-file=$cnf >$log_file 2>&1");
|
||||
$retval = system("$trunk/bin/pt-stalk --iterations 1 --dest $dest --variable Uptime --threshold $threshold --cycles 2 --run-time 2 --pid $pid_file -- --defaults-file=$cnf >$log_file 2>&1");
|
||||
|
||||
sleep 3;
|
||||
|
||||
|
Reference in New Issue
Block a user