1

We have 3 instances of redis running on a test server. For some reason, our start script which starts redis can write the wrong pid to a file. Here is what it's doing:

su redis -c "redis-server /redis.conf & echo \$! > /var/run/redis_6379"

If I chain together redis_6379 start && redis_6380 start && redis_6381 start and then I stop them like that and start them like that, after 10 or 15 iterations I'll encounter a pid in the start file that is off by 1.

Does anyone know why that may occur?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
JasonG
  • 395
  • 3
  • 9
  • Which shell are you using? Bash? How exactly are you chaining them? The script you show cannot be run as `redis_6379 start && redis_6380`. – terdon Sep 18 '13 at 15:37
  • Oh sorry - Bash, rhel. – JasonG Sep 18 '13 at 15:42
  • 1
    OK, but please show us exactly how you are launching these, what is `redis_6379 start`? Is each of these a script file containing the `redis-server` command you've posted? – terdon Sep 18 '13 at 15:45

1 Answers1

2

Is it possible that redis-server forks, and that the PID you get from $! is the parent PID, but you're actually interested in the child PID?

Martin von Wittich
  • 13,857
  • 6
  • 51
  • 74
  • I'm thinking it's something like this. Best way to verify? read the source? – JasonG Sep 18 '13 at 17:40
  • @JasonG: probably yes. This [posting](http://stackoverflow.com/questions/8674788/running-redis-in-daemonized-form-and-using-upstart-to-manage-it-doesnt-work) is relevant - it contains a snippet of the redis-server daemonize code, but it's from 2011 though. And it doesn't really explain why this would only happen in one of 10-15 runs. – Martin von Wittich Sep 18 '13 at 18:00
  • 1
    @MartinvonWittich - nice detective work! – slm Sep 18 '13 at 18:47