]> git.pld-linux.org Git - packages/rsync.git/blob - rsync.init
- versioned Obsoletes for replaced rsyncd package
[packages/rsync.git] / rsync.init
1 #!/bin/sh
2 #
3 # rsyncd        This shell script takes care of starting and stopping rsyncd
4 #
5 # chkconfig:    345 90 25
6 # description:  rsync daemon
7 # processname:  rsync
8 #
9
10 # Get service config
11 [ -f /etc/sysconfig/rsyncd ] && . /etc/sysconfig/rsyncd
12
13 [ -n "$2" ] && DAEMONS="$2"
14
15 # no daemons. exit silently
16 if [ -z "$DAEMONS" ]; then
17         case "$1" in
18         start|stop|restart|reload|force-reload)
19                 exit 0
20                 ;;
21         esac
22 fi
23
24 # Source function library
25 . /etc/rc.d/init.d/functions
26
27 # Source networking configuration.
28 . /etc/sysconfig/network
29
30 # Check that networking is up.
31 if is_yes "${NETWORKING}"; then
32         if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
33                 msg_network_down rsyncd
34                 exit 1
35         fi
36 else
37         exit 0
38 fi
39
40 # check if the daemon $1 is up
41 daemonup() {
42         local daemon="$1"
43         local pidfile=/var/run/rsyncd/$daemon.pid
44         local pid=$(cat $pidfile 2>/dev/null)
45         kill -0 $pid 2>/dev/null
46         return $?
47 }
48
49 # check if all the configured daemons are up
50 daemonsup() {
51         local daemon
52         ret=0
53         for daemon in $DAEMONS; do
54                 daemonup $daemon && continue
55                 ret=1
56         done
57         return $ret
58 }
59
60 start() {
61         msg_starting "rsyncd"; started
62         for daemon in $DAEMONS; do
63                 config="/etc/rsyncd/$daemon.conf"
64                 if [ ! -f "$config" ]; then
65                         nls "Invalid daemon \`%s': missing config: %s" $daemon "$config"
66                         fail
67                         RET=1
68                 else
69                         daemonup $daemon && continue
70                         show "Starting Rsync daemon %s" "$daemon"; busy
71                         daemon /usr/bin/rsync --daemon --config=$config --dparam=pidfile=/var/run/rsyncd/$daemon.pid ${RSYNC_OPTIONS}
72                         RET=$?
73                 fi
74                 [ $RETVAL -eq 0 ] && RETVAL=$RET
75         done
76         [ $RETVAL -eq 0 ] && touch /var/lock/subsys/rsyncd
77 }
78
79 stop() {
80         msg_stopping "rsyncd"; started
81         for daemon in $DAEMONS; do
82                 pidfile=/var/run/rsyncd/$daemon.pid
83                 [ -f "$pidfile" ] || continue
84                 pid=`cat "$pidfile"`
85                 show "Stopping Rsync daemon %s" "$daemon"; busy
86                 killproc --pidfile rsyncd/$daemon.pid || err=1
87         done
88         rm -f /var/lock/subsys/rsyncd >/dev/null 2>&1
89 }
90
91 reload() {
92         msg_reloading "rsyncd"; started
93         for daemon in $DAEMONS; do
94                 pidfile=/var/run/rsyncd/$daemon.pid
95                 [ -f "$pidfile" ] || continue
96                 show "Reloading Rsync daemon %s" "$daemon"
97                 killproc --pidfile rsyncd/$daemon.pid rsyncd -HUP
98                 [ $? -ne 0 -a $RETVAL -eq 0 ] && RETVAL=7
99         done
100 }
101
102 condrestart() {
103         if [ -f /var/lock/subsys/rsyncd ]; then
104                 stop
105                 start
106         else
107                 msg_not_running rsyncd
108                 RETVAL=$1
109         fi
110 }
111
112 status() {
113         nls "Configured daemons:"
114         echo " $DAEMONS"
115         nls "Currently active daemons:"
116         for pidfile in /var/run/rsyncd/*.pid; do
117                 [ -f "$pidfile" ] || continue
118                 daemon=${pidfile#/var/run/rsyncd/}
119                 daemon=${daemon%.pid}
120                 daemonup $daemon && echo -n " $daemon($(cat $pidfile))"
121         done
122         echo ""
123         nm_rsyncd_pid=$(ps -o pid= -C nm-rsyncd-service | xargs)
124         if [ "$nm_rsyncd_pid" ]; then
125                 nls "NM ($nm_rsyncd_pid) managed rsyncd sessions"
126                 ps -o pid,user,command --ppid=$nm_rsyncd_pid
127         fi
128         daemonsup
129         RETVAL=$?
130 }
131
132 RETVAL=0
133 # See how we were called.
134 case "$1" in
135   start)
136         start
137         ;;
138   stop)
139         stop
140         ;;
141   reload)
142         reload
143         ;;
144   restart)
145         stop
146         sleep 1
147         start
148         ;;
149   try-restart)
150         condrestart 0
151         ;;
152   force-reload)
153         condrestart 7
154         ;;
155   status)
156         status
157         ;;
158   *)
159         msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|status}"
160         exit 3
161         ;;
162 esac
163
164 exit $RETVAL
This page took 0.069357 seconds and 4 git commands to generate.