I’ve read every Haskell deploy thread I could find here and several on the wider web, but I still don’t get one thing. If I’ve compiled an app for my server, and can ssh in and run it, how do I go about running the thing? Assume I’m using an HTTP interface (not FastCGI).
For example, with node.js, we use cluster to get the app started on several processor cores, then create an init.d script for centOS to get the thing to run, daemonize, have a pid file, etc.
How do I do this for a Haskell app?
Since you don’t mention which framework you’re using, I’m just going to answer this question in general.
With Haskell, you don’t have to start multiple instances (in a cluster) of the web application, because if the application supports concurrency, it usually uses multiple threads internally. What you instead want to do, is to make sure that the application is compiled with the
-threadedand-rtsoptsflags. Then, when you run the application, you pass the flags+RTS -N<number of simultaneous threads>. If you use a Snap web application running on port 1234 on a 8-core computer with Intel® Hyper-Threading, for example, you would start it withmy-server -p 1234 +RTS -N16to get it to parallellize to up to 16 OS threads.To daemonize the web application, you use the same procedure as with node.js. You create an init script that starts the executable in various UNIX run modes, and Bob’s your uncle.
As with any other web application, you might want to use a front end server that redirects traffic to your web application (which is why you might not want to use port 80 for your web applications). For details on how to do this, visit the Web/Deploy page on HaskellWiki.