Ruby-Graphviz icon indicating copy to clipboard operation
Ruby-Graphviz copied to clipboard

Node image loading problems with Apache2 (passenger) due to environment variables

Open zealot128 opened this issue 11 years ago • 0 comments

When switching to passenger, we noticed, that our referenced node image paths where empty (white). Strange is, when running that same function via IRB, the images where included into the diagram correctly.

After hours of search, we found out, that Graphviz reads 2 environment variables SERVER_NAME and GV_FILE_PATH. http://www.graphviz.org/doc/info/command.html#d:GV_FILE_PATH

If SERVER_NAME is present (which apache sets automatically), than graphviz will not load any image from standard path. ->

            Warning: file loading is disabled because the environment contains:
            and there is no GV_FILE_PATH variable.
            Warning: "/tmp/pp-4.png" was not found as a file or as a shape library member
            Warning: No or improper image="/tmp/pp-4.png" for node "user1"

We "fixed" that by using a custom shell-out function (instead of using Graphviz#output)

        tempfile = Tempfile.new(["graph",".dot"])
        tempfile.write graph.to_s
        tempfile.close

        pngfile = Tempfile.new(["graph",".png"])
        pngfile.binmode

        cmd = "unset SERVER_NAME; circo #{tempfile.path} -Tpng  > #{pngfile.path}"
        `#{cmd}`

        blob = File.open(pngfile,"rb").read

if there is an option to remove that env var via another switch in Graphviz#output that would be great.

Otherwise, this issue description might save other people some time. :)

zealot128 avatar May 27 '13 17:05 zealot128