summaryrefslogtreecommitdiffstats
path: root/extras/init.d/glusterfsd
blob: 866a0010e9afd20d0913996ce8250d18ecf15d73 (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
#!/bin/bash
#
# chkconfig: 35 90 12
# description: Glusterfsd server
#

# Get function from functions library
# . /etc/rc.d/init.d/functions

BASE=glusterfsd
GSERVER="/sbin/$BASE -f /etc/glusterfs/glusterfs-server.vol"

# A function to stop gluster
killgluster()
{
       killlevel="-9"
       # Find pid.
       pid=
       if [ -f /var/run/$BASE.pid ]; then
               local line p
               read line < /var/run/$BASE.pid
               for p in $line ; do
                       [ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && pid="$pid
$p"
               done
       fi
       if [ -z "$pid" ]; then
               pid=`pidof -o $$ -o $PPID -o %PPID -x $1 || \
                       pidof -o $$ -o $PPID -o %PPID -x $BASE`
       fi
       # Kill it.
       kill $killlevel $pid
       if [ "$?" = 0 ]
         then
            echo "Gluster process $pid has been killed"
            initlog -n "Kill gluster" -e 1
         else
            echo "Failed: Gluster process $pid has not been killed"
            initlog -n "Kill gluster" -e 2
       fi

       # Remove pid and lock file if any.
        if [ -f /var/run/$BASE.pid ]
           then
             rm -f /var/run/$BASE.pid && initlog -n "Remove $BASE.pid:" -e
1
           else echo "$BASE.pid not found" && initlog -n "Remove
$BASE.pid:" -e 2
        fi

        if [ -f /var/lock/subsys/$BASE ]
           then
             rm -f /var/lock/subsys/$BASE && initlog -n "Remove $BASE lock
file:" -e 1
           else echo "$BASE lock file not found" && initlog -n "Remove
$BASE lock file:" -e 2
        fi
}

# Start the service $BASE
start()
{
       initlog -c "echo -n Starting $BASE:"
       $GSERVER
       if [ $? = 0 ]
        then
          touch /var/lock/subsys/$BASE
          initlog -n "Starting $BASE" -e 1
          echo "  [OK]"
        else
          echo "$BASE start failed."
          initlog -n "$BASE start" -e 2
       fi
}

# Stop the service $BASE
stop()
{
       echo "Stopping $BASE:"
       killgluster
}
status()
{
       if test "`lsof |grep -c /sbin/$BASE`" = "0"
         then echo "$BASE is stopped."
         else echo "$BASE is running..."
       fi
}

### service arguments ###
case $1 in
 start)
       start
       ;;
 stop)
       stop
       ;;
 status)
       status
       ;;
 restart|reload|condrestart)
       stop
       start
       ;;
 *)
       echo $.Usage: $0 {start|stop|restart|reload|status}.
       exit 1
esac

exit 0