~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

Viewing changes to vivid/etc/init.d/sphinxsearch

  • Committer: Dimitri John Ledkov
  • Date: 2014-11-19 12:58:41 UTC
  • Revision ID: dimitri.j.ledkov@intel.com-20141119125841-98dr37roy8dvcv3b
auto update

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh
 
2
#
 
3
#               Written by Miquel van Smoorenburg <miquels@cistron.nl>.
 
4
#               Modified for Debian
 
5
#               by Ian Murdock <imurdock@gnu.ai.mit.edu>.
 
6
#               Further changes by Javier Fernandez-Sanguino <jfs@debian.org>
 
7
#               Modified for sphinx by Radu Spineanu <radu@debian.org>
 
8
#
 
9
#
 
10
 
 
11
### BEGIN INIT INFO
 
12
# Provides:          sphinxsearch
 
13
# Required-Start:    $local_fs $remote_fs $syslog $network $time
 
14
# Required-Stop:     $local_fs $remote_fs $syslog $network
 
15
# Default-Start:     2 3 4 5
 
16
# Default-Stop:      0 1 6
 
17
# Short-Description: Fast standalone full-text SQL search engine
 
18
### END INIT INFO
 
19
 
 
20
 
 
21
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 
22
DAEMON=/usr/bin/searchd
 
23
NAME=sphinxsearch
 
24
DESC=sphinxsearch
 
25
 
 
26
test -x $DAEMON || exit 0
 
27
 
 
28
LOGDIR=/var/log/sphinxsearch
 
29
PIDFILE=/var/run/sphinxsearch/searchd.pid
 
30
DODTIME=1                   # Time to wait for the server to die, in seconds
 
31
                            # If this value is set too low you might not
 
32
                            # let some servers to die gracefully and
 
33
                            # 'restart' will not work
 
34
 
 
35
STARTDELAY=0.5
 
36
 
 
37
# Include sphinxsearch defaults if available
 
38
if [ -f /etc/default/sphinxsearch ] ; then
 
39
    . /etc/default/sphinxsearch
 
40
fi
 
41
 
 
42
if [ "$START" != "yes" ]; then
 
43
  echo "To enable $NAME, edit /etc/default/sphinxsearch and set START=yes"
 
44
  exit 0
 
45
fi
 
46
 
 
47
 
 
48
set -e
 
49
 
 
50
# Make sure the pidfile directory exists with correct permissions
 
51
piddir=`dirname "$PIDFILE"`
 
52
if [ ! -d "$piddir" ]; then
 
53
    mkdir -p "$piddir"
 
54
    chown -R sphinxsearch "$piddir"
 
55
    chgrp -R sphinxsearch "$piddir"
 
56
fi
 
57
 
 
58
 
 
59
running_pid()
 
60
{
 
61
    # Check if a given process pid's cmdline matches a given name
 
62
    pid=$1
 
63
    name=$2
 
64
    [ -z "$pid" ] && return 1
 
65
    [ ! -d /proc/$pid ] &&  return 1
 
66
    cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
 
67
    # Is this the expected child?
 
68
    [ "$cmd" != "$name" ] &&  return 1
 
69
    return 0
 
70
}
 
71
 
 
72
running()
 
73
{
 
74
# Check if the process is running looking at /proc
 
75
# (works for all users)
 
76
 
 
77
    # No pidfile, probably no daemon present
 
78
    [ ! -f "$PIDFILE" ] && return 1
 
79
    # Obtain the pid and check it against the binary name
 
80
    pid=`cat $PIDFILE`
 
81
    running_pid $pid $DAEMON || return 1
 
82
    return 0
 
83
}
 
84
 
 
85
do_force_stop() {
 
86
# Forcefully kill the process
 
87
    [ ! -f "$PIDFILE" ] && return
 
88
    if running ; then
 
89
        kill -15 $pid
 
90
        # Is it really dead?
 
91
        [ -n "$DODTIME" ] && sleep "$DODTIME"s
 
92
        if running ; then
 
93
            kill -9 $pid
 
94
            [ -n "$DODTIME" ] && sleep "$DODTIME"s
 
95
            if running ; then
 
96
                echo "Cannot kill $NAME (pid=$pid)!"
 
97
                exit 1
 
98
            fi
 
99
        fi
 
100
    fi
 
101
    rm -f $PIDFILE
 
102
    return 0
 
103
}
 
104
do_start() {
 
105
        # Check if we have the configuration file
 
106
        if [ ! -f /etc/sphinxsearch/sphinx.conf ]; then
 
107
            echo "\n"
 
108
            echo "Please create an /etc/sphinxsearch/sphinx.conf configuration file."
 
109
            echo "A template is provided as /etc/sphinxsearch/sphinx.conf.sample."
 
110
            exit 1
 
111
        fi
 
112
 
 
113
        start-stop-daemon --start --pidfile $PIDFILE --chuid sphinxsearch --exec ${DAEMON}
 
114
}
 
115
do_stop() {
 
116
        start-stop-daemon --stop --quiet --oknodo --user sphinxsearch --pidfile $PIDFILE \
 
117
            --exec $DAEMON
 
118
}
 
119
 
 
120
case "$1" in
 
121
  start)
 
122
        echo -n "Starting $DESC: "
 
123
        do_start
 
124
        [ -n "$STARTDELAY" ] && sleep $STARTDELAY
 
125
 
 
126
        if running ; then
 
127
            echo "$NAME."
 
128
        else
 
129
            echo " ERROR."
 
130
        fi
 
131
        ;;
 
132
  stop)
 
133
        echo -n "Stopping $DESC: "
 
134
        do_stop
 
135
        echo "$NAME."
 
136
        ;;
 
137
  force-stop)
 
138
        echo -n "Forcefully stopping $DESC: "
 
139
        do_force_stop
 
140
        if ! running ; then
 
141
            echo "$NAME."
 
142
        else
 
143
            echo " ERROR."
 
144
        fi
 
145
        ;;
 
146
  restart|reload|force-reload)
 
147
    echo -n "Restarting $DESC: "
 
148
        do_stop
 
149
        [ -n "$DODTIME" ] && sleep $DODTIME
 
150
        do_start
 
151
        echo "$NAME."
 
152
        ;;
 
153
 
 
154
  status)
 
155
    echo -n "$NAME is "
 
156
    if running ;  then
 
157
        echo "running"
 
158
    else
 
159
        echo " not running."
 
160
        exit 1
 
161
    fi
 
162
    ;;
 
163
  *)
 
164
    N=/etc/init.d/$NAME
 
165
    # echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
 
166
    echo "Usage: $N {start|stop|restart|force-reload|status|force-stop}" >&2
 
167
    exit 1
 
168
    ;;
 
169
esac
 
170
 
 
171
exit 0