Frage

I have a long-running command (sidekiq, if you must know) that depends on another long-running processes (redis-server, as you may have guessed from the previous parenthetical).

I'd like to write a Bash (well, okay, Zsh actually) alias to start redis-server in the background, then run sidekiq and, when I use ctrl-C to interrupt sidekiq, to kill the background Redis job. If it's relevant, I'm on a Mac and only need to support OS X.

So what I'm looking for is something like:

redis-server & ; sidekiq ; kill $!

Unfortunately, my interrupt of the sidekiq command also prevents the kill from occurring. Is there any way to do this?

Bonus points if this can be a one-liner alias and not a function. Double bonus points if I don't have to write to any files in advance (like turning on the daemonize flag in /usr/local/etc/redis.conf).

War es hilfreich?

Lösung

Maybe this:

#!/bin/zsh
redis-server &
redispid=$!
trap 'kill $redispid' INT
sidekiq
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top