How to deploy perl dancer app with cgi and calling external scripts?

646 Views Asked by At

I have had a webapp using CGI implementation. It basically uses system() calls to launch other programs and the results will be rendered in html.

Now, I am trying to implement it using Dancer. In order to run these external programs, I created a "scripts" directory in /MyApp, so it's like /MyApp/scripts. I put all my other scripts there, which will be called in a route handler.

get '/analysis' => sub {
    if (session('user')  && session('logged_in')) {
    open FH, "<", "./scripts/test.out";
    my $msg = <FH>;
    close FH;
    chdir ("./scripts");
    system("call sth"); #call external programs to generate a "test.png"
    my $err;
    copy ("test.png", "../public/images/test.png") || ($err = "cannot copy"); #copy the "test.png" to public/images directory, so the 
    my $img = "test.png";
       template 'analysis',{msg => $msg, img => $img, err => $err};
    }
    else {
    return redirect '/'
   }

};

However, I can launch this app successfully as a standalone or using plackup/starman. But I can not deploy it with CGI. I did every step using dancer's doc regarding cgi deployment. I can successfully using cgi to launch dancer's example app. but when I tried to launch my own as above, I always got the error:

app directory '/home/tester/MyApp/bin/..' isn't writable/executable and can't chmod it at /usr/local/share/perl/5.14.2/Dancer/Logger.pm line 16, referer:localhost

It seems a permission problem, but I don't know how to fix it. Is there a better way to launch an external program from route handler? where should I store these external programs, thus they can be executed by the dancer app when it was deployed as CGI.

Could anyone help me? Thanks.

Xiaokuan

1

There are 1 best solutions below

0
On

Dancer::Logger::File documentation says:

It's possible to specify a logs directory with the log_path option.

     setting log_path => $dir;

Simply add a line to your (production.yml) environment file:

log_path: /var/log/dancer/myapp/

and make this path writable to www-data.