commit f18e8c7b73cbb79e61b60fa26a9da3e66c84414d
Author: Marcin Krol <h...@tld-linux.org>
Date:   Mon Apr 1 13:36:50 2024 +0200

    - allow running multiple daemons with separate config files
      (based on openvpn.spec)

 rsync.init       | 125 +++++++++++++++++++++++++++++++++++++++++++------------
 rsync.spec       |   3 +-
 rsync.sysconfig  |   4 ++
 rsyncd.logrotate |   2 +-
 4 files changed, 106 insertions(+), 28 deletions(-)
---
diff --git a/rsync.spec b/rsync.spec
index 8023f15..573f42b 100644
--- a/rsync.spec
+++ b/rsync.spec
@@ -198,7 +198,7 @@ cp -f /usr/share/automake/config.sub .
 
 %install
 rm -rf $RPM_BUILD_ROOT
-install -d 
$RPM_BUILD_ROOT{%{_sysconfdir},/etc/{sysconfig/rc-inetd,rc.d/init.d,logrotate.d,env.d},/var/log}
+install -d 
$RPM_BUILD_ROOT{%{_sysconfdir},/etc/{sysconfig/rc-inetd,rc.d/init.d,logrotate.d,env.d},/var/{log,run/rsyncd}}
 
 %{__make} install \
        prefix=$RPM_BUILD_ROOT%{_prefix} \
@@ -288,4 +288,5 @@ fi
 %attr(640,root,root) %config(noreplace) %verify(not md5 mtime size) 
/etc/logrotate.d/rsyncd
 %attr(640,root,root) %ghost /var/log/rsyncd.log
 %attr(754,root,root) /etc/rc.d/init.d/rsyncd
+%dir /var/run/rsyncd
 %{_mandir}/man5/rsyncd.conf.5*
diff --git a/rsync.init b/rsync.init
index 6f0ba5e..86f46e4 100644
--- a/rsync.init
+++ b/rsync.init
@@ -6,9 +6,22 @@
 # description: rsync daemon
 # processname: rsync
 #
-# pidfile:     /var/run/rsyncd.pid
 
-# Source function library.
+# Get service config
+[ -f /etc/sysconfig/rsyncd ] && . /etc/sysconfig/rsyncd
+
+[ -n "$2" ] && DAEMONS="$2"
+
+# no daemons. exit silently
+if [ -z "$DAEMONS" ]; then
+       case "$1" in
+       start|stop|restart|reload|force-reload)
+               exit 0
+               ;;
+       esac
+fi
+
+# Source function library
 . /etc/rc.d/init.d/functions
 
 # Source networking configuration.
@@ -24,30 +37,66 @@ else
        exit 0
 fi
 
