Monday, July 18, 2011

Introducing keep-one-running!

I just added another utility to the run-one package -- keep-one-running.  It's already in Ubuntu Oneiric (11.10), or you can add it to any other supported Ubuntu release from the PPA, with:

sudo apt-add-repository ppa:run-one/ppa
sudo apt-get update
sudo apt-get install -y run-one

run-one is a very useful tool that you can use to ensure that you never have more than one invocation of a process running on a system at a time.  I now use it in every single cron job I have, to keep long running jobs from ever stepping on a subsequent one.

I use a bip proxy to keep me connected to IRC and log messages even while I'm away.  Before opening xchat, I need to establish an ssh tunnel to my bip proxy.  More importantly, I need to keep that connection up (particularly when I'm on an unreliable network). 

To solve that problem generally, I added the keep-one-running mode to run-one.  And now, I added this command to my Unity startup applications:

keep-one-running ssh -N -C -L 7778:localhost:7778 divitup.com

If I were a root user, I could perhaps use upstart and the respawn directive.  I guess you could look at keep-one-running as a poor man's respawn.  Give it a shot and let me know if it's useful to you!

Enjoy ;-)

:-Dustin

4 comments:

  1. so you reivented "nuhup"? Why?

    ReplyDelete
  2. Interesting! I've the same use-case for an SSH tunnel for IRC; I've edited my xchat-gnome.desktop file to launch the tunnel before it opens the XChat window, and also added a quicklist item to re-launch the tunnel if I the connection dies.

    Your solution is much more automated.

    ReplyDelete
  3. Anonymous,

    keep-one-running isn't really nohup, for two reasons.

    First, the "one" part of keep-one-running is important, in that it uses run-one to protect you from running more than one instances of the specified command. This is handy for something like an ssh tunnel, that you only really want/need one of.

    Second, nohup doesn't rerun the specified command if it exits or gets killed. nohup only ignores the hangup signal.

    Cheers,
    Dustin

    ReplyDelete
  4. Useful utility, I'm currently using the 1.7.0 version from oneiric as a utility on a CentOS 5 machine as a poor man's init script (I need to run a daemon which is written in Python and doesn't have its own init script).

    @reboot in crontab with keep-one-running seems to work perfectly, so thanks!

    ReplyDelete

Please do not use blog comments for support requests! Blog comments do not scale well to this effect.

Instead, please use Launchpad for Bugs and StackExchange for Questions.
* bugs.launchpad.net
* stackexchange.com

Thanks,
:-Dustin