I want to run raw_exec to install an nginx , is this possible? or how can this be done by raw_exec only. since this code will not start/run.
job "raw-exec" {
datacenters = ["dc1"]
type = "service"
group "exec" {
count = 1
update {
max_parallel = 1
min_healthy_time = "10s"
healthy_deadline = "5m"
progress_deadline = "10m"
auto_revert = true
}
task "raw-exec-test" {
driver = "raw_exec"
config {
command = "/bin/apt"
args = ["-y", "install", "nginx.service"]
}
resources {
cpu = 100
memory = 125
}
}
}
}
Without a job status it is hard to troubleshoot what's wrong.
nomad job status raw-exec would show your job status. It will also show allocations created by the job.
You can check what's wrong with the allocations (set of tasks in a job should be run on a particular node) that Nomad creates by nomad alloc status YOUR-ALLOC-ID.
I've run the following Nomad job specification and it worked well on my MacBook.
I ran nomad using nomad agent -dev in one terminal window, then created the file test.job in another terminal window and ran nomad job run test.job and it installed htop software on the MacBook.
job "raw-exec" {
datacenters = ["dc1"]
type = "batch"
group "exec" {
count = 1
task "raw-exec-test" {
driver = "raw_exec"
config {
command = "brew"
args = ["install", "htop"]
}
resources {
cpu = 100
memory = 125
}
}
}
}
Notice that I've changed job type from service to batch. Batch jobs are designed to run once while services should be up and running all the time. I suppose that you want your apt install -y nginx command to run only once. You can read more about job types here.