-# Get service configuration
-[ -f /etc/sysconfig/rsyncd ] && . /etc/sysconfig/rsyncd
+# check if the daemon $1 is up
+daemonup() {
+       local daemon="$1"
+       local pidfile=/var/run/rsyncd/$daemon.pid
+       local pid=$(cat $pidfile 2>/dev/null)
+       kill -0 $pid 2>/dev/null
+       return $?
+}
+
+# check if all the configured daemons are up
+daemonsup() {
+        local daemon
+        ret=0
+        for daemon in $DAEMONS; do
+                daemonup $daemon && continue
+                ret=1
+        done
+        return $ret
+}
 
 start() {
-       # Start daemons.
-       if [ ! -f /var/lock/subsys/rsyncd ]; then
-               msg_starting rsyncd
-               daemon /usr/bin/rsync --daemon 
--dparam=pidfile=/var/run/rsync.pid ${RSYNC_OPTIONS}
-               RETVAL=$?
-               [ $RETVAL -eq 0 ] && touch /var/lock/subsys/rsyncd
-       else
-               msg_already_running rsyncd
-       fi
+       msg_starting "rsyncd"; started
+       for daemon in $DAEMONS; do
+               config="/etc/rsyncd/$daemon.conf"
+               if [ ! -f "$config" ]; then
+                       nls "Invalid daemon \`%s': missing config: %s" $daemon 
"$config"
+                       fail
+                       RET=1
+               else
+                       daemonup $daemon && continue
+                       show "Starting Rsync daemon %s" "$daemon"; busy
+                       daemon /usr/bin/rsync --daemon --config=$config 
--dparam=pidfile=/var/run/rsyncd/$daemon.pid ${RSYNC_OPTIONS}
+                       RET=$?
+               fi
+               [ $RETVAL -eq 0 ] && RETVAL=$RET
+       done
+       [ $RETVAL -eq 0 ] && touch /var/lock/subsys/rsyncd
 }
 
 stop() {
-       # Stop daemons.
-       if [ -f /var/lock/subsys/rsyncd ]; then
-               msg_stopping rsyncd
-               killproc rsync
-               rm -f /var/lock/subsys/rsyncd >/dev/null 2>&1
-       else
-               msg_not_running rsyncd
-       fi
+       msg_stopping "rsyncd"; started
+       for daemon in $DAEMONS; do
+               pidfile=/var/run/rsyncd/$daemon.pid
+               [ -f "$pidfile" ] || continue
+               pid=`cat "$pidfile"`
+               show "Stopping Rsync daemon %s" "$daemon"; busy
+               killproc --pidfile rsyncd/$daemon.pid || err=1
+       done
+       rm -f /var/lock/subsys/rsyncd >/dev/null 2>&1
+}
+
+reload() {
+       msg_reloading "rsyncd"; started
+       for daemon in $DAEMONS; do
+               pidfile=/var/run/rsyncd/$daemon.pid
+               [ -f "$pidfile" ] || continue
+               show "Reloading Rsync daemon %s" "$daemon"
+               killproc --pidfile rsyncd/$daemon.pid rsyncd -HUP
+               [ $? -ne 0 -a $RETVAL -eq 0 ] && RETVAL=7
+       done
 }
 
 condrestart() {
@@ -60,17 +109,41 @@ condrestart() {
        fi
 }
 
+status() {
+       nls "Configured daemons:"
+       echo " $DAEMONS"
+       nls "Currently active daemons:"
+       for pidfile in /var/run/rsyncd/*.pid; do
+               [ -f "$pidfile" ] || continue
+               daemon=${pidfile#/var/run/rsyncd/}
+               daemon=${daemon%.pid}
+               daemonup $daemon && echo -n " $daemon($(cat $pidfile))"
+       done
+       echo ""
+       nm_rsyncd_pid=$(ps -o pid= -C nm-rsyncd-service | xargs)
+       if [ "$nm_rsyncd_pid" ]; then
+               nls "NM ($nm_rsyncd_pid) managed rsyncd sessions"
+               ps -o pid,user,command --ppid=$nm_rsyncd_pid
+       fi
+       daemonsup
+       RETVAL=$?
+}
+
 RETVAL=0
 # See how we were called.
 case "$1" in
   start)
-       start
+       start
        ;;
   stop)
-       stop
+       stop
+       ;;
+  reload)
+       reload
        ;;
   restart)
        stop
+       sleep 1
        start
        ;;
   try-restart)
@@ -80,12 +153,12 @@ case "$1" in
        condrestart 7
        ;;
   status)
-       status rsyncd rsync
-       exit $?
+       status
        ;;
   *)
-       msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}"
+       msg_usage "$0 
{start|stop|restart|try-restart|reload|force-reload|status}"
        exit 3
+       ;;
 esac
 
 exit $RETVAL
diff --git a/rsync.sysconfig b/rsync.sysconfig
index b0420e9..30b50c9 100644
--- a/rsync.sysconfig
+++ b/rsync.sysconfig
@@ -8,3 +8,7 @@ SERVICE_RUN_NICE_LEVEL="+5"
 # -4   - use only IPv4 address
 # -6   - use only IPv6 address
 #RSYNC_OPTIONS="-4"
+
+# Daemons to set up
+# For each daemon name, there should be config file in /etc/rsyncd
+DAEMONS="rsyncd"
diff --git a/rsyncd.logrotate b/rsyncd.logrotate
index de382b1..a936045 100644
--- a/rsyncd.logrotate
+++ b/rsyncd.logrotate
@@ -1,4 +1,4 @@
-/var/log/rsyncd.log {
+/var/log/rsyncd*.log {
        create 640 root logs
        delaycompress
 }
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/rsync.git/commitdiff/f18e8c7b73cbb79e61b60fa26a9da3e66c84414d

_______________________________________________
pld-cvs-commit mailing list
pld-cvs-commit@lists.pld-linux.org
http://lists.pld-linux.org/mailman/listinfo/pld-cvs-commit

Reply via email to