X-Git-Url: http://git.annexia.org/?p=whenjobs.git;a=blobdiff_plain;f=daemon%2Fdaemon.ml;h=6ccfcce983606075b6457c7c433763fdf4ab8da6;hp=47a67ed0443b2400a07c6b92a2e8f7d4ef3232a2;hb=0bfe72d06b55b0db076c900c6c2173b59c8b75f3;hpb=65b5a307fc1c55a197ee337180842ac6885ba784 diff --git a/daemon/daemon.ml b/daemon/daemon.ml index 47a67ed..6ccfcce 100644 --- a/daemon/daemon.ml +++ b/daemon/daemon.ml @@ -198,7 +198,7 @@ and reload_file () = dependencies := map in (* Re-evaluate all when jobs. *) - reevaluate_whenjobs (StringMap.keys !jobs); + reevaluate_whenjobs ~onload:true (StringMap.keys !jobs); (* Schedule the next every job to run. *) schedule_next_everyjob () @@ -207,7 +207,7 @@ and reload_file () = * a fixpoint. Run those that need to be run. every-statement jobs * are ignored here. *) -and reevaluate_whenjobs jobnames = +and reevaluate_whenjobs ?(onload=false) jobnames = let rec loop set jobnames = let set' = List.fold_left ( @@ -218,7 +218,7 @@ and reevaluate_whenjobs jobnames = assert (jobname = job.job_name); let r, job' = - try job_evaluate job !variables + try job_evaluate job !variables onload with Invalid_argument err | Failure err -> Syslog.error "error evaluating job %s (at %s): %s" jobname (Camlp4.PreCast.Ast.Loc.to_string job.job_loc) err; @@ -353,12 +353,15 @@ and run_job job = (* Create a temporary file containing the shell script fragment. *) let script = dir // "script" in let chan = open_out script in + fprintf chan "set -e\n"; (* So that jobs exit on error. *) output_string chan job.job_script.sh_script; close_out chan; chmod script 0o700; + let shell = try getenv "SHELL" with Not_found -> "/bin/sh" in + (* Execute the shell script. *) - (try execvp "bash" [| "bash"; "-c"; script |]; + (try execvp shell [| shell; "-c"; script |]; with Unix_error (err, fn, _) -> Syslog.error "%s failed: %s: %s" fn script (error_message err) );