]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | #! /bin/sh |
2 | ### BEGIN INIT INFO | |
3 | # Provides: radosgw | |
4 | # Required-Start: $remote_fs $named $network $time | |
5 | # Required-Stop: $remote_fs $named $network $time | |
6 | # Default-Start: 2 3 4 5 | |
7 | # Default-Stop: 0 1 6 | |
8 | # Short-Description: radosgw RESTful rados gateway | |
9 | # Description: radosgw RESTful rados gateway | |
10 | ### END INIT INFO | |
11 | ||
12 | PATH=/sbin:/bin:/usr/bin | |
13 | ||
14 | if [ -x /sbin/start-stop-daemon ]; then | |
15 | DEBIAN=1 | |
16 | . /lib/lsb/init-functions | |
17 | else | |
18 | . /etc/rc.d/init.d/functions | |
19 | DEBIAN=0 | |
20 | fi | |
21 | ||
22 | daemon_is_running() { | |
23 | daemon=$1 | |
24 | if pidof $daemon >/dev/null; then | |
25 | echo "$daemon is running." | |
26 | exit 0 | |
27 | else | |
28 | echo "$daemon is not running." | |
29 | exit 1 | |
30 | fi | |
31 | } | |
32 | ||
33 | VERBOSE=0 | |
34 | for opt in $*; do | |
35 | if [ "$opt" = "-v" ] || [ "$opt" = "--verbose" ]; then | |
36 | VERBOSE=1 | |
37 | fi | |
38 | done | |
39 | ||
40 | # prefix for radosgw instances in ceph.conf | |
41 | PREFIX='client.radosgw.' | |
42 | ||
43 | # user to run radosgw as (if not specified in ceph.conf) | |
44 | DEFAULT_USER='root' | |
45 | ||
46 | RADOSGW=`which radosgw` | |
47 | if [ ! -x "$RADOSGW" ]; then | |
48 | [ $VERBOSE -eq 1 ] && echo "$RADOSGW could not start, it is not executable." | |
49 | exit 1 | |
50 | fi | |
51 | ||
52 | # list daemons, old-style and new-style | |
53 | # NOTE: no support for cluster names that aren't "ceph" | |
54 | dlist=`ceph-conf --list-sections $PREFIX` | |
55 | if [ -d "/var/lib/ceph/radosgw" ]; then | |
56 | for d in `ls /var/lib/ceph/radosgw | grep ^ceph-`; do | |
57 | if [ -e "/var/lib/ceph/radosgw/$d/sysvinit" ]; then | |
58 | id=`echo $d | cut -c 6-` | |
59 | dlist="client.$id $dlist" | |
60 | fi | |
61 | done | |
62 | fi | |
63 | ||
64 | case "$1" in | |
65 | start) | |
66 | for name in $dlist | |
67 | do | |
68 | auto_start=`ceph-conf -n $name 'auto start'` | |
69 | if [ "$auto_start" = "no" ] || [ "$auto_start" = "false" ] || [ "$auto_start" = "0" ]; then | |
70 | continue | |
71 | fi | |
72 | ||
73 | shortname=`echo $name | cut -c 8-` | |
74 | if [ ! -e "/var/lib/ceph/radosgw/ceph-$shortname/sysvinit" ]; then | |
75 | # mapped to this host? | |
76 | host=`ceph-conf -n $name host` | |
77 | hostname=`hostname -s` | |
78 | if [ "$host" != "$hostname" ]; then | |
79 | [ $VERBOSE -eq 1 ] && echo "hostname $hostname could not be found in ceph.conf:[$name], not starting." | |
80 | continue | |
81 | fi | |
82 | fi | |
83 | ||
84 | user=`ceph-conf -n $name user` | |
85 | if [ -z "$user" ]; then | |
86 | user="$DEFAULT_USER" | |
87 | fi | |
88 | ||
9f95a23c | 89 | log_file=`ceph-conf -n $name --show-config-value log_file` |
7c673cae FG |
90 | if [ -n "$log_file" ]; then |
91 | if [ ! -e "$log_file" ]; then | |
92 | touch "$log_file" | |
93 | fi | |
94 | chown $user $log_file | |
95 | fi | |
96 | ||
97 | echo "Starting $name..." | |
98 | if [ $DEBIAN -eq 1 ]; then | |
99 | start-stop-daemon --start -u $user -x $RADOSGW -p /var/run/ceph/client-$name.pid -- -n $name | |
100 | else | |
101 | ulimit -n 32768 | |
102 | core_limit=`ceph-conf -n $name 'core file limit'` | |
103 | if [ -z $core_limit ]; then | |
104 | DAEMON_COREFILE_LIMIT=$core_limit | |
105 | fi | |
106 | daemon --user="$user" "$RADOSGW -n $name" | |
107 | fi | |
108 | done | |
109 | ;; | |
110 | reload) | |
111 | echo "Reloading $name..." | |
112 | if [ $DEBIAN -eq 1 ]; then | |
113 | start-stop-daemon --stop --signal HUP -x $RADOSGW --oknodo | |
114 | else | |
115 | killproc $RADOSGW -HUP | |
116 | fi | |
117 | ;; | |
118 | restart|force-reload) | |
119 | $0 stop | |
120 | $0 start | |
121 | ;; | |
122 | stop) | |
123 | timeout=0 | |
124 | for name in $dlist | |
125 | do | |
9f95a23c | 126 | t=`ceph-conf -n $name --show-config-value rgw_exit_timeout_secs` |
7c673cae FG |
127 | if [ $t -gt $timeout ]; then timeout=$t; fi |
128 | done | |
129 | ||
130 | if [ $DEBIAN -eq 1 ]; then | |
131 | if [ $timeout -gt 0 ]; then TIMEOUT="-R $timeout"; fi | |
132 | start-stop-daemon --stop -x $RADOSGW --oknodo $TIMEOUT | |
133 | else | |
134 | killproc $RADOSGW | |
135 | while pidof $RADOSGW >/dev/null && [ $timeout -gt 0 ] ; do | |
136 | sleep 1 | |
137 | timeout=$(($timeout - 1)) | |
138 | done | |
139 | fi | |
140 | ;; | |
141 | status) | |
142 | daemon_is_running $RADOSGW | |
143 | ;; | |
144 | *) | |
145 | echo "Usage: $0 {start|stop|restart|force-reload|reload|status} [-v|--verbose]" >&2 | |
146 | exit 3 | |
147 | ;; | |
148 | esac | |
149 |