Running bash scripts as a task in nomad using raw_exec driver

I am unable run bash scripts as a task in a job in nomad. i have used exec driver. The task is not running and just saying its dead

exec and raw_exec are different. exec is chroot, raw_exec is on the OS itself (non-chroot).

There are many pieces of information missing in your query :slight_smile:
What type of job? (batch/service/etc.)

Would it be possible for you to post a minimal example (remove any sensitive information) of your job file to indicate what you are trying to do?

Hi Thanks for the reply.
I am new to nomad so was confused a bit and some basic doubts
Here is my job file -

job “example” {

datacenters = [“dc1”]

type = “service”

update {
max_parallel = 1

min_healthy_time = “10s”

healthy_deadline = “3m”

progress_deadline = “10m”

auto_revert = false

canary = 0
}
migrate {

max_parallel = 1

health_check = “checks”

min_healthy_time = “10s”

healthy_deadline = “5m”
}

group “cache” {
count = 1

restart {
attempts = 2
interval = “30m”

delay = “15s”

mode = “fail”
}

ephemeral_disk {
size = 300
}

   task "script"{
   driver = "raw_exec"
   
   config {
   command = "/bin/bash"
   args = ["run.sh"]
        }
    }

}
}
run.sh will simply print “Hello world”. How to know if the task ran. Should it print Hello world on the terminal as soon as I do nomad job run example.nomad ? The task does pending for a few seconds and then dead. Its not showing any errors as such.
Also what should command and args include in this case.

I am not sure which driver to use here. The file is in the vagrant folder in virtualbox running through vagrant. The folder is a shared folder present on desktop.

Couple of things here:

  • “service” type of job means the task should not end (running forever until stopped/failed)
  • nomad logs should let you look at the STDOUT and STDERR outputs
  • As this is a sample job, I can suggest to make the run.sh as a “while 1, sleep 1” code, so you can see the expected behavior of the “service” job.
  • In case you want to run tasks which actually exit, you should use the job type “batch”
2 Likes