-batch mode: X11 connection required?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

-batch mode: X11 connection required?

Mark J. Chopping
Greetings list,

I am running macros in -batch mode on a linux virtual machine (Debian 8.1 "jessie") and it seems that an X11 connection is required: is this correct?

It would be good to be able to background a whole bunch of jobs in one VM with nohup or & and then log out of the VM and into another one (i.e., quitting the interactive shell and ultimately the remote session). The command I am using is something like:

~/ImageJ/jre/bin/java -Xmx2048m -jar ~/ImageJ/ij.jar -ijpath ~/ImageJ -batch thisone.ijm arg1:arg2> ~/logs/todays_log &

Am I missing something obvious, or is there no way to do this? Thanks.

 Mark

Mark Chopping
Montclair State University

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: -batch mode: X11 connection required?

ctrueden
Hi Mark,

> I am running macros in -batch mode on a linux virtual machine (Debian
> 8.1 "jessie") and it seems that an X11 connection is required: is
> this correct?

ImageJ 1.x does not support running headless. You must use the headless
mode of ImageJ2:

   http://imagej.net/Headless

And note that it comes with many caveats and limitations.

Or you can use xvfb, which comes with its own set of caveats and
limitations, too.

Regards,
Curtis


On Thu, Aug 20, 2015 at 3:42 PM, Mark Chopping <
[hidden email]> wrote:

> Greetings list,
>
> I am running macros in -batch mode on a linux virtual machine (Debian 8.1
> "jessie") and it seems that an X11 connection is required: is this correct?
>
> It would be good to be able to background a whole bunch of jobs in one VM
> with nohup or & and then log out of the VM and into another one (i.e.,
> quitting the interactive shell and ultimately the remote session). The
> command I am using is something like:
>
> ~/ImageJ/jre/bin/java -Xmx2048m -jar ~/ImageJ/ij.jar -ijpath ~/ImageJ
> -batch thisone.ijm arg1:arg2> ~/logs/todays_log &
>
> Am I missing something obvious, or is there no way to do this? Thanks.
>
>  Mark
>
> Mark Chopping
> Montclair State University
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: -batch mode: X11 connection required?

Mark J. Chopping
In reply to this post by Mark J. Chopping
Thanks Curtis, I will look into xvfb. Cheers, Mark

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: -batch mode: X11 connection required?

Mark J. Chopping
In reply to this post by Mark J. Chopping
Hi Curtis, list,

I have had success using xvfb -- and specifically xvfb-run called from a script xvfb-run-safe by Charles Duffy via StackOverFlow, quote;

"...let's write our own code to find a free display number, instead of assuming that xvfb-run -a will work reliably:

#!/bin/bash

# allow settings to be updated via environment
: "${xvfb_lockdir:=$HOME/.xvfb-locks}"
: "${xvfb_display_min:=99}"
: "${xvfb_display_max:=599}"

# assuming only one user will use this, let's put the locks in our own home directory
# avoids vulnerability to symlink attacks.
mkdir -p -- "$xvfb_lockdir" || exit

i=$xvfb_display_min     # minimum display number
while (( i < xvfb_display_max )); do
  if [ -f "/tmp/.X$i-lock" ]; then                # still avoid an obvious open display
    (( ++i )); continue
  fi
  exec 5>"$xvfb_lockdir/$i" || continue           # open a lockfile
  if flock -x -n 5; then                          # try to lock it
    exec xvfb-run --server-num="$i" "$@" || exit  # if locked, run xvfb-run
  fi
  (( i++ ))
done

If you save this script as xvfb-run-safe, you can then invoke:

xvfb-run-safe python script.py

...and not worry about race conditions so long as no other users on your system are also running xvfb. " </quote>

Link: http://stackoverflow.com/questions/30332137/xvfb-run-unreliable-when-multiple-instances-invoked-in-parallel

In my case (on Debian linux VMs), the calls look like:

xvfb-run-safe ~/ImageJ/jre/bin/java -Xmx2048m -jar ~/ImageJ/ij.jar -ijpath ~/ImageJ -batch mymacro.ijm arg1:arg2 > /dev/null &
xvfb-run-safe ~/ImageJ/jre/bin/java -Xmx2048m -jar ~/ImageJ/ij.jar -ijpath ~/ImageJ -batch mymacro.ijm arg3:arg4 > /dev/null &
xvfb-run-safe ~/ImageJ/jre/bin/java -Xmx2048m -jar ~/ImageJ/ij.jar -ijpath ~/ImageJ -batch mymacro.ijm arg5:arg6 > /dev/null &
....

