Search code examples
ubuntuupstart

Passing a command with whitespace to an Upstart service instance


I have an Upstart service that is supposed to launch multiple worker instances (using rq as a job queue). But I'm having trouble passing commands with whitespace to the service launcher.

My Upstart config (worker-manager.conf) looks like this:

description "my worker manager"

instance $id

start on runlevel [2345]
stop on runlevel [!2345]

respawn

script
    logfile="/home/ubuntu/worker.log"
    exec bash -c $cmd 2>$logfile
end script

So, to start the worker, this works:

sudo service worker-manager start id=1 cmd="rqworker"

But this doesn't:

sudo service worker-manager start id=1 cmd="rqworker -v queue_1"

The error I get is:

start: Env must be KEY=VALUE pairs

I haven't had any luck yet using double quotes, single-inside-double quotes or escaping the whitespace either. Hardcoding the argument inside the config file does work.

I can't pass the command in as multiple arguments, because I don't know in advance which or how many queues should be listened to etc. The workaround I have at the moment is to put the command in a file and let the service manager read it from there, but that's messy and I'm sure there's a better way. Also, this is all supposed to be happening on a bunch of AWS "minion" instances controlled by a master, so that limits the number of solutions open to me. Any ideas?


Solution

  • use the start command directly

    sudo start worker-manager id=1 cmd="rqworker -v queue_1"
    

    though you may need to quote again:

    sudo start worker-manager id=1 cmd="'rqworker -v queue_1'"