]> git.pld-linux.org Git - projects/rc-scripts.git/commitdiff
add test script experimenting daemon --makepid --fork
authorElan Ruusamäe <glen@delfi.ee>
Fri, 9 Sep 2016 21:06:08 +0000 (00:06 +0300)
committerElan Ruusamäe <glen@delfi.ee>
Fri, 9 Sep 2016 21:06:43 +0000 (00:06 +0300)
t/service-fork-makepid.sh [new file with mode: 0755]

diff --git a/t/service-fork-makepid.sh b/t/service-fork-makepid.sh
new file mode 100755 (executable)
index 0000000..2426149
--- /dev/null
@@ -0,0 +1,51 @@
+#!/bin/sh
+#
+# testcase experimenting whether daemon --pidfile --fork --makepid works with RC_LOGGING=on and off
+#
+
+dir=$(readlink -f $(dirname "$0"))
+testname=$(basename "$0")
+# save flags, as want to load functions with set +x
+set=$-
+
+set +x
+. $dir/../lib/functions
+set -$set
+
+pidfile=$dir/$testname.pid
+makepid="$dir/../lib/makepid"
+# use /bin/sleep to avoid using sleep builtin
+testprog="/bin/sleep 300"
+
+# fail on errors
+set -e
+
+assert_pidfile() {
+       pid=$(cat $pidfile)
+       # pid must exist
+       test -n "$pid"
+
+       # command must match what was started
+       cmd=$(ps -o cmd= -p $pid)
+       test "$cmd" = "$testprog"
+}
+
+test_makepid() {
+       rm -f $pidfile
+       PIDFILE=$pidfile $makepid $testprog
+       assert_pidfile
+}
+
+test_daemon() {
+       rm -f $pidfile
+       daemon --pidfile $pidfile --fork --makepid $testprog
+       assert_pidfile
+}
+
+test_makepid
+
+RC_LOGGING=yes
+test_daemon
+
+RC_LOGGING=no
+test_daemon
This page took 0.130174 seconds and 4 git commands to generate.