如何为使用fastcgi和perlbrew在Nginx上运行的Perl催化剂应用程序创建初始化脚本 [英] How to create a init-script for an Perl catalyst application running on nginx with fastcgi and perlbrew

查看:94
本文介绍了如何为使用fastcgi和perlbrew在Nginx上运行的Perl催化剂应用程序创建初始化脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个初始化脚本,以在运行Nginx的Web服务器上使用Perlbrew作为Perl催化剂应用程序的代理.我目前正在尝试通过

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"

,但是它找不到本地的perl安装. $ PERLBREW设置为我的perlbrew文件夹.

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

推荐答案

这是一个很好的逐步指南,说明了如何进行此操作,但它是法语(但仍然可以理解).

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

我在这里复制

设置要运行催化剂应用程序的用户(在此示例中为www-data)

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

(我假设您的应用程序名称为myapp,请用您的应用程序名称替换.)

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

创建/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;
    }
}

创建/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;

设置文件权限并创建正确的初始化文件:

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

启动您的应用程序并启动Web服务器:

$ /etc/init.d/cat-myapp start
$ /etc/init.d/nginx restart 

这篇关于如何为使用fastcgi和perlbrew在Nginx上运行的Perl催化剂应用程序创建初始化脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