Commit 4424747e authored by dulajdilshan's avatar dulajdilshan

Added a patch which added a status target to the initscript

parent 3e029d55
>From 984ff8a1a01e01d3510733388338bc6d409b1fba Mon Sep 17 00:00:00 2001
From: Gunnar Wolf <gwolf@debian.org>
Date: Tue, 19 Nov 2013 11:54:14 -0600
Subject: [PATCH] Added a "status" target to the initscript
---
debian/changelog | 7 +++++
debian/control | 2 +-
debian/patches/fix-init-script | 63 ++++++++++++++++++++++++++++++++++++++----
3 files changed, 66 insertions(+), 6 deletions(-)
diff --git a/debian/changelog b/debian/changelog
index 6e74d9a..dda5de9 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+thin (1.3.1-4) UNRELEASED; urgency=low
+
+ * Team upload
+ * Added a "status" target to the initscript
+
+ -- Gunnar Wolf <gwolf@debian.org> Tue, 19 Nov 2013 11:48:22 -0600
+
thin (1.3.1-3) unstable; urgency=low
* Team upload.
diff --git a/debian/control b/debian/control
index 999c30f..617e045 100644
--- a/debian/control
+++ b/debian/control
@@ -13,7 +13,7 @@ XS-Ruby-Versions: all
Package: thin
Architecture: any
XB-Ruby-Versions: ${ruby:Versions}
-Depends: ${shlibs:Depends}, ${misc:Depends}, ruby | ruby-interpreter, ruby-rack (>= 1.0.0), ruby-eventmachine (>= 0.12.10), ruby-daemons (>= 1.0.9)
+Depends: ${shlibs:Depends}, ${misc:Depends}, ruby | ruby-interpreter, ruby-rack (>= 1.0.0), ruby-eventmachine (>= 0.12.10), ruby-daemons (>= 1.0.9), lsb-base
Replaces: thin1.8 (<< 1.3.1-1)
Breaks: thin1.8 (<< 1.3.1-1)
Provides: thin1.8
diff --git a/debian/patches/fix-init-script b/debian/patches/fix-init-script
index 249f261..adab242 100644
--- a/debian/patches/fix-init-script
+++ b/debian/patches/fix-init-script
@@ -1,9 +1,9 @@
# (better) lsb compliance
-Index: ruby-thin/lib/thin/controllers/service.sh.erb
+Index: thin/lib/thin/controllers/service.sh.erb
===================================================================
---- ruby-thin.orig/lib/thin/controllers/service.sh.erb 2012-01-10 01:15:50.000000000 -0800
-+++ ruby-thin/lib/thin/controllers/service.sh.erb 2012-01-10 01:17:56.000000000 -0800
+--- thin.orig/lib/thin/controllers/service.sh.erb 2013-11-19 11:40:33.000000000 -0600
++++ thin/lib/thin/controllers/service.sh.erb 2013-11-19 11:43:17.000000000 -0600
@@ -4,7 +4,7 @@
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
@@ -13,11 +13,13 @@ Index: ruby-thin/lib/thin/controllers/service.sh.erb
# Short-Description: thin initscript
# Description: thin
### END INIT INFO
-@@ -15,20 +15,28 @@
+@@ -15,23 +15,80 @@
DAEMON=<%= Command.script %>
SCRIPT_NAME=<%= INITD_PATH %>
-CONFIG_PATH=<%= config_files_path %>
++
++. /lib/lsb/init-functions
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
@@ -31,6 +33,23 @@ Index: ruby-thin/lib/thin/controllers/service.sh.erb
+ <% end %>
+}
+
++parse_config() {
++ # Thin configuration files are expressed as flat YAML; implement a very
++ # simplistic parser, good enough for our limited purposes.
++ #
++ # This parser interprets each YAML declaration used in this script
++ # in the current shell environment; of course, it should be used
++ # with care, as a crafted expression could lead to arbitrary code
++ # execution. Some care is taken to sanitize it.
++ CONFIG=$1
++ if [ ! -f $CONFIG -o ! -r $CONFIG ]; then
++ echo "Thin configuration file $CONFIG not readable"
++ exit 3
++ fi
++ `ruby -ne 'next unless /^(port|servers|address|tag)\s*:\s*([\.\-\_\d\w]+)$/ ;puts "export %s=%s" % [$1,$2]' $CONFIG`
++}
++
++
case "$1" in
start)
- $DAEMON start --all $CONFIG_PATH
@@ -45,5 +64,39 @@ Index: ruby-thin/lib/thin/controllers/service.sh.erb
+ restart|force-reload|reload)
+ run_action restart
;;
++ status)
++ FAILED=0
++ TESTED=0
++ ACTIVE=$(ps axf | grep 'thin server')
++ for FILE in $CONFIG_PATH/*.yml
++ do
++ parse_config $FILE
++ MINPORT=$port
++ MAXPORT=$(($MINPORT + $servers - 1))
++ for PORT in $(seq $MINPORT $MAXPORT); do
++ TESTED=$(($TESTED + 1))
++ if echo $ACTIVE | grep -q "($address:$PORT)"; then
++ true
++ else
++ if [ ! -z "$tag" ]; then
++ MSG="for service tagged '$tag'"
++ fi
++ log_warning_msg "Thin server $MSG (port $PORT) not running"
++ FAILED=$(($FAILED + 1))
++ fi
++ done
++ done
++ if [ $FAILED = 0 ]; then
++ log_success_msg "All thin servers are running"
++ exit 0
++ else
++ log_failure_msg "$FAILED thin servers out of $TESTED are not running"
++ exit 3
++ fi
++ ;;
*)
- echo "Usage: $SCRIPT_NAME {start|stop|restart}" >&2
+- echo "Usage: $SCRIPT_NAME {start|stop|restart}" >&2
++ echo "Usage: $SCRIPT_NAME {start|stop|status|restart}" >&2
+ exit 3
+ ;;
+ esac
--
1.8.4.rc3
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment