[vhffs-dev] [1606] added Debian initscript for vhffsfssync, added --pidfile option to master and slave

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 1606
Author:   gradator
Date:     2010-05-12 02:10:38 +0200 (Wed, 12 May 2010)
Log Message:
-----------
added Debian initscript for vhffsfssync, added --pidfile option to master and slave

Modified Paths:
--------------
    trunk/debian/rules
    trunk/vhffs-fssync/vhffsfssync_master.c
    trunk/vhffs-fssync/vhffsfssync_slave.c

Added Paths:
-----------
    trunk/debian/vhffs-fssync.vhffs-fssync.default
    trunk/debian/vhffs-fssync.vhffs-fssync.init

Modified: trunk/debian/rules
===================================================================
--- trunk/debian/rules	2010-05-09 23:18:54 UTC (rev 1605)
+++ trunk/debian/rules	2010-05-12 00:10:38 UTC (rev 1606)
@@ -140,7 +140,7 @@
 #	dh_installpam
 #	dh_installmime
 #	dh_python
-#	dh_installinit
+	dh_installinit --name=vhffs-fssync --restart-after-upgrade
 	dh_installcron
 #	dh_installinfo
 	dh_installman

Added: trunk/debian/vhffs-fssync.vhffs-fssync.default
===================================================================
--- trunk/debian/vhffs-fssync.vhffs-fssync.default	                        (rev 0)
+++ trunk/debian/vhffs-fssync.vhffs-fssync.default	2010-05-12 00:10:38 UTC (rev 1606)
@@ -0,0 +1,12 @@
+#MASTER0_NAME="data"
+#MASTER0_ARGS="-p 4567 /data/web"
+
+#MASTER1_NAME ..
+#MASTER1_ARGS ..
+
+#SLAVE0_NAME="data"
+#SLAVE0_ARGS="-t 1800 -r 1000 -p --prevent-loop 10.20.30.40:4567 /data/web"
+
+#SLAVE1_NAME ..
+#SLAVE1_ARGS ..
+

Added: trunk/debian/vhffs-fssync.vhffs-fssync.init
===================================================================
--- trunk/debian/vhffs-fssync.vhffs-fssync.init	                        (rev 0)
+++ trunk/debian/vhffs-fssync.vhffs-fssync.init	2010-05-12 00:10:38 UTC (rev 1606)
@@ -0,0 +1,78 @@
+#!/bin/sh -e
+# vim:ts=4:sw=4:et:ai:sts=4:filetype=sh
+### BEGIN INIT INFO
+# Provides:          vhffs-fssync
+# Required-Start:    $remote_fs $syslog $network
+# Required-Stop:     $remote_fs $syslog $network
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: remote synchronous file-copying tool
+### END INIT INFO
+
+PATH=/bin:/usr/bin:/sbin:/usr/sbin
+DAEMON_MASTER=/usr/bin/vhffsfssync_master
+DAEMON_SLAVE=/usr/bin/vhffsfssync_slave
+NAME=vhffs-fssync
+DESC="remote synchronous file-copying tool"
+PIDPREFIX=/var/run/vhffs-fssync
+
+test -f $DAEMON_MASTER || exit 0
+test -f $DAEMON_SLAVE || exit 0
+
+. /lib/lsb/init-functions
+
+# Include defaults if available
+if [ -f /etc/default/$NAME ] ; then
+        . /etc/default/$NAME
+fi
+
+case "$1" in
+    start)
+        SOMETHING_STARTED=0
+        for i in 0 1 2 3 4 5 6 7 8 9; do
+            eval name=\$MASTER${i}_NAME
+            eval args=\$MASTER${i}_ARGS
+            if [ -n "$name" ] && [ -n "$args" ] ; then
+                log_daemon_msg "Starting $DESC master $name " "$NAME"
+                start-stop-daemon --start --startas $DAEMON_MASTER --oknodo \
+                    --pidfile $PIDPREFIX.master-$name.pid -- --pidfile $PIDPREFIX.master-$name.pid $args
+                log_end_msg $?
+                SOMETHING_STARTED=1
+            fi
+        done
+        for i in 0 1 2 3 4 5 6 7 8 9; do
+            eval name=\$SLAVE${i}_NAME
+            eval args=\$SLAVE${i}_ARGS
+            if [ -n "$name" ] && [ -n "$args" ] ; then
+                log_daemon_msg "Starting $DESC slave $name " "$NAME"
+                start-stop-daemon --start --startas $DAEMON_SLAVE --oknodo \
+                    --pidfile $PIDPREFIX.slave-$name.pid -- --pidfile $PIDPREFIX.slave-$name.pid $args
+                log_end_msg $?
+                SOMETHING_STARTED=1
+            fi
+        done
+        if [ "$SOMETHING_STARTED" -eq 0 ]; then
+            log_failure_msg "$NAME disabled, please adjust the configuration to your needs in /etc/default/$NAME to enable it."
+            exit 0
+        fi
+        ;;
+    stop)
+	for i in $PIDPREFIX*.pid; do
+		test -f "$i" || continue
+		log_daemon_msg "Stopping $DESC" "$NAME"
+		start-stop-daemon --oknodo --stop --pidfile $i
+		log_end_msg $?
+		rm -f $i
+	done
+        ;;
+    reload|force-reload|restart)
+        $0 stop
+        sleep 1;
+        $0 start
+        ;;
+    *)
+        echo "Usage: $0 {start|stop|restart|reload|force-reload}" >&2
+        exit 1
+        ;;
+esac
+exit 0

