Debian Codegraph @

scripts/memcached-init

raw symbols ◀ ▶
Source reconstructed at patch state 1 of 3 — not the installed (fully patched) source.
3 Debian patches touch this file
1 #! /bin/bash
2 ### BEGIN INIT INFO
3 # Provides: memcached
4 # Required-Start: $remote_fs $syslog
5 # Required-Stop: $remote_fs $syslog
6 # Should-Start: $local_fs
7 # Should-Stop: $local_fs
8 # Default-Start: 2 3 4 5
9 # Default-Stop: 0 1 6
10 # Short-Description: memcached - Memory caching daemon
11 # Description: memcached - Memory caching daemon
12 ### END INIT INFO
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.
26
27 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
28 DAEMON=/usr/bin/memcached
29 DAEMONNAME=memcached
30 DAEMONBOOTSTRAP=/usr/share/memcached/scripts/start-memcached
31 DESC=memcached
32
33 test -x $DAEMON || exit 0
34 test -x $DAEMONBOOTSTRAP || exit 0
35
36 set -e
37
38 . /lib/lsb/init-functions
39
40 FILES=(/etc/memcached_*.conf)
41 # check for alternative config schema
42 if [ -r "${FILES[0]}" ]; then
43 CONFIGS=()
44 for FILE in "${FILES[@]}";
45 do
46 # remove prefix
47 NAME=${FILE#/etc/}
48 # remove suffix
49 NAME=${NAME%.conf}
50
51 # check optional second param
52 if [ $# -ne 2 ];
53 then
54 # add to config array
55 CONFIGS+=($NAME)
56 elif [ "memcached_$2" == "$NAME" ];
57 then
58 # use only one memcached
59 CONFIGS=($NAME)
60 break;
61 fi;
62 done;
63
64 if [ ${#CONFIGS[@]} == 0 ];
65 then
66 echo "Config not exist for: $2" >&2
67 exit 1
68 fi;
69 else
70 CONFIGS=(memcached)
71 fi;
72
73 CONFIG_NUM=${#CONFIGS[@]}
74 for ((i=0; i < $CONFIG_NUM; i++)); do
75 NAME=${CONFIGS[${i}]}
76 PIDFILE="/var/run/${NAME}.pid"
77
78 case "$1" in
79 start)
80 echo -n "Starting $DESC: "
81 start-stop-daemon --start --quiet --exec "$DAEMONBOOTSTRAP" -- /etc/${NAME}.conf $PIDFILE
82 echo "$NAME."
83 ;;
84 stop)
85 echo -n "Stopping $DESC: "
86 start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON
87 echo "$NAME."
88 rm -f $PIDFILE
89 ;;
90 status)
91 [ $# -lt 2 ] && NAME=$DAEMONNAME
92 PIDFILE="/var/run/$NAME.pid"
93 set +e
94 start-stop-daemon --status --pidfile $PIDFILE
95 case $? in
96 0) echo "$DESC: $NAME (pid $(cat $PIDFILE)) is running" && exit 0;;
97 1) echo "$DESC: $NAME is not running thro' the pid file exists" && rm -f $PIDFILE && exit 1;;
98 3) echo "$DESC: $NAME is not running" && exit 3;;
99 4) echo "$DESC: $NAME status is unclear, sorry" && exit 4;;
100 esac
101 ;;
102 restart|force-reload)
103 #
104 # If the "reload" option is implemented, move the "force-reload"
105 # option to the "reload" entry above. If not, "force-reload" is
106 # just the same as "restart".
107 #
108 echo -n "Restarting $DESC: "
109 start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
110 rm -f $PIDFILE
111 sleep 1
112 start-stop-daemon --start --quiet --exec "$DAEMONBOOTSTRAP" -- /etc/${NAME}.conf $PIDFILE
113 echo "$NAME."
114 ;;
115 *)
116 N=/etc/init.d/$NAME
117 # echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
118 echo "Usage: $N {start|stop|status|restart|force-reload}" >&2
119 exit 1
120 ;;
121 esac
122 done;
123
124 exit 0