~john-koepi/ubuntu/trusty/memcached/default

« back to all changes in this revision

Viewing changes to scripts/memcached-init

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2011-10-05 13:27:39 UTC
  • mfrom: (1.1.8 upstream) (3.3.4 sid)
  • Revision ID: james.westby@ubuntu.com-20111005132739-ntsnlj16fcze221i
Tags: 1.4.7-0.1ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Run as 'memcache' user instead of nobody (LP #599461)
  - Depend on adduser for preinst/postrm
  - Create user in postinst

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /bin/sh
2
 
#
3
 
# skeleton  example file to build /etc/init.d/ scripts.
4
 
#       This file should be used to construct scripts for /etc/init.d.
5
 
#
6
 
#       Written by Miquel van Smoorenburg <miquels@cistron.nl>.
7
 
#       Modified for Debian
8
 
#       by Ian Murdock <imurdock@gnu.ai.mit.edu>.
9
 
#
10
 
# Version:  @(#)skeleton  1.9  26-Feb-2001  miquels@cistron.nl
11
 
#
 
1
#! /bin/bash
12
2
### BEGIN INIT INFO
13
3
# Provides:          memcached
14
4
# Required-Start:    $syslog
15
5
# Required-Stop:     $syslog
 
6
# Should-Start:        $local_fs
 
7
# Should-Stop:        $local_fs
16
8
# Default-Start:     2 3 4 5
17
9
# Default-Stop:      0 1 6
18
 
# Short-Description: Start memcached daemon at boot time
19
 
# Description:       Enable memcached server
 
10
# Short-Description:    memcached - Memory caching daemon
 
11
# Description:        memcached - Memory caching daemon
20
12
### END INIT INFO
21
13
 
 
14
# Usage:
 
15
# cp /etc/memcached.conf /etc/memcached_server1.conf
 
16
# cp /etc/memcached.conf /etc/memcached_server2.conf
 
17
# start all instances:
 
18
# /etc/init.d/memcached start
 
19
# start one instance:
 
20
# /etc/init.d/memcached start server1
 
21
# stop all instances:
 
22
# /etc/init.d/memcached stop
 
23
# stop one instance:
 
24
# /etc/init.d/memcached stop server1
 
25
# There is no "status" command.
22
26
 
23
27
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
24
28
DAEMON=/usr/bin/memcached
 
29
DAEMONNAME=memcached
25
30
DAEMONBOOTSTRAP=/usr/share/memcached/scripts/start-memcached
26
 
NAME=memcached
27
31
DESC=memcached
28
 
PIDFILE=/var/run/$NAME.pid
29
32
 
30
33
test -x $DAEMON || exit 0
31
34
test -x $DAEMONBOOTSTRAP || exit 0
32
35
 
33
36
set -e
34
37
 
 
38
FILES=(/etc/memcached_*.conf)
 
39
# check for alternative config schema
 
40
if [ -r "${FILES[0]}" ]; then
 
41
  CONFIGS=()
 
42
  for FILE in "${FILES[@]}";
 
43
  do
 
44
    # remove prefix
 
45
    NAME=${FILE#/etc/}
 
46
    # remove suffix
 
47
    NAME=${NAME%.conf}
 
48
 
 
49
    # check optional second param
 
50
    if [ $# -ne 2 ];
 
51
    then
 
52
      # add to config array
 
53
      CONFIGS+=($NAME)
 
54
    elif [ "memcached_$2" == "$NAME" ];
 
55
    then
 
56
      # use only one memcached
 
57
      CONFIGS=($NAME)
 
58
      break;
 
59
    fi;
 
60
  done;
 
61
 
 
62
  if [ ${#CONFIGS[@]} == 0 ];
 
63
  then
 
64
    echo "Config not exist for: $2" >&2
 
65
    exit 1
 
66
  fi;
 
67
else
 
68
  CONFIGS=(memcached)
 
69
fi;
 
70
 
 
71
CONFIG_NUM=${#CONFIGS[@]}
 
72
for ((i=0; i < $CONFIG_NUM; i++)); do
 
73
  NAME=${CONFIGS[${i}]}
 
74
  PIDFILE="/var/run/${NAME}.pid"
 
75
 
35
76
case "$1" in
36
77
    start)
37
78
        echo -n "Starting $DESC: "
38
 
        start-stop-daemon --start --quiet --exec $DAEMONBOOTSTRAP
 
79
        start-stop-daemon --start --quiet --exec "$DAEMONBOOTSTRAP" -- /etc/${NAME}.conf $PIDFILE
39
80
        echo "$NAME."
40
81
        ;;
41
82
    stop)
55
96
        start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
56
97
        rm -f $PIDFILE
57
98
        sleep 1
58
 
        start-stop-daemon --start --quiet --exec $DAEMONBOOTSTRAP
 
99
        start-stop-daemon --start --quiet --exec "$DAEMONBOOTSTRAP" -- /etc/${NAME}.conf $PIDFILE
59
100
        echo "$NAME."
60
101
        ;;
61
102
    *)
65
106
        exit 1
66
107
        ;;
67
108
esac
 
109
done;
68
110
 
69
111
exit 0