[projects/rc-scripts] add test script experimenting daemon --makepid --fork

glen glen at pld-linux.org
Fri Sep 9 23:06:56 CEST 2016


commit 43f8f34fe255587b198ca25d23ed77ac9e042c8a
Author: Elan Ruusamäe <glen at delfi.ee>
Date:   Sat Sep 10 00:06:08 2016 +0300

    add test script experimenting daemon --makepid --fork

 t/service-fork-makepid.sh | 51 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
---
diff --git a/t/service-fork-makepid.sh b/t/service-fork-makepid.sh
new file mode 100755
index 0000000..2426149
--- /dev/null
+++ b/t/service-fork-makepid.sh
@@ -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
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/projects/rc-scripts.git/commitdiff/43f8f34fe255587b198ca25d23ed77ac9e042c8a



More information about the pld-cvs-commit mailing list