How to launch a deployed Haskell web application

I read every Haskell deployment thread I could find here, and several on a wider network, but I still don't understand. If I compiled an application for my server and can run it and run, how can I do it? Suppose I use an HTTP interface (not FastCGI).

For example, using node.js, we use a cluster so that the application runs on several processor cores, and then create an init.d script for centOS to get the item to run, daemonize, have a pid file, etc.

How to do this for a Haskell application?

+8
haskell
source share
2 answers

Since you are not indicating which structure you are using, I am just going to answer this question as a whole.

With Haskell, you do not need to run multiple instances (in a cluster) of a web application, because if the application supports concurrency, it usually uses multiple threads internally. Instead, you should make sure that the application is compiled with the -threaded and -rtsopts . Then, when you start the application, you pass the flags +RTS -N<number of simultaneous threads> . If you are using the Snap web application running on port 1234 on an 8-core Intelยฎ Hyper-Threading computer, for example, you must run it using my-server -p 1234 +RTS -N16 to get it parallelized to 16 threads OS

To demonstrate the web application, you use the same procedure as with node.js. You create an init script that runs the executable in various UNIX modes of operation, and your uncle's bob.

As with any other web application, you can use an external server that redirects traffic to your web application (therefore, you can not use port 80 for your web applications). For more information on how to do this, visit the HaskellWiki Web / Deploy page .

+6
source share

The three main Haskell web frameworks (Snap, Yesod, and Happstack) have the ability to send with a built-in web server. The traditional production deployment approach should probably use your OS engine to start the process as a daemon in an init script or similar. One easier solution I used was a script something like the following:

 while true; do echo Restarting at `date` | tee -a stdout.log stderr.log > /dev/null ./my_app 80 >> stdout.log 2>> stderr.log done 

I am running this script in the background. It is simply dead, so the script shell process itself never crashes. If the server crashes for any reason, this script automatically ensures that it reboots immediately. If you want to release a new version, just copy it on top of the my_app executable and send SIGHUP to the my_app process.

Seasoned sidedmins can shudder at something like that. I will not say that this is the best way to do this, but I have been doing the production application for several years with this approach, and it did a great job. As mentioned above, you can also configure this using an external proxy server so that your application does not run as root.

+2
source share

All Articles