3

I have the following upstart job which takes arguments to run multiple instances of the same job:

instance $ARG1,$ARG2

script
    exec /path/to/executable "$ARG1" "ARG2"
end script

Now if I start two instances of my job like this:

$ start my-job ARG1=ABCD ARG2=1
my-job (ABCD,1) start/running, process 6242

$ start my-job ARG1=EFGH ARG2=2
my-job (EFGH,2) start/running, process 6254

How do I stop all instances of my-job in one command, short of doing a grep on initctl list, extracting the parameters of running instances of my-job and doing a stop on each of the instances.

I've tried stop my-job and stop my-job ARG1=\* ARG2=\*. Both don't work.

ErJab
  • 6,056
  • 10
  • 42
  • 54

2 Answers2

2

I ended-up doing the following, it works with [start|stop|restart] svc.

scv.conf:

description "An Example Service"
start on networking
stop on runlevel[06]

svc-instance.conf:

instance $ADDR,$PORT
manual
respawn
console log
exec /opt/svc/bin/svc -a $ADDR -p $PORT

start-svc-task.conf:

start on starting svc

task

script
  for a in 10.10.10.1 10.10.10.2 10.10.10.3 10.10.10.4
  do
    for p in 4001 4002 4003 4004
    do status svc-instance ADDR=$a PORT=$p \
      || start svc-instance ADDR=$a PORT=$p \
    done
  done
end script

stop-my-job-task.conf:

start on stopping svc

task

script
  for a in 10.10.10.1 10.10.10.2 10.10.10.3 10.10.10.4
  do
    for p in 2001 2002 2003 2004
    do status svc-instance ADDR=$a PORT=$p \
      && stop svc-instance ADDR=$a PORT=$p \
      || continue
    done
  done
end script

See for yourself whether status || start and status && stop || continue logic is needed in your case. I should note that my original use case required only one instance variable and I haven't tested this with two variable like that.

errordeveloper
  • 6,716
  • 6
  • 41
  • 54
1

Use signals. You can stop all of them at once by doing initctl emit scv-stop

scv.conf:

description "An Example Service Starter"
start on networking
stop on runlevel[06]

for addr in 10.10.10.1 10.10.10.2 10.10.10.3 10.10.10.4;
{
    for port in 4001 4002 4003 4004;
    {
        status svc-n $addr:$port || start svc-n ADDR=$addr PORT=$port
    }
}
script

scv-n.conf

description "An Example Service Instance"
instance $ADDR:$PORT
stop on runlevel[06] or scv-stop

script
    exec /opt/svc/bin/svc -a $ADDR -p $PORT
end script
Arie Skliarouk
  • 423
  • 2
  • 11