Package: sobby
Version: 0.4.1-1

Tags: patch

Here is a patch for seting up sobby as a daemon. It is composed of:
- an init script
- a default file (to enable/disable launch at startup)
- a default configuration file

Lionel

diff -pruN sobby-0.4.1/debian/control sobby-0.4.1.new/debian/control
--- sobby-0.4.1/debian/control	2006-12-27 19:26:24.000000000 +0100
+++ sobby-0.4.1.new/debian/control	2006-12-27 19:03:59.000000000 +0100
@@ -7,7 +7,7 @@ Standards-Version: 3.7.2
 
 Package: sobby
 Architecture: any
-Depends: ${shlibs:Depends}, ${misc:Depends}
+Depends: ${shlibs:Depends}, ${misc:Depends}, adduser
 Description: a dedicated server for collaborative editing
  Sobby is a dedicated server which allows clients to edit plain text
  documents and source files collaboratively over a network. Changes
diff -pruN sobby-0.4.1/debian/defaults sobby-0.4.1.new/debian/defaults
--- sobby-0.4.1/debian/defaults	1970-01-01 01:00:00.000000000 +0100
+++ sobby-0.4.1.new/debian/defaults	2007-01-07 11:25:40.000000000 +0100
@@ -0,0 +1,3 @@
+# start sobby at startup
+# default is no
+RUNSOBBY=no
diff -pruN sobby-0.4.1/debian/dirs sobby-0.4.1.new/debian/dirs
--- sobby-0.4.1/debian/dirs	2006-12-27 19:26:24.000000000 +0100
+++ sobby-0.4.1.new/debian/dirs	2006-12-27 21:07:41.000000000 +0100
@@ -1 +1 @@
-usr/bin
+usr/sbin
diff -pruN sobby-0.4.1/debian/init sobby-0.4.1.new/debian/init
--- sobby-0.4.1/debian/init	1970-01-01 01:00:00.000000000 +0100
+++ sobby-0.4.1.new/debian/init	2007-01-07 11:25:35.000000000 +0100
@@ -0,0 +1,115 @@
+#! /bin/sh
+# Author: Lionel Porcheron <[EMAIL PROTECTED]>
+
+# PATH should only include /usr/* if it runs after the mountnfs.sh script
+PATH=/usr/sbin:/usr/bin:/sbin:/bin
+DESC="Sobby Daemon"
+NAME=sobby
+DAEMON=/usr/sbin/$NAME
+SESSION_FILE=`grep autosave_file /etc/sobby.conf  | cut -f2 -d'>' | cut -f1 -d'<'`
+DAEMON_ARGS="-c /etc/sobby.conf $SESSION_FILE"
+PIDFILE=/var/run/$NAME.pid
+SCRIPTNAME=/etc/init.d/$NAME
+USER="sobby"
+
+# Read config file if it is present.
+if [ -r /etc/default/$NAME ]
+then
+       . /etc/default/$NAME
+fi
+
+# Exit if the package is not installed
+[ -x "$DAEMON" ] || exit 0
+
+# sobby is disabled
+[ "$RUNSOBBY" == "yes" ] || exit 0
+
+#
+# Function that starts the daemon/service
+#
+do_start()
+{
+	# Return
+	#   0 if daemon has been started
+	#   1 if daemon was already running
+	#   2 if daemon could not be started
+	start-stop-daemon --start --quiet --background --make-pidfile --pidfile $PIDFILE --chuid $USER --exec $DAEMON --test > /dev/null \
+		|| return 1
+	start-stop-daemon --start --quiet --background --make-pidfile --pidfile $PIDFILE --chuid $USER --exec $DAEMON -- \
+		$DAEMON_ARGS \
+		|| return 2
+}
+
+#
+# Function that stops the daemon/service
+#
+do_stop()
+{
+	# Return
+	#   0 if daemon has been stopped
+	#   1 if daemon was already stopped
+	#   2 if daemon could not be stopped
+	#   other if a failure occurred
+	start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
+	RETVAL="$?"
+	[ "$RETVAL" = 2 ] && return 2
+	start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
+	[ "$?" = 2 ] && return 2
+	rm -f $PIDFILE
+	return "$RETVAL"
+}
+
+#
+# Function that sends a SIGHUP to the daemon/service
+#
+do_reload() {
+	start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
+	return 0
+}
+
+case "$1" in
+  start)
+	[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC"
+	do_start
+	case "$?" in
+		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+	esac
+	;;
+  stop)
+	[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC"
+	do_stop
+	case "$?" in
+		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+	esac
+	;;
+  restart|force-reload)
+	#
+	# If the "reload" option is implemented then remove the
+	# 'force-reload' alias
+	#
+	log_daemon_msg "Restarting $DESC"
+	do_stop
+	case "$?" in
+	  0|1)
+		do_start
+		case "$?" in
+			0) log_end_msg 0 ;;
+			1) log_end_msg 1 ;; # Old process is still running
+			*) log_end_msg 1 ;; # Failed to start
+		esac
+		;;
+	  *)
+	  	# Failed to stop
+		log_end_msg 1
+		;;
+	esac
+	;;
+  *)
+	echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
+	exit 3
+	;;
+esac
+
+:
diff -pruN sobby-0.4.1/debian/install sobby-0.4.1.new/debian/install
--- sobby-0.4.1/debian/install	1970-01-01 01:00:00.000000000 +0100
+++ sobby-0.4.1.new/debian/install	2006-12-27 18:21:02.000000000 +0100
@@ -0,0 +1 @@
+debian/sobby.conf etc/
diff -pruN sobby-0.4.1/debian/postinst sobby-0.4.1.new/debian/postinst
--- sobby-0.4.1/debian/postinst	1970-01-01 01:00:00.000000000 +0100
+++ sobby-0.4.1.new/debian/postinst	2006-12-27 19:20:44.000000000 +0100
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+set -e
+
+case "$1" in
+    configure)
+
+        if [ -z "`getent passwd sobby`" ];then
+                adduser --quiet --system --group --home /var/lib/sobby --gecos "Sobby daemon" sobby
+        fi
+
+        test -d /var/lib/sobby || mkdir -p /var/lib/sobby
+    ;;
+    abort-upgrade|abort-remove|abort-deconfigure)
+
+    ;;
+
+    *)
+        echo "postinst called with unknown argument \`$1'" >&2
+        exit 1
+    ;;
+esac
+
+# dh_installdeb will replace this with shell code automatically
+# generated by other debhelper scripts.
+
+#DEBHELPER#
+
+exit 0
+
diff -pruN sobby-0.4.1/debian/postrm sobby-0.4.1.new/debian/postrm
--- sobby-0.4.1/debian/postrm	1970-01-01 01:00:00.000000000 +0100
+++ sobby-0.4.1.new/debian/postrm	2006-12-27 18:19:30.000000000 +0100
@@ -0,0 +1,9 @@
+#! /bin/sh -e
+
+if [ "$1" = purge ]; then
+        userdel -r sobby 2>/dev/null || true
+
+fi
+
+#DEBHELPER#
+
diff -pruN sobby-0.4.1/debian/rules sobby-0.4.1.new/debian/rules
--- sobby-0.4.1/debian/rules	2006-12-27 19:26:24.000000000 +0100
+++ sobby-0.4.1.new/debian/rules	2006-12-27 22:02:32.000000000 +0100
@@ -19,14 +19,12 @@ endif
 
 config.status: configure
 	dh_testdir
