i have tried everything and i just can’t get an exec type job to run. i tired it on 3 different clusters and it fails on all.
the job prunes docker containers and just runs
docker system prune -a
this is the config section what am i doing wrong?
driver = “exec”
config {
command = “bash”
args = ["-c",
" docker system prune -a "]
}
no logs and containers are not prunced
job “docker-cleanup” {
type = “system”
constraint {
attribute = “${attr.kernel.name}”
operator = “=”
value = “linux”
}
datacenters = [“dc1”]
group “docker-cleanup” {
restart {
interval = "24h"
attempts = 0
mode = "fail"
}
task "docker-system-prune" {
driver = "exec"
config {
command = "bash"
args = ["-c",
" docker system prune -a "]
}
resources {
cpu = 100
memory = 50
network {
mbits = 1
}
}
}
}
}
exec runs inside a chroot. could you try the same as a raw_exec
job, rather than an exec
job?
tried raw_exec same. if I do a bash sleep 5m i will see it running can see the process (os) running then at the end of 5 mins it stops and is marked as a failure. then it starts up again for 5 mins and then stops and marked as a failure.
if i try anyother command it runs for a second then is marked as a faliure.
running latest version of nomand in the Hashiqube
ah … I see what’s the matter.
- you’ll need to read up on the types of jobs; “system”, “service”, “batch”.
system === runs forever on all hosts matching the constraints.
service === runs forever somewhere on the hosts matching the constraints.
batch == runs and exits, on the matching host via the constraints.
so the system job rerunning is the expected behavior.
btw the command you are using should be docker system prune -af
, right? as only “-a” will be waiting for interactive prompt to enter “Y”, which will not work, correct?
couple of things to debug here …
1 Like
thanks u for response. U are right. i was able to get it to work using batch.
in addition no need to do it since Nomad does GC on its own.
However what if you want a job to run on all nodes like a system job but its a script that you want to run every x amount of time? Sort of a system/batch job?
i wan the command to run every 5 minutes on every node. I do it as follows
so i did the following
config {
command = “bash”
args = ["-c", " while true \n\t do\n\t echo hello world\n\t sleep 5m\n\t done\n\t "]
}
Hack, it creates and infinite loop that
what you are asking for is a “system + batch + periodic” job. It isn’t there yet, though using the “restart” block you can make it “happen”.
The hack is to:
- create a system job
- lets the script do whatever it wants (docker system prune -af) and then exit.
** this will put the job in “failed” state, this is OK.
- make the restart interval long enough so nomad “reruns” the task appropriately.
Credit for hack: @tommyalatalo from the Gitter channel