Linux bash & cfexecute & Lucee

541 views
Skip to first unread message

Ivan

unread,
Mar 2, 2016, 6:32:07 PM3/2/16
to Lucee
Hi,
I can not fix this problem:

cfhttp.cfm:
<cfexecute name="bash" arguments="/var/www/website/import/sh/mozjpeg.sh #NuovaImg#" timeout="600" variable="result" />




bash script mozjpeg.sh:
#!/bin/bash
/opt/mozjpeg/bin/cjpeg -quality 80 /var/www/website/tmp/_$1.jpg > /var/www/website/tmp/_moz_$1.jpg



When I start for the first time cfhttp.cfm get this error:




If I run the second time (I update the page) the problem goes away (Jpeg file is created correctly)! This in all situations.
I tried to run bash /var/www/website/import/sh/mozjpeg.sh _97341 from the shell and it works the first time.


How can I fix?

Igal @ Lucee.org

unread,
Mar 2, 2016, 6:55:11 PM3/2/16
to lu...@googlegroups.com
are you sure that the file exists and that there are no permissions issues when you call cfexecute?

try to check with calling <cfdump eval='fileExists("/var/www/website/tmp/_#NuovaImg#.jpg")'> before calling execute. 

when you run the bash from shell then you are most likely doing it under a different user, so possibly permission issues at play here.

Igal Sapir
Lucee Core Developer
Lucee.org

--
Love Lucee? Become a supporter and be part of the Lucee project today! - http://lucee.org/supporters/become-a-supporter.html
---
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/c8a4a6f4-8a83-464d-aa8d-f321806e53f0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ivan

unread,
Mar 3, 2016, 3:20:13 AM3/3/16
to Lucee
Hi Igal,
I included fileExists() before cfexecute. At the first run return false. If I update,  return true.

Ivan

unread,
Mar 3, 2016, 3:36:58 AM3/3/16
to Lucee
I may have found where the error...

Before <cfexecute name="bash" arguments="/var/www/website/import/sh/mozjpeg.sh #NuovaImg#" timeout="600" variable="result" /> I have others cfexecute. It 'possible that the first are not completed and the seconds fail.

I do the tests.

Ivan

unread,
Mar 3, 2016, 4:08:55 AM3/3/16
to Lucee
I confirm. It would seem that so many cfexecute one after the other is not good. I grouped all in a bash file.

Robert Munn

unread,
Mar 3, 2016, 11:49:21 PM3/3/16
to lu...@googlegroups.com
I wonder is there a way to instantiate a shell and keep it resident in memory across cfexecute commands, or through some other as yet unbuilt feature?  Could be very useful in a case like Ivan’s where multiple commands need to be run. I know I have written code that used multiple shell commands in a single method,, and it would seem like a good thing for commands that are going to be executed in sequence within the same context/thread be able to share the same instance of the shell.

FYI, I know in Ivan’s case he was able to solve his issue by putting all the commands in a single sh file, but there would invariably be cases where that solution doesn’t work because other things are going on inside the code in between individual shell calls.

Is this issue resonating with anyone else? I have been pining for a better method of CLI integration than what cfexecute has always offered. Looking at the Java.lang.Runtime class, it doesn’t look like there is a way to persist a process within the context of an exec() method call, but maybe some of the more expert Java coders know something I don’t about it.

I know you can do something like this:

process_runtime = local.runtime.getRuntime();
process_exec = local.process_runtime.exec( javacast( "string[]", ["bash", "-c", str ]) );
exitCode = local.process_exec.waitFor();
process_exec2 = local.process_runtime.exec( javacast"string[]", ["bash""-c", str2 ]) );
exitCode = local.process_exec.waitFor();

but you are still instantiating a new bash shell with each .exec() method call.

I realize leaving it open could be playing with fire and maybe that’s why java.lang.Runtime calls each exec() in a separate process. It just seems like there should be a better way to integrate with the shell than what currently exists.

Robert




On Mar 3, 2016, at 1:08 AM, Ivan <ivan....@gmail.com> wrote:

I confirm. It would seem that so many cfexecute one after the other is not good. I grouped all in a bash file.

--
Love Lucee? Become a supporter and be part of the Lucee project today! - http://lucee.org/supporters/become-a-supporter.html
---
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.

Michael Sprague

unread,
Mar 4, 2016, 12:13:56 AM3/4/16
to lucee
Don't have an answer to your question but in cases when an existing/static sh file won't suffice couldn't one be written dynamically and then executed? Just a thought.

Mike

Robert Munn

unread,
Mar 6, 2016, 1:51:48 PM3/6/16
to lu...@googlegroups.com
Maybe. I am specifically thinking about a use case where some processes have to be run inside the Lucee environment in between executions of shell scripts. You can use the script version I showed below to get stdout and stderr if the process returns correctly, but it will still close the shell after executing. 

The solution I have found is to connect to the console via an SSH client like Ganymede http://www.ganymed.ethz.ch/ssh2/

You can instantiate an SSH session and pass it commands to execute, then close the session when done. That does not seem like it would scale, though.

Denard Springle

unread,
Mar 7, 2016, 5:30:03 PM3/7/16
to Lucee
cfexecute doesn't scale, period. 1000 cfexecutes will bring your system to a halt. Furthermore, when doing anything file system intensive, cfexecute will often return before i/o is actually complete, further complicating processing within CFML, and often requiring logic that not just waits for the files existence, but it's completion.

At the end of the day, cfexecute is not, generally, a good option. The best options are generally finding a .jar that does what you want and implementing that instead of going to the OS level. For apps that don't have many concurrent users (e.g. admin interfaces) cfexecute is fine, but if you need to scale, its just not the right tool for the job :)

-- Denny

Risto

unread,
Mar 9, 2016, 2:01:30 PM3/9/16
to Lucee
Robert, would you have time to post a little snippet of how you use Ganymede?
Reply all
Reply to author
Forward
0 new messages