I have installed memcached
on Ubuntu. How can I run it as a daemon so that it runs in the background and I can use it in my rails application?
Ubuntu: Running Memcached as daemon
memcached
is configured to run at boot by default, at least on 10.10:
# apt-get install memcached
...
Setting up memcached (1.4.5-1ubuntu1) ...
Starting memcached: memcached.
# ls -l /etc/rc*.d/*memcached
lrwxrwxrwx 1 root root 19 2011-03-23 13:36 /etc/rc0.d/K20memcached -> ../init.d/memcached
lrwxrwxrwx 1 root root 19 2011-03-23 13:36 /etc/rc1.d/K20memcached -> ../init.d/memcached
lrwxrwxrwx 1 root root 19 2011-03-23 13:36 /etc/rc2.d/S20memcached -> ../init.d/memcached
lrwxrwxrwx 1 root root 19 2011-03-23 13:36 /etc/rc3.d/S20memcached -> ../init.d/memcached
lrwxrwxrwx 1 root root 19 2011-03-23 13:36 /etc/rc4.d/S20memcached -> ../init.d/memcached
lrwxrwxrwx 1 root root 19 2011-03-23 13:36 /etc/rc5.d/S20memcached -> ../init.d/memcached
lrwxrwxrwx 1 root root 19 2011-03-23 13:36 /etc/rc6.d/K20memcached -> ../init.d/memcached
#
In runlevels 2, 3, 4, and 5, memcached will be running.
If you're not sure, you can run the initscript with status
:
# /etc/init.d/memcached status
* memcached is running
Ah, you should have mentioned that you installed from source :) See if there is a contributed initscript in the memcached sources that you can install into
/etc/init.d
and all symlink into the /etc/rc*.d/
directories as the default packaging provides. (If the memcached source doesn't include an initscript, you might just want to run cd /tmp; apt-get source memcached
and steal the initscript from the Ubuntu packaging, then edit it to reference wherever you installed your memcached
executable. It might also need you to create user and group accounts.) –
Quandary If you get permission denied errors when you enter the install command then remember to add sudo before it - sudo apt-get install memcached. –
Corduroy
Just in case anyone else ends up here looking for how to run the daemon directly (like inside a docker container for example). The flag you're looking for is -d
.
/usr/bin/memcached start -u memcached -d
To install memcached on ubuntu
apt-get install memcached
To start memcached
/etc/init.d/memcached start
To restart memcached
/etc/init.d/memcached start
To check the status of memcached
/etc/init.d/memcached status
To edit memcached config
sudo vi /etc/memcached.conf
By default memcached will run on 127.0.0.1:11211
and is configured to run at boot by default
© 2022 - 2024 — McMap. All rights reserved.
apt-get
. Now I have ran is indaemon mode
using-d
switch. But/etc/init.d/memcached status
sayNo such file or directory
. However when I try 'memcached status' it sayfailed to listen on TCP port 11211: Address already in use
. So it means it's running in background. – Phosphate