Repository navigation
Expand file tree
/
Copy pathrsync.init
More file actions
164 lines (149 loc) · 3.19 KB
/
Copy pathrsync.init
File metadata and controls
164 lines (149 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/sh
#
# rsyncd This shell script takes care of starting and stopping rsyncd
#
# chkconfig: 345 90 25
# description: rsync daemon
# processname: rsync
#
# 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.
. /etc/sysconfig/network
# Check that networking is up.
if is_yes "${NETWORKING}"; then
if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
msg_network_down rsyncd
exit 1
fi
else
exit 0
fi
# 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() {
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() {
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() {
if [ -f /var/lock/subsys/rsyncd ]; then
stop
start
else
msg_not_running rsyncd
RETVAL=$1
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
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
sleep 1
start
;;
try-restart)
condrestart 0
;;
force-reload)
condrestart 7
;;
status)
status
;;
*)
msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|status}"
exit 3
;;
esac
exit $RETVAL