How to create a init-script for an Perl catalyst application running on nginx with fastcgi and perlbrew -
i'm looking initscript make usage of perlbrew on webserver running nginx proxy perl catalyst application. i'm trying start 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 appers cannot find local perl installation. $perlbrew set perlbrew folder.
this step step guide how this, french (but still understandable).
http://www.catapulse.org/articles/view/124
i copied here:
setup user going run catalyst app (www-data in 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 application name myapp, replace 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 runlevels # update-rc.d cat-myapp defaults $app_home = '/var/www/myapp'; $perl = 'perl'; $program = $app_home . '/script/myapp_fastcgi.pl'; $name = 'myapp'; $workers = 1; $pid_file = $app_home . '/myapp.pid'; $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 , create proper init file:
$ chmod +x myapp.fastcgi.initd $ ./myapp.fastcgi.initd get_init_file > /etc/init.d/cat-myapp
start application , bounce webserver:
$ /etc/init.d/cat-myapp start $ /etc/init.d/nginx restart