Modified: trunk/vhffs-fssync/vhffsfssync_master.c
===================================================================
--- trunk/vhffs-fssync/vhffsfssync_master.c	2010-05-09 23:18:54 UTC (rev 1605)
+++ trunk/vhffs-fssync/vhffsfssync_master.c	2010-05-12 00:10:38 UTC (rev 1606)
@@ -1647,6 +1647,7 @@
 		"  -f, --foreground\tDon't daemonise the server, display errors on the console\n"
 		"  -b, --bind=IP\t\tListen to the specified IP address\n"
 		"  -p, --port=PORT\tListen to this port\n"
+		"      --pidfile=PATH\tWrite the pid to that file\n"
 		"  -h, --help\t\tDisplay this help and exit\n"
 		"  -v, --version\t\tOutput version information and exit\n",
 		progname);
@@ -1666,11 +1667,13 @@
 	uint32_t bindaddr = INADDR_ANY;
 	uint16_t bindport = 4567;
 	char *root = NULL;
+	FILE *pidfile = NULL;
 
 	struct option long_options[] = {
 		{ "foreground", no_argument, NULL, 'f' },
 		{ "bind", required_argument, NULL, 'b' },
 		{ "port", required_argument, NULL, 'p' },
+		{ "pidfile", required_argument, NULL, 1000 },
 		{ "help", no_argument, NULL, 'h' },
 		{ "version", no_argument, NULL, 'v' },
 		{ 0, 0, 0, 0 }
@@ -1695,6 +1698,10 @@
 				bindport = atoi(optarg);
 				break;
 
+			case 1000:
+				pidfile = fopen(optarg, "w");
+				break;
+
 			case 'h':
 				usage_exit(0, argv[0]);
 
@@ -1728,6 +1735,14 @@
 		if(fork()) exit(0);
 	}
 
+	/* write the pidfile */
+	if(pidfile) {
+		char *tmp = g_strdup_printf("%d\n", getpid() );
+		fwrite(tmp, strlen(tmp), 1, pidfile);
+		free(tmp);
+		fclose(pidfile);
+	}
+
 	/* chdir() to the filesystem to monitor */
 	if(!root) return -1;
 	if( root[strlen(root)-1] == '/' ) root[strlen(root)-1] = '\0';

Modified: trunk/vhffs-fssync/vhffsfssync_slave.c
===================================================================
--- trunk/vhffs-fssync/vhffsfssync_slave.c	2010-05-09 23:18:54 UTC (rev 1605)
+++ trunk/vhffs-fssync/vhffsfssync_slave.c	2010-05-12 00:10:38 UTC (rev 1606)
@@ -962,6 +962,7 @@
 		"  -r, --limit-rate=kB/s\tLimit I/O bandwidth; kBytes per second\n"
 		"  -p, --preserve\tPreserve owners, groups and permissions\n"
 		"      --prevent-loop\tAbort if the host seen by the master is the host we are connecting to (loopback)\n"
+		"      --pidfile=PATH\tWrite the pid to that file\n"
 		"  -h, --help\t\tDisplay this help and exit\n"
 		"  -v, --version\t\tOutput version information and exit\n",
 		progname);
@@ -981,6 +982,7 @@
 	char *root = NULL;
 	int timeout = 3600;
 	int limitrate = 0;
+	FILE *pidfile = NULL;
 
 	vhffsfssync_preserve = 0;
 	vhffsfssync_preventloop = 0;
@@ -994,6 +996,7 @@
 		{ "limit-rate", required_argument, NULL, 'r' },
 		{ "preserve", no_argument, NULL, 'p' },
 		{ "prevent-loop", no_argument, NULL, 1000 },
+		{ "pidfile", required_argument, NULL, 1001 },
 		{ "help", no_argument, NULL, 'h' },
 		{ "version", no_argument, NULL, 'v' },
 		{ 0, 0, 0, 0 }
@@ -1026,6 +1029,10 @@
 				vhffsfssync_preventloop = 1;
 				break;
 
+			case 1001:
+				pidfile = fopen(optarg, "w");
+				break;
+
 			case 'h':
 				usage_exit(0, argv[0]);
 
@@ -1068,6 +1075,14 @@
 		if(fork()) exit(0);
 	}
 
+	/* write the pidfile */
+	if(pidfile) {
+		char *tmp = g_strdup_printf("%d\n", getpid() );
+		fwrite(tmp, strlen(tmp), 1, pidfile);
+		free(tmp);
+		fclose(pidfile);
+	}
+
 	// so that open() and mkdir() will not enforce wanted mode with mode&~umask
 	umask(0);
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/