3

I'm looking for a initscript to make usage of perlbrew on a webserver running a nginx as proxy for an perl catalyst application. I'm currently trying to start the app via

  source $PERLBREW
  execute "perlbrew use perl-5.14.4@devel"
  execute "mkdir -p $PID_PATH && $START_ICOS_APP > /dev/null  2>&1 &"
  echo "$DESC started"

but it appers it cannot find the local perl installation. $PERLBREW is set to my perlbrew folder.

frlan
  • 6,950
  • 3
  • 31
  • 72
  • what is "execute"? what does `perlbrew list` show? what errors do you see? – ysth Dec 08 '13 at 21:06
  • It's ok to run it as normal user, but I need an init-script doing the job here. And this I'm not getting to run :( – frlan Dec 09 '13 at 08:01
  • what runs the init-script? I'm not familiar with anything that has an execute command like that. – ysth Dec 09 '13 at 09:14
  • what do you mean it cannot find the local perl installation? what exactly *does* happen, what errors do you see? – ysth Dec 09 '13 at 09:15
  • and if you put in a perlbrew list before the perlbrew use line, what does that show? – ysth Dec 09 '13 at 09:15
  • I've got an init script located in /etc/init.d which shall be running catalyst for execution with nginx. Part of this script, executed by root, is this section posted before. But it appers it's not working with perlbrew. – frlan Dec 09 '13 at 09:16
  • what operating system and distribution is this? I've never seen "execute" like that in an init.d script. what happens if you leave it off and just say `perlbrew use perl-5.14.4@devel` on a line by itself? – ysth Dec 09 '13 at 09:18
  • It shall run under Debian Wheezy. This part is based upon gitlab's init script – frlan Dec 09 '13 at 09:20

1 Answers1

3

This is a good step by step guide how to do this, but it is French (but still understandable).

http://www.catapulse.org/articles/view/124

I copied here:

Setup the user which is going to run the catalyst app (www-data in this example)

su - www-data
curl -kL http://install.perlbrew.pl | bash
echo 'source ~/perl5/perlbrew/etc/bashrc' >> .profile
. .profile

perlbrew install perl-5.16.3 -Dusethreads --as perl-5.16.3_WITH_THREADS
perlbrew switch perl-5.16.3_WITH_THREADS
#perlbrew install-cpanm
#cpanm Catalyst Catalyst::Devel
#catalyst.pl myapp

(I assume that your application name is myapp, replace it with yours.)

create /etc/nginx/sites-enabled/myapp

server {
    listen 80;
    server_name exemple.com *.exemple.com;
    client_max_body_size 50m;

    location / {
      include /etc/nginx/fastcgi_params;
      fastcgi_param SCRIPT_NAME '';
      fastcgi_param PATH_INFO $fastcgi_script_name;
      fastcgi_pass unix:/var/www/myapp/myapp.socket;
    }

    location /static {
      root /var/www/myapp/root;
      expires 30d;
    }
}

Create /var/www/myapp/myapp.fastcgi.initd

#!/usr/bin/env perl
use warnings;
use strict;
use Daemon::Control;

# 1) create initd file
# ./myapp.fastcgi.initd get_init_file >  /etc/init.d/cat-myapp
#
# 3) install to runlevels
# update-rc.d cat-myapp defaults


my $app_home = '/var/www/myapp';
my $perl     = 'perl';
my $program  = $app_home . '/script/myapp_fastcgi.pl';
my $name     = 'myapp';
my $workers  = 1;
my $pid_file = $app_home . '/myapp.pid';
my $socket   = $app_home . '/myapp.socket';

Daemon::Control->new({
    name        => $name,
    lsb_start   => '$nginx',
    lsb_stop    => '$nginx',
    lsb_sdesc   => $name,
    lsb_desc    => $name,
    path        => $app_home . '/myapp.fastcgi.initd',

    user        => 'www-data',
    group       => 'www-data',
    directory   => $app_home,
    program     => "$perl $program --nproc $workers --listen $socket",

    pid_file    => $pid_file,
    stderr_file => $app_home . '/myapp.out',
    stdout_file => $app_home . '/myapp.out',

    fork        => 2,
})->run;

Set permission on files and create the proper init file:

$ chmod +x myapp.fastcgi.initd
$ ./myapp.fastcgi.initd get_init_file >  /etc/init.d/cat-myapp

Start your application and bounce your webserver:

$ /etc/init.d/cat-myapp start
$ /etc/init.d/nginx restart 
user1126070
  • 5,059
  • 1
  • 16
  • 15
  • So far it looks good -- fastcgi is starting. Only nginx is not yet finding the fastcgi-socket..... – frlan Dec 09 '13 at 17:11
  • fastcgi_pass unix:/var/www/myapp/myapp.socket; and my $socket = $app_home . '/myapp.socket'; are the same? – user1126070 Dec 10 '13 at 09:41
  • http://stackoverflow.com/questions/369850/how-can-i-run-perl-scripts-using-fastcgi-on-nginx?rq=1 see the answer – user1126070 Dec 10 '13 at 09:42