WebFaction
Community site: login faq

Got memcache socket setup. Trying to create a cron job using a script posted here.

if ps -U user | grep -v grep | grep memcached > /dev/null
then
  echo "Memcached is running.";
else
  echo "Starting memcache.";
  /usr/local/bin/memcached -d -m 64 -s $HOME/memcached.sock -P $HOME/memcached.pid;
fi

Where user is my username.

Problem with this script is that even when I kill my socket it always says 'Memcached is running.'--even when it isn't.

Also when i put it directly in the command-line the script works.

asked 07 Apr '13, 22:55

jayhallaux
1112
accept rate: 0%

We have a real watchdog script available here which is much more heavily tested and is in use in many production websites. Can you see if you have any better luck with this one instead?

(08 Apr '13, 03:36) ryans ♦♦

Thanks. That definitely worked the charm.

#!/usr/bin/env bash

PIDFILE="$HOME/memcached/memcached.pid"

if [ -e "${PIDFILE}" ] && (ps -u $(whoami) -f | grep "[ ]$(cat ${PIDFILE})[ ]"); 
then
    echo "Memcached already running."
    exit 99
fi

echo "Starting up memcache."
/usr/local/bin/memcached -d -m 64 -s $HOME/memcached/memcached.sock -P ${PIDFILE} > $HOME/tmp/memcached.log &

echo $! > "${PIDFILE}"
chmod 644 "${PIDFILE}"

for those that interested.

permanent link

answered 08 Apr '13, 23:18

jayhallaux
1112
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×34

question asked: 07 Apr '13, 22:55

question was seen: 3,367 times

last updated: 08 Apr '13, 23:18

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM