1job "java_pid" { 2 datacenters = ["dc1"] 3 type = "batch" 4 5 group "java" { 6 7 task "build" { 8 lifecycle { 9 hook = "prestart" 10 sidecar = false 11 } 12 13 driver = "exec" 14 config { 15 command = "javac" 16 args = ["-d", "${NOMAD_ALLOC_DIR}", "local/Pid.java"] 17 } 18 19 template { 20 destination = "local/Pid.java" 21 data = <<EOH 22public class Pid { 23 public static void main(String... s) throws Exception { 24 System.out.println("my pid is " + ProcessHandle.current().pid()); 25 } 26} 27EOH 28 } 29 } 30 31 task "pid" { 32 driver = "java" 33 config { 34 class_path = "${NOMAD_ALLOC_DIR}" 35 class = "Pid" 36 pid_mode = "host" 37 ipc_mode = "host" 38 } 39 } 40 } 41}