summaryrefslogtreecommitdiffstats
path: root/src/init-radosgw
blob: 768d27bdb8b858041ea07699d14e7c6189846691 (plain)
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
#! /bin/sh
### BEGIN INIT INFO
# Provides:          radosgw
# Required-Start:    $remote_fs $named $network $time
# Required-Stop:     $remote_fs $named $network $time
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: radosgw RESTful rados gateway
# Description: radosgw RESTful rados gateway
### END INIT INFO

PATH=/sbin:/bin:/usr/bin

if [ -x /sbin/start-stop-daemon ]; then
    DEBIAN=1
    . /lib/lsb/init-functions
else
    . /etc/rc.d/init.d/functions
    DEBIAN=0
fi

daemon_is_running() {
    daemon=$1
    if pidof $daemon >/dev/null; then
        echo "$daemon is running."
        exit 0
    else
        echo "$daemon is not running."
        exit 1
    fi
}

VERBOSE=0
for opt in $*; do
    if [ "$opt" = "-v" ] || [ "$opt" = "--verbose" ]; then
       VERBOSE=1
    fi
done

# prefix for radosgw instances in ceph.conf
PREFIX='client.radosgw.'

# user to run radosgw as (if not specified in ceph.conf)
DEFAULT_USER='root'

RADOSGW=`which radosgw`
if [ ! -x "$RADOSGW" ]; then
    [ $VERBOSE -eq 1 ] && echo "$RADOSGW could not start, it is not executable."
    exit 1
fi

# list daemons, old-style and new-style
# NOTE: no support for cluster names that aren't "ceph"
dlist=`ceph-conf --list-sections $PREFIX`
if [ -d "/var/lib/ceph/radosgw" ]; then
    for d in `ls /var/lib/ceph/radosgw | grep ^ceph-`; do
	if [ -e "/var/lib/ceph/radosgw/$d/sysvinit" ]; then
	    id=`echo $d | cut -c 6-`
	    dlist="client.$id $dlist"
	fi
    done
fi

case "$1" in
    start)
        for name in $dlist
        do
            auto_start=`ceph-conf -n $name 'auto start'`
            if [ "$auto_start" = "no" ] || [ "$auto_start" = "false" ] || [ "$auto_start" = "0" ]; then
                continue
            fi

	    shortname=`echo $name | cut -c 8-`
	    if [ ! -e "/var/lib/ceph/radosgw/ceph-$shortname/sysvinit" ]; then
                # mapped to this host?
		host=`ceph-conf -n $name host`
		hostname=`hostname -s`
		if [ "$host" != "$hostname" ]; then
                    [ $VERBOSE -eq 1 ] && echo "hostname $hostname could not be found in ceph.conf:[$name], not starting."
                    continue
		fi
	    fi

            user=`ceph-conf -n $name user`
            if [ -z "$user" ]; then
                user="$DEFAULT_USER"
            fi

            log_file=`ceph-conf -n $name --show-config-value log_file`
            if [ -n "$log_file" ]; then
                if [ ! -e "$log_file" ]; then
                    touch "$log_file"
                fi
                chown $user $log_file
            fi

            echo "Starting $name..."
            if [ $DEBIAN -eq 1 ]; then
                start-stop-daemon --start -u $user -x $RADOSGW -p /var/run/ceph/client-$name.pid -- -n $name
            else
                ulimit -n 32768
                core_limit=`ceph-conf -n $name 'core file limit'`
                if [ -z $core_limit ]; then
                    DAEMON_COREFILE_LIMIT=$core_limit
                fi
                daemon --user="$user" "$RADOSGW -n $name"
            fi
        done
        ;;
    reload)
        echo "Reloading $name..."
	if [ $DEBIAN -eq 1 ]; then
            start-stop-daemon --stop --signal HUP -x $RADOSGW --oknodo
	else
            killproc $RADOSGW -HUP
	fi
	;;
    restart|force-reload)
        $0 stop
        $0 start
        ;;
    stop)
        timeout=0
        for name in $dlist
        do
          t=`ceph-conf -n $name --show-config-value rgw_exit_timeout_secs`
          if [ $t -gt $timeout ]; then timeout=$t; fi
        done

	if [ $DEBIAN -eq 1 ]; then
            if [ $timeout -gt 0 ]; then TIMEOUT="-R $timeout"; fi
            start-stop-daemon --stop -x $RADOSGW --oknodo $TIMEOUT
	else
	    killproc $RADOSGW
	    while pidof $RADOSGW >/dev/null && [ $timeout -gt 0 ] ; do
		sleep 1
		timeout=$(($timeout - 1))
            done
	fi
        ;;
    status)
        daemon_is_running $RADOSGW
        ;;
    *)
        echo "Usage: $0 {start|stop|restart|force-reload|reload|status} [-v|--verbose]" >&2
        exit 3
        ;;
esac