How can I launch memcached on boot?
3 Answers
Why cron???
If its installed on Debian ( use rcconf ) or
update-rc.d memcached defaults
If its installed on Redhat,Fedora,Centos,Suse
chkconfig memcached on
If its installed on windows..
Dont Know, But suggest you install it on Linux :P
Since you included cron as part of the question, I'm going to assume you are looking to do this on a UNIX or UNIXlike systems (Linux, *BSD, Solaris, etc). Although you could be trying to do this with cygwin.
This is not the normal method of starting services but it can be done. Running things from cron can be a way to ensure a critical service is restarted if it fails. You will need to write a wrapper script that checks if memcached is already running then starts it if it isn't. Then put entries in the cron.
The wrapper script will look in part like:
...
if ps -C memcached 2>/dev/null | grep -q memcached 2>/dev/null ; then
MEMCAHED_RUNNING=1
then
if [ ! $MEMCACHED_RUNNING ] ; then
memecached $options
fi
...
Some enhancements that you should consider for this would be a check to ensure that memcache is not only running but returning values to key requests. That is is a bit beyond the scope of your question.
Then call the full script from cron. A cron entry in /etc/crontab would look like
*/5 * * * * user /path/to/memcached_restart_script
In a user cron it would look like
*/5 * * * * /path/to/memcached_restart_script
Most UNIX variants support the use of startup scripts. In SysV like systems like Solaris and Linux these are files named (servicename) stored in /etc/init.d with a link or symlink named S(nn)(servicename) in a directory like /etc/rc2.d, /etc/rc3.d, or /etc/rc5.d. In the BSD variants the script is stored under /usr/local/etc/rc.d or similar.
RHEL variants (RHEL, CentOS, Fedora, Scientific Linux, etc) can manage the scripts for you with a tool named chkconfig (chkconfig memcached on). Debian and ubuntu have a tool named update-rc.d (update-rc.d memcached defaults) Others have different methods.
Best Regards Rik
Presuming linux-ish cron (ISC cron aka vixiecron, actually),
@reboot /path/to/memcached/start/script
will start memcached once at startup. man 5 crontab has more details.
-
Very interesting... It makes sense for non daemon scripts, Why would you just not use standard init start?– ArenstarNov 14, 2010 at 3:30
-