Package: thin
Version: 1.3.1-3
Severity: normal
Tags: patch

I added a 'status' target to the initscript, which gives useful
information (i.e. which Thin servers went down if any). I decided to
implement it against the output of netstat and not against the running
processes as I have at least found one case where an instance was
running but somehow not listening to the right socket — But I know
this might be polemic/dirty.

Read: I'm not uploading this yet, please comment!

-- System Information:
Debian Release: jessie/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: amd64 (x86_64)

Kernel: Linux 3.11-1-amd64 (SMP w/4 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages thin depends on:
ii  libc6                         2.17-93
ii  libruby1.8                    1.8.7.358-8
ii  libruby1.9.1                  1.9.3.448-1
ii  ruby                          1:1.9.3
ii  ruby-daemons                  1.1.5-2
ii  ruby-eventmachine             1.0.3-3
ii  ruby-rack                     1.5.2-1
ii  ruby1.8 [ruby-interpreter]    1.8.7.358-8
ii  ruby1.9.1 [ruby-interpreter]  1.9.3.448-1
ii  ruby2.0 [ruby-interpreter]    2.0.0.299-2

thin recommends no packages.

thin suggests no packages.

-- debconf-show failed
>From 984ff8a1a01e01d3510733388338bc6d409b1fba Mon Sep 17 00:00:00 2001
From: Gunnar Wolf <gw...@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 <gw...@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

Reply via email to