The redirect to /dev/null is required because the macro outputs intermediate Results tables as well as my logging statements written with print(), so output to stdout is too massive and hard to use.

I thought this might be useful to someone down the road.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: -batch mode: X11 connection required?

ctrueden
Thanks Mark, I added a link to http://imagej.net/Headless#Xvfb

On Wed, Aug 26, 2015 at 12:56 PM, Mark Chopping <
[hidden email]> wrote:

> Hi Curtis, list,
>
> I have had success using xvfb -- and specifically xvfb-run called from a
> script xvfb-run-safe by Charles Duffy via StackOverFlow, quote;
>
> "...let's write our own code to find a free display number, instead of
> assuming that xvfb-run -a will work reliably:
>
> #!/bin/bash
>
> # allow settings to be updated via environment
> : "${xvfb_lockdir:=$HOME/.xvfb-locks}"
> : "${xvfb_display_min:=99}"
> : "${xvfb_display_max:=599}"
>
> # assuming only one user will use this, let's put the locks in our own
> home directory
> # avoids vulnerability to symlink attacks.
> mkdir -p -- "$xvfb_lockdir" || exit
>
> i=$xvfb_display_min     # minimum display number
> while (( i < xvfb_display_max )); do
>   if [ -f "/tmp/.X$i-lock" ]; then                # still avoid an obvious
> open display
>     (( ++i )); continue
>   fi
>   exec 5>"$xvfb_lockdir/$i" || continue           # open a lockfile
>   if flock -x -n 5; then                          # try to lock it
>     exec xvfb-run --server-num="$i" "$@" || exit  # if locked, run xvfb-run
>   fi
>   (( i++ ))
> done
>
> If you save this script as xvfb-run-safe, you can then invoke:
>
> xvfb-run-safe python script.py
>
> ...and not worry about race conditions so long as no other users on your
> system are also running xvfb. " </quote>
>
> Link:
> http://stackoverflow.com/questions/30332137/xvfb-run-unreliable-when-multiple-instances-invoked-in-parallel
>
> In my case (on Debian linux VMs), the calls look like:
>
> xvfb-run-safe ~/ImageJ/jre/bin/java -Xmx2048m -jar ~/ImageJ/ij.jar -ijpath
> ~/ImageJ -batch mymacro.ijm arg1:arg2 > /dev/null &
> xvfb-run-safe ~/ImageJ/jre/bin/java -Xmx2048m -jar ~/ImageJ/ij.jar -ijpath
> ~/ImageJ -batch mymacro.ijm arg3:arg4 > /dev/null &
> xvfb-run-safe ~/ImageJ/jre/bin/java -Xmx2048m -jar ~/ImageJ/ij.jar -ijpath
> ~/ImageJ -batch mymacro.ijm arg5:arg6 > /dev/null &
> ....
>
> The redirect to /dev/null is required because the macro outputs
> intermediate Results tables as well as my logging statements written with
> print(), so output to stdout is too massive and hard to use.
>
> I thought this might be useful to someone down the road.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: -batch mode: X11 connection required?

Thomas Julou
In reply to this post by Mark J. Chopping
Dear Mark,

Thank you so much for solving an issue that I was suspecting but had not diagnosed properly yet! And even more so before I wrote about it to the list!

> On 27 Aug 2015, at 04:43, IMAGEJ automatic digest system <[hidden email]> wrote:
>
> I have had success using xvfb -- and specifically xvfb-run called from a script xvfb-run-safe by Charles Duffy via StackOverFlow: http://stackoverflow.com/questions/30332137/xvfb-run-unreliable-when-multiple-instances-invoked-in-parallel <http://stackoverflow.com/questions/30332137/xvfb-run-unreliable-when-multiple-instances-invoked-in-parallel>

Best,
Thomas

--
Thomas Julou  |  Computational & Systems Biology  |  Biozentrum – University of Basel  |  Klingelbergstrasse 50/70 CH-4056 Basel  |  +41 (0)61 267 16 21


--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html