109

How to stop and restart memcached server 1.4.5 in linux OS from command line?

Arslan Ali
  • 17,418
  • 8
  • 58
  • 76
smriti
  • 1,119
  • 2
  • 8
  • 5
  • can anybody help me in this https://stackoverflow.com/questions/50135302/memcached-could-not-connect-to-remote-server-memcached-js – Rituraj RF N TF May 07 '18 at 12:13

12 Answers12

128

Using root, try something like this:

/etc/init.d/memcached restart
spatical
  • 657
  • 4
  • 12
pejuko
  • 1,654
  • 1
  • 10
  • 5
  • it did not work- is there a need to creare script to stop and start as service? – smriti Jun 23 '10 at 15:56
  • 3
    well, it realy depends on your linux distribution and how you did install memcache. If you hav installed package of your distribution there should be memcached start/stop script (maybe it is in different directory like /etc/rc.d) If you installed memcached manualy you probably need also create star/stop script by yourself. – pejuko Jun 23 '10 at 17:11
  • I had to add sudo – Tomas Gonzalez May 05 '20 at 22:55
51

Log in as root or do

su -

Then:

service memcached restart

If that doesn't work, then:

/etc/init.d/memcached restart

It all depends on which Linux distro (or other OS) you're using.

Boris Verkhovskiy
  • 14,854
  • 11
  • 100
  • 103
ajacian81
  • 7,419
  • 9
  • 51
  • 64
29

If you're using homebrew:

brew services restart memcached
Henry
  • 7,721
  • 2
  • 38
  • 38
  • Note that `services` is now considered an external tool to brew. http://apple.stackexchange.com/questions/150300/need-help-using-homebrew-services-command – Kirby May 06 '15 at 21:54
  • ...meaning you need to install it before you can use it: `brew tap homebrew/services` – wxactly Sep 23 '15 at 00:26
26
sudo service memcached stop

sudo service memcached start

sudo service memcached restart
Akshar Raaj
  • 14,231
  • 7
  • 51
  • 45
9

if linux

if install by apt-get

service memcached stop
service memcached restart

if install by source code

Usage: /etc/init.d/memcached {start|stop|restart|force-reload|status}

can also simply kill $pid to stop

Emmerich Liang
  • 131
  • 1
  • 3
7
sudo /etc/init.d/memcached restart
j0k
  • 22,600
  • 28
  • 79
  • 90
DaddyCee
  • 71
  • 1
  • 1
7

As root on CentOS 7:

systemctl start memcached
systemctl stop memcached
systemctl restart memcached

To tell the service to start at reboot (ex chkconfig):

systemctl enable memcached

To tell the service to not start at reboot:

systemctl disable memcached
chirale
  • 1,659
  • 16
  • 20
7

To shutdown memcache daemon:

sudo service memcached stop

To start memcached daemon:

sudo service memcached start

Restart memcached server:

sudo service memcached restart

You can see if Memcache is currently runing:

sudo ps -e | grep memcached

And you can check the TCP or UDP ports if something (e.g. Memcache) is listening to it:

netstat -ap | grep TheChosenPort#
netstat -ap | grep 11211

For some Linuxes you need to change your commands like:

sudo /etc/init.d/memcached start
sudo /etc/init.d/memcached restart
sudo /etc/init.d/memcached stop
Eugene Kaurov
  • 2,356
  • 28
  • 39
6

If you want to be allowed to shutdown the memcached server you can give it that option before start it :

memcached -A &

With this option when you connect to memcached server for example:

telnet localhost 11211

then you can use shutdown command to shutdown the server. You can also shutdown the memcached server when it is run as a process, first find the process PID using:

pidof memcached

then use:

kill PID command
Martin Evans
  • 45,791
  • 17
  • 81
  • 97
Mustafa R.Mahdi
  • 744
  • 7
  • 11
3

This worked for me:

brew services stop memcached
Ardent Coder
  • 3,777
  • 9
  • 27
  • 53
Miles Lane
  • 31
  • 1
1

If you have an older version of memcached and need a script to wrap memcached as a service, here it is: Memcached Service Script

Beachhouse
  • 4,972
  • 3
  • 25
  • 39
1

For me, I installed it on a Mac via Homebrew and it is not set up as a service. To run the memcached server, I simply execute memcached -d. This will establish Memcached server on the default port, 11211.

> memcached -d
> telnet localhost 11211
Trying ::1...
Connected to localhost.
Escape character is '^]'.
version
VERSION 1.4.20
Kirby
  • 15,127
  • 10
  • 89
  • 104