-ifneq "$(wildcard /usr/share/misc/config.sub)" ""
-	cp -f /usr/share/misc/config.sub config.sub
-endif
-ifneq "$(wildcard /usr/share/misc/config.guess)" ""
-	cp -f /usr/share/misc/config.guess config.guess
-endif
+	ln -sf /usr/share/misc/config.sub .
+	ln -sf /usr/share/misc/config.guess .
+
 	CFLAGS="$(CFLAGS)" ./configure --host=$(DEB_HOST_GNU_TYPE) \
 		--build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr \
+		--bindir=\$${prefix}/sbin \
 		--mandir=\$${prefix}/share/man \
 		--infodir=\$${prefix}/share/info \
 		--disable-zeroconf
@@ -44,13 +42,6 @@ clean:
 	rm -f build-stamp 
 
 	-$(MAKE) distclean
-ifneq "$(wildcard /usr/share/misc/config.sub)" ""
-	cp -f /usr/share/misc/config.sub config.sub
-endif
-ifneq "$(wildcard /usr/share/misc/config.guess)" ""
-	cp -f /usr/share/misc/config.guess config.guess
-endif
-
 
 	dh_clean 
 
@@ -62,6 +53,8 @@ install: build
 
 	$(MAKE) install DESTDIR=$(CURDIR)/debian/sobby
 
+	dh_install
+	dh_installinit
 
 # Build architecture-independent files here.
 binary-indep: build install
diff -pruN sobby-0.4.1/debian/sobby.conf sobby-0.4.1.new/debian/sobby.conf
--- sobby-0.4.1/debian/sobby.conf	1970-01-01 01:00:00.000000000 +0100
+++ sobby-0.4.1.new/debian/sobby.conf	2007-01-07 11:27:42.000000000 +0100
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<sobby_config>
+  <settings>
+    <autosave_file>/var/lib/sobby/sobby.sav</autosave_file>
+    <autosave_interval>60</autosave_interval>
+    <name>Standalone obby server</name>
+<!-- To enable password protection, uncomment line below -->
+<!--    <password>password</password> -->
+    <port>6522</port>
+  </settings>
+</sobby_config>

Reply via email to