Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 31 additions & 12 deletions scripts/memcached-init
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,29 @@ set -e

case "$1" in
start)
echo -n "Starting $DESC: "
start-stop-daemon --start --quiet --exec $DAEMONBOOTSTRAP
echo "$NAME."
if [ -f "$PIDFILE" ]; then
pid=$(cat "$PIDFILE")
if kill -0 "$pid" 2>/dev/null; then
Comment thread
cheesecrust marked this conversation as resolved.
echo "Already running with PID: $pid"
exit 1
fi
rm -f "$PIDFILE"
fi
nohup $DAEMONBOOTSTRAP > /dev/null 2>&1 &
Comment thread
cheesecrust marked this conversation as resolved.
daemon_pid=$!
echo "$daemon_pid" > "$PIDFILE" & echo "Started with PID: $daemon_pid"
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON
echo "$NAME."
rm -f $PIDFILE
if [ -f "$PIDFILE" ]; then
pid=$(cat "$PIDFILE")
if kill -0 "$pid" 2>/dev/null; then
kill "$pid"
echo "Stopped with PID: $pid"
fi
rm -f "$PIDFILE"
else
echo "PID file not found: $PIDFILE"
fi
;;

restart|force-reload)
Expand All @@ -51,12 +65,17 @@ case "$1" in
# option to the "reload" entry above. If not, "force-reload" is
# just the same as "restart".
#
echo -n "Restarting $DESC: "
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
rm -f $PIDFILE
if [ -f "$PIDFILE" ]; then
pid=$(cat "$PIDFILE")
if kill -0 "$pid" 2>/dev/null; then
kill "$pid"
fi
rm -f "$PIDFILE"
fi
sleep 1
start-stop-daemon --start --quiet --exec $DAEMONBOOTSTRAP
echo "$NAME."
nohup $DAEMONBOOTSTRAP > /dev/null 2>&1 &
daemon_pid=$!
echo "$daemon_pid" > "$PIDFILE" & echo "Restarted with PID: $daemon_pid"
;;
*)
N=/etc/init.d/$NAME
Expand Down
1 change: 1 addition & 0 deletions scripts/memcached.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-E lib/default_engine.so
47 changes: 3 additions & 44 deletions scripts/start-memcached
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,12 @@

use strict;

if($> != 0 and $< != 0)
Comment thread
cheesecrust marked this conversation as resolved.
{
print STDERR "Only root wants to run start-memcached.\n";
exit;
}

my $params; my $etchandle; my $etcfile = "/etc/memcached.conf";

# This script assumes that memcached is located at /usr/bin/memcached, and
# that the pidfile is writable at /var/run/memcached.pid

my $memcached = "/usr/bin/memcached";
my $pidfile = "/var/run/memcached.pid";

# If we don't get a valid logfile parameter in the /etc/memcached.conf file,
# we'll just throw away all of our in-daemon output. We need to re-tie it so
Expand Down Expand Up @@ -76,42 +69,8 @@ if(open $etchandle, $etcfile)
$params = [];
}

push @$params, "-u root" unless(grep "-u", @$params);
$params = join " ", @$params;

if(-e $pidfile)
{
open PIDHANDLE, "$pidfile";
my $localpid = <PIDHANDLE>;
close PIDHANDLE;

chomp $localpid;
if(-d "/proc/$localpid")
{
print STDERR "memcached is already running.\n";
exit;
}else{
`rm -f $localpid`;
}

}

my $pid = fork();

if($pid == 0)
{
reopen_logfile($fd_reopened);
exec "$memcached $params";
exit(0);

}else{
if(open PIDHANDLE,">$pidfile")
{
print PIDHANDLE $pid;
close PIDHANDLE;
}else{

print STDERR "Can't write pidfile to $pidfile.\n";
}
}

reopen_logfile($fd_reopened);
exec "$memcached $params";
exit(0);