如何在生产中运行Snap haskell webapp? [英] How to run Snap haskell webapp in production?

查看:110
本文介绍了如何在生产中运行Snap haskell webapp?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在生产Ubuntu服务器上安装了Snap / Haskell(在EC2上),并签出了我的项目 - 但是如何运行它?



I意思是,在本地,我从命令行运行它:

 项目名称-p 8000 

Snap是否带有自己的Web服务器(它看起来像),如果是的话,我该如何配置它作为某种守护进程运行?



任何提示?



编辑2:



他们说 wiki



< blockquote>

snap-server是一个HTTP服务器库,支持snap-core中定义的接口


$ b $在这里,haskell关于Haskell网络代码的部署/后端选项的wiki说:Snap:


包含自己的服务器。 查看网页/框架


如何?我将如何运行它自己的服务器?为什么我必须知道该死的事情的部署,如果我只是对编程感兴趣......



编辑:相关问题:部署使用Snap Framework的Haskell代码

$ b $好的,等一些挖掘

解决方案

问一个问题,这是我想出来的东西。

大创意



将您的Snap应用程序编译为二进制文件,然后在帮助中将其作为服务运行的暴发户

分步说明




  1. 编译你的web应用程序。为了这个例子,我们假定webapp位于 / home / john / webapps / mysite

      $ cd / home / john / webapps / mysite 
    $ cabal install
    ...
    为'mysite-0.1'预处理可执行'mysite` ...
    在/home/john/.cabal/bin中安装可执行文件

    正如我们所看到的那样,二进制文件位于 /home/john/.cabal/bin 中。您可以将它移动到您喜欢的任何地方,但我们会将它保留在那里。

  2. 在应用程序文件夹中创建一个日志,否则snap会抱怨: / p>

      $ mkdir / home / john / webapps / mysite / log 


  3. 现在我们将创建一个运行我们的webapp的服务。为此,我们将使用名为 upstart 的Ubuntu服务设施。
    $ b $ a)我们简单地通过在 / etc / init / 目录。我们称之为 mysite



    $ $ $ sudo vi / etc / init / mysite.conf



    现在让我们添加我们服务的描述:

     在启动时启动
    chdir / home / john / webapps / mysite
    exec /home/john/.cabal/bin/ mysite -p 80

    首先,我们说服务应该在启动(或启动时)系统。第二,由于snap需要 snaplets 和其他静态资源(比如我们之前创建的日志目录) - 我们告诉服务在我们项目的目录中运行。

    最后,我们指定实际上将作为服务运行的二进制文件: /home/john/.cabal/bin/mysite 。我们将 -p 80 参数传递给捕捉web服务器以使其在端口80上运行。(注意:必须禁用所有apache和nginx服务器,不再需要这个端口)


  4. 完成。您可以检查它是否正在运行,并在需要时手动启动它:

      initctl list | grep mysite 
    initctl start mysite



I've installed Snap/Haskell on my production Ubuntu server (on EC2), and checked-out my project - but how do I run it?

I mean, locally, I run it from command line:

project-name -p 8000

Does snap come with it's own web-server (it looks like it), and if so how do I go about configuring it to run as a daemon of some sort?

Any tips?

Edit 2:

On the wiki they say:

snap-server is an HTTP server library that supports the interface defined in snap-core.

While here, the haskell wiki about "Deployment/Backend options for your haskell web code" says that Snap:

includes its own server. see Web/Frameworks

But HOW? How would I run it's own server? Why must I know about deployment of the damn thing if I am just interested in programming...

Edit: related question: Deploy Haskell code that uses the Snap Framework

解决方案

Ok, so after some digging and asking, here is what I came up with.

Big idea

Compile your Snap application into a binary and then run it as a service with the help of upstart.

Step by Step

  1. Compile your webapp. For the sake of this example, we'll assume the webapp is at /home/john/webapps/mysite:

    $ cd /home/john/webapps/mysite
    $ cabal install
    ...
    Preprocessing executable 'mysite` for 'mysite-0.1'...
    Installing executable(s) in /home/john/.cabal/bin
    

    As we can see the, the binary is placed in /home/john/.cabal/bin. You may move it to any place you like, but we'll leave it there.

  2. Create a log in your application folder, otherwise snap will complain:

    $ mkdir /home/john/webapps/mysite/log
    

  3. Now we will create a service that will run our webapp. To do so we will use Ubuntu's service facility called upstart.

    a) We name our service simply by creating a conf file with the desired name in the /etc/init/ directory. Let's call it mysite:

    $ sudo vi /etc/init/mysite.conf
    

    b) Now let's add the description of what our service is:

    start on startup
    chdir /home/john/webapps/mysite
    exec /home/john/.cabal/bin/mysite -p 80
    

    First, we say that the service should run on startup (or on bootup) of the system.

    Second, since snap needs it's snaplets and other static resources (like the log directory we created earlier) - we tell the service to run inside our project's directory.

    Lastly, we specify the binary that actually will run as a service: /home/john/.cabal/bin/mysite. We pass the -p 80 parameter to the snap webserver to make it run on port 80. (Note: you have to disable all apache and nginx servers, so that they don't take up that port any more)

  4. Done. You can check if it is running and start it manually if you need to:

    initctl list | grep mysite
    initctl start mysite
    

这篇关于如何在生产中运行Snap haskell webapp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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