3 usage_help_text
="qrun [<OPTIONS>]
4 Run next task in the queue.
11 -E, --no-task-exit-code"
13 qrun_suppress_output
=''
14 qrun_return_task_status
=yes
24 for itemfile
in $
(find "$queue_dir" -maxdepth 1 -name '*.comm' -printf '%f\n' |
sort -n -t '.')
26 item_id
=`basename "$itemfile" .comm`
27 state
=`qtask_state "$item_id"`
29 if [ "$state" = running
]
31 # it's a running task. don't start any more.
34 pid
=`cat "$queue_dir/$item_id.pid"`
35 pidns
=`cat "$queue_dir/$item_id.pidns"`
36 this_pidns
=`readlink /proc/self/ns/pid`
37 if [ "$pidns" = "$this_pidns" ]
41 pidns_info
=" pidns=${pidns#*:}"
43 task_command
=`cat "$queue_dir/$item_id.comm" | { read -r -d $'\0' task_command rest; echo "$task_command"; }`
44 echo "qrun: task $item_id (pid=$pid$pidns_info cmd=$task_command) is running. not starting new one." >&2
49 if [ "$state" = queued
]
51 if [ -z "$next_item_id" ]
59 if [ -z "$next_item_id" ]
63 echo "qrun: no next item found to run" >&2
69 pwd=`cat "$queue_dir/$next_item_id.pwd"`
70 umask=`cat "$queue_dir/$next_item_id.umask"`
71 load_command_global
"$queue_dir/$next_item_id.comm"
79 pidfile
=$queue_dir/$next_item_id.pid
80 echo $BASHPID > "$pidfile"
81 readlink
/proc
/self
/ns
/pid
> "${pidfile}ns"
85 # lock our pidfile and release the lock on queue_dir
86 exec {task_lock_fd
}>>"$pidfile"
87 flock
--exclusive "$task_lock_fd"
90 if [ $qrun_suppress_output ]
96 # now we are turning into a task
97 .
"$queue_dir/$next_item_id.env.bash"
98 if [ -e "$queue_dir/$next_item_id.func.bash" ]; then .
"$queue_dir/$next_item_id.func.bash"; fi
102 # setsid prevents SIGINT to sent to us when the user types ctrl-c on the main foreground process,
103 # so leaving it to the main qrun process to reape our exit status.
104 exec -- setsid
"${command[@]}"
112 echo "qrun:${dryrun:+ DRYRUN} starting task $next_item_id, pid: $task_pid, command: ${command[*]}" >&2
115 # release the lock on queue_dir, letting other queue management happen while running the task
123 trap signal_handler INT
136 kill -s INT
$task_pid || true
147 echo -n $task_exit_code > "$queue_dir/$next_item_id.end"
151 echo "qrun: task $next_item_id returned $task_exit_code" >&2
154 if [ $qrun_return_task_status ]