summaryrefslogtreecommitdiff
path: root/src/init-radosgw.sysv
blob: 017e3f9bc07a394b64f80de1f77bf0f0128f790c (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
#! /bin/bash
### 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
### END INIT INFO

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

#. /lib/lsb/init-functions
. /etc/rc.d/init.d/functions

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

# user to run radosgw as (it not specified in ceph.conf)
#DEFAULT_USER='www-data'
DEFAULT_USER='apache'

# directory to write logs to
LOGDIR='/var/log/radosgw'

RADOSGW=`which radosgw`
if [ ! -x "$RADOSGW" ]; then
    exit 0
fi

# make sure log dir exists
if [ ! -d "$LOGDIR" ]; then
    mkdir -p $LOGDIR
fi

case "$1" in
    start)
        echo "Starting radosgw instance(s)..."
        for name in `ceph-conf --list-sections $PREFIX`;
        do
            auto_start=`ceph-conf -n $name 'auto start'`
            if [ "$auto_start" = "no" ] || [ "$auto_start" = "false" ] || [ "$auto_start" = "0" ]; then
                continue
            fi

            # is the socket defined?  if it's not, this instance shouldn't run as a daemon.
            rgw_socket=`$RADOSGW -n $name --show-config-value rgw_socket_path`
            if [ -z "$rgw_socket" ]; then
                continue
            fi

            # mapped to this host?
            host=`ceph-conf -n $name host`
            if [ "$host" != `hostname` ]; then
                continue
            fi

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

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

            #start-stop-daemon --start -u $user -x $RADOSGW -- -n $name
            daemon --user="$user" "$RADOSGW -n $name"
            echo "Starting $name..."
        done
        ;;
    reload)
        #start-stop-daemon --signal HUP -x $RADOSGW --oknodo
        killproc $RADOSGW -SIGHUP
        echo "Reloading radosgw instance(s)..."
        ;;
    restart|force-reload)
        $0 stop
        $0 start
        ;;
    stop)
        #start-stop-daemon --stop -x $RADOSGW --oknodo
        killproc $RADOSGW
        echo "Stopping radosgw instance(s)..."
        ;;
    status)
        if pidof $RADOSGW >/dev/null; then
            echo "$RADOSGW is running."
        else
            echo "$RADOSGW is not running."
            exit 1
        fi
        ;;
    *)
        echo "Usage: $0 start|stop|restart|force-reload|reload|status" >&2
        exit 3
        ;;
esac