updated on Thu Jan 19 20:01:47 UTC 2012
[aur-mirror.git] / memcached-repcached / memcached-repcached.sh
blobd3184542654c54dbd20111a8f85b3ad711011d14
1 #!/bin/bash
3 . /etc/rc.conf
4 . /etc/rc.d/functions
5 . /etc/conf.d/memcached-repcached
7 PIDFILE='/var/run/memcached-repcached.pid'
9 getpid() {
10 local pid
11 pid=$(cat $PIDFILE 2>/dev/null)
12 # if the process is no longer valid, don't return it
13 if [ -n "$pid" ]; then
14 if ! ps -p $pid >/dev/null; then
15 rm -f $PIDFILE
16 pid=""
19 echo $pid
22 PID="$(getpid)"
24 case "$1" in
25 start)
26 stat_busy "Starting memcached-repcached"
27 # memcached is retarded and doesn't write to the pidfile
28 # before it drops permissions
29 if [ -n "$PID" ]; then
30 stat_fail
31 elif [ -z "$MEMCACHED_USER" ]; then
32 echo "MEMCACHED_USER must be defined in /etc/conf.d/memcached-repcached"
33 stat_fail
34 else
35 touch $PIDFILE && chown $MEMCACHED_USER $PIDFILE
36 /usr/bin/memcached-repcached -d -P $PIDFILE -u $MEMCACHED_USER $MEMCACHED_ARGS
37 if [ $? -gt 0 ]; then
38 stat_fail
39 else
40 add_daemon memcached-repcached
41 stat_done
45 stop)
46 stat_busy "Stopping memcached-repcached"
47 [ ! -z "$PID" ] && kill $PID &> /dev/null
48 if [ $? -gt 0 ]; then
49 stat_fail
50 else
51 rm -f $PIDFILE
52 rm_daemon memcached-repcached
53 stat_done
56 restart)
57 $0 stop
58 sleep 1
59 $0 start
62 echo "usage: $0 {start|stop|restart}"
63 esac