76

I have downloaded redis-2.6.16.tar.gz file and i installed sucessfully. After installed i run src/redis-server it worked fine.

But i don't want manually run src/redis-server everytime, rather i want redis-server running as background process continuously.

So far after installed i did following tasks:

1. vim redis.conf and i changed to

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
  daemonize yes

But same result i found. What mistake i did?

After redis run in background. I will run juggernaut also as background process with following command.

nohup node server.js

But i am not able to make redis run in background. Please provide some solution.

siv rj
  • 1,451
  • 1
  • 14
  • 31

6 Answers6

288

Since Redis 2.6 it is possible to pass Redis configuration parameters using the command line directly. This is very useful for testing purposes.

redis-server --daemonize yes

Check if the process started or not:

ps aux | grep redis-server
Sagar Ranglani
  • 5,491
  • 4
  • 34
  • 47
  • 9
    Thanks for the answer, after this to see if its working on the background you could just use: redis-cli ping – Aronis Mariano Nov 13 '15 at 15:17
  • 3
    @AronisMariano and `PONG` for the response :) – Chemical Programmer Nov 20 '15 at 12:11
  • 7
    And just add `alias redis-server='redis-server --daemonize yes'` to your `~/.bash_profile` then you will get daemonize every time you type `redis-server` to your command line. – Benyi May 03 '17 at 06:52
  • I wish that this flag was in the --help documentation. This helped me to load this directly from python using subprocess: subprocess.Popen(['redis-server', '--daemonize', 'yes']) – Andrew Bowman Nov 02 '18 at 15:38
  • 1
    This helped me solve a production error within seconds! – Stefano Groenland Sep 27 '19 at 12:14
  • 1
    The inevitable followup is how to stop/close a daemonized redis-server. `redis-cli shutdown` works for me. See more with: https://stackoverflow.com/questions/49249229/how-to-stop-a-redis-server-that-was-started-with-daemonize-yes/ – Viet Than Dec 15 '21 at 20:34
17

I think the best way is to use Redis' config file:

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize yes

Set daemonize to yes in the config file. Say the file is ~/.redis/redis.conf, then just run

$ redis-server ~/.redis/redis.conf

And it just works.

laike9m
  • 18,344
  • 20
  • 107
  • 140
10

Or you can simply run it as src/redis-server redis.conf&

Hartley Brody
  • 8,669
  • 14
  • 37
  • 48
Chhavi Gangwal
  • 1,166
  • 9
  • 13
  • thanx i will make it try, for now problem get resolved. – siv rj Jun 16 '14 at 12:55
  • 1
    You can also pass configuration values on the command line, refer to the Redis configuration documentation: http://redis.io/topics/config To daemonize at the command line: redis-server --daemonize yes – chnrxn Jan 09 '15 at 05:34
  • More info on background jobs: https://www.digitalocean.com/community/tutorials/how-to-use-bash-s-job-control-to-manage-foreground-and-background-processes – TomFuertes May 29 '19 at 17:02
2

For windows:

Step 1: Install redis as a service

redis-server --server-install 

Step 2: Run background

redis-server --server-start 
1

To run redis server in background and ignore output .

nohup redis-server &

To check the server

ps aux | grep redis-server 

To Kill server

sudo service redis-server stop
Codertjay
  • 588
  • 8
  • 13
0

You can use PM2 when you want to run an application in the background.

  • Download pm2 package as global by npm. https://www.npmjs.com/package/pm2
    • npm i -g pm2
  • Then you can start the redis server.
    • pm2 start "redis-server" --name redis-caching-session

You can check pm2 sessions by pm2 status command and get logs of redis server by pm2 logs redis-caching-server command.

Edit: After 9 years, I just saw this post :) This answer may help other people so why I want to share.

canmustu
  • 2,304
  • 4
  • 21
  • 34