mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-11 13:40:07 +00:00
Add daemon.sh.
This commit is contained in:
72
t/lib/bash/daemon.sh
Normal file
72
t/lib/bash/daemon.sh
Normal file
@@ -0,0 +1,72 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
TESTS=8
|
||||
|
||||
TMPDIR="$TEST_TMPDIR"
|
||||
ON_EXIT=":"
|
||||
local file="$TMPDIR/pid-file"
|
||||
|
||||
source "$LIB_DIR/log_warn_die.sh"
|
||||
source "$LIB_DIR/daemon.sh"
|
||||
|
||||
cmd_ok \
|
||||
"test ! -f $file" \
|
||||
"PID file doesn't exist"
|
||||
|
||||
make_pid_file $file $$
|
||||
|
||||
cmd_ok \
|
||||
"test -f $file" \
|
||||
"PID file created"
|
||||
|
||||
local pid=`cat $file`
|
||||
is \
|
||||
"$pid" \
|
||||
"$$" \
|
||||
"Correct PID"
|
||||
|
||||
remove_pid_file $file
|
||||
|
||||
cmd_ok \
|
||||
"test ! -f $file" \
|
||||
"PID file removed"
|
||||
|
||||
is \
|
||||
"$ON_EXIT" \
|
||||
":; remove_pid_file $file" \
|
||||
"Sets ON_EXIT to remove PID file"
|
||||
|
||||
# ###########################################################################
|
||||
# PID file already exists and proc is running.
|
||||
# ###########################################################################
|
||||
ON_EXIT=""
|
||||
echo $$ > $file
|
||||
|
||||
(
|
||||
make_pid_file $file $$ >$TMPDIR/output 2>&1
|
||||
)
|
||||
|
||||
cmd_ok \
|
||||
"grep -q \"PID file /tmp/percona-toolkit.test/pid-file already exists and its PID ($$) is running\" $TMPDIR/output" \
|
||||
"Does not overwrite PID file is PID is running"
|
||||
|
||||
echo 999999 > $file
|
||||
|
||||
make_pid_file $file $$ >$TMPDIR/output 2>&1
|
||||
|
||||
cmd_ok \
|
||||
"grep -q 'Overwriting PID file /tmp/percona-toolkit.test/pid-file because its PID (999999) is not running' $TMPDIR/output" \
|
||||
"Overwrites PID file if PID is not running"
|
||||
|
||||
pid=`cat $file`
|
||||
is \
|
||||
"$pid" \
|
||||
"$$" \
|
||||
"Correct PID"
|
||||
|
||||
rm $file
|
||||
rm $TMPDIR/output
|
||||
|
||||
# ###########################################################################
|
||||
# Done.
|
||||
# ###########################################################################
|
Reference in New Issue
Block a user