memcached not started automatically upon boot

I'm using Ubuntu 9.10 Server for my django-based web site and I want to run memcached automatically when booting up, so I've put the following lines to rc.local:

python /home/webapp/bin/start_memcached.py site
python /home/webapp/bin/start_django.py site

exit 0

start_memcached.py is just a script that starts memcached:

from os import system
import sys
import settings

arg = sys.argv[1]
setting = settings.MEMCACHED_SETTINGS[arg]
command = 'memcached start -d -l %s -m %d -P %s/%s_memcached.pid -p %d' % \
        (setting['listen'], setting['memory'],settings.PATH, arg, setting['port'])

system(command)

print 'Started'

It just reads some configuration from settings based on some key (that's why I'm calling it with argument site).

The thing is that django is started automatically upon boot but memcached is not. If I run the start_memcached.py script manually, then it's ok. Does anybody have any suggestion how to solve this or where the problem may be?

3 Replies

$PATH ?

Safest and most recommended option for all kinds of init/cron/anythingotherthaninteractiveshell scripts is using absolute paths.

Why not use an init script, which is the proper way to start daemons?

apt-get install memcached
/etc/init.d/memcached start

That doesn't start Memcached properly on Ubuntu, because for some incomprehensible reasons the packagers decided to disable Memcached by default. You have to edit /etc/default/memcached

# Set this to yes to enable memcached.
ENABLE_MEMCACHED=yes

If you have Webmin installed you can configure this in 'Startup and Shutdown.'

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct