How to run Yesod apps for actual services

401 views
Skip to first unread message

Kazu Yamamoto

unread,
Apr 10, 2012, 6:02:26 AM4/10/12
to yeso...@googlegroups.com
Hello,

I read the book but I cannot find how to run Yesod apps for actual
services.

In short I would like to ask:
Q1) Where should we run Yesod apps
Q2) How to deamonize Yesod apps

1)

"yesod init" says that "cd foo && cabal install". This
means that Yesod application "foo" is installed to the cabal
directory.

We develop the application with "yesod devel".

For service in, I would like to compile it. [1] recommends
"cabal clean && cabal configure && cabal build". So, we have
"dist/build/foo/foo".

If we run "dist/build/foo/foo" in the top of scaffold directory
("foo"), this Yesod app works because "config/setting.yml" exists.

So, it seems to me that Yesod team assumes that a complied app should
be run in the top of scaffold directory.

But what about the Yesod app installed in the cabal directory?  If
this is not necessary, I would suggest to print "cabal install
--only-dependencies".

2)

And if my understanding is correct, Yesod apps cannot be daemonized by
itself. Should users run Yesod apps with, for instance, the "screen"
command?

Cheers,

[1] http://www.yesodweb.com/book/deploying-your-webapp

--Kazu

Arash Rouhani

unread,
Apr 10, 2012, 7:31:29 AM4/10/12
to yeso...@googlegroups.com
Hi Kazu,

I've a little unprofessional site running of my own. For
servicization/deamonizing I simply created a so called `init.d` script,
and for deploying I've made a simple bash-alias that compiles and
replaces and restarts the yesod daemon. Effectively this means that my
yesod site starts automatically at boot up and I can also easily restart it.

This was the first time I dealt with init.d scripts and I think I got it
working alright. Here are some very unpolished pastes of the code I
effectively use.

init.d-script: https://gist.github.com/1e2534545cbf9a7e788a
deployment-aliases:
https://github.com/Tarrasch/dotfiles/blob/dtek/zsh/zsh_aliases#L53-63

In the above unpolished scripts "dp", "dportalen" and "DtekPortalen"
basically is the name of my yesod project, so it should be changed to
whatever you call yours respectively. Note that the deployment script
also compiles the site, VPSs usually can't handle that.

Also, one needs to install the init.d script, I once found and used a
command that easily could install/uninstall init.d-scripts, but I can't
find it anymore :/


So this is how I solved deployment of my yesod service, and I'm
interested to know how other people have solved this, or if there is any
official recommendations in the community.

Best Wishes,
Arash Rouhani

crosser

unread,
Apr 10, 2012, 9:20:40 AM4/10/12
to yeso...@googlegroups.com
In case you love adventure, this is how I was able to deploy a Yesod app under Apache fastcgi:

http://www.average.org/YBother/static/txt/Apache-fcgid.howto.txt

Eugene

Michael Snoyman

unread,
Apr 10, 2012, 10:32:22 AM4/10/12
to yeso...@googlegroups.com
On Tue, Apr 10, 2012 at 1:02 PM, Kazu Yamamoto <kazu.y...@gmail.com> wrote:
> Hello,
>
> I read the book but I cannot find how to run Yesod apps for actual
> services.
>
> In short I would like to ask:
> Q1) Where should we run Yesod apps
> Q2) How to deamonize Yesod apps
>
> 1)
>
> "yesod init" says that "cd foo && cabal install". This
> means that Yesod application "foo" is installed to the cabal
> directory.
>
> We develop the application with "yesod devel".
>
> For service in, I would like to compile it. [1] recommends
> "cabal clean && cabal configure && cabal build". So, we have
> "dist/build/foo/foo".
>
> If we run "dist/build/foo/foo" in the top of scaffold directory
> ("foo"), this Yesod app works because "config/setting.yml" exists.
>
> So, it seems to me that Yesod team assumes that a complied app should
> be run in the top of scaffold directory.
>
> But what about the Yesod app installed in the cabal directory?  If
> this is not necessary, I would suggest to print "cabal install
> --only-dependencies".

Yes, that probably makes more sense. I've avoided using that command
just because it's longer and (theoretically) more confusing to new
users. You're hitting the opposite problem: an experienced user
getting confused by the overly-simplified command. I got similar
comments on the book.

>
> 2)
>
> And if my understanding is correct, Yesod apps cannot be daemonized by
> itself. Should users run Yesod apps with, for instance, the "screen"
> command?

I've personally been using angel recently. But yes, the idea would be
to use some kind of monitoring daemon. I've got some deployment
scripts[1] that I use in my newer setups. It works, but it's not yet
completely polished.

Michael

[1] https://github.com/yesodweb/deploy

Vagif Verdi

unread,
Apr 10, 2012, 1:55:54 PM4/10/12
to yeso...@googlegroups.com
Here's how i setup my yesod app in production:

1. create folder /srv/awesome-app
2. Move necessary files there (static folder, config folder)
3. create a bin folder in there
4. drop your app exe into a bin folder. I usually name them like awesome-app-2012-04-10-1
5. create a bash script in the /srv/awesome-app/ folder

#!/bin/bash

cd /srv/awesome-app

exec bin/awesome-app-2012-03-19-1 Production +RTS -N 2>&1 | logger -p local3.info

The parts after -N is for logging using syslog-ng. You can remove them if you do not need that.

And finally.

put this into your /etc/inittab file:

z1:2345:respawn:/srv/awesome-app/start-app
 
This will start your app on boot, and also restart it if it crashes.

How to update it ?

1. Put new exe awesome-app-2012-04-10-2 into /srv/awesome-app/bin folder.
2. Change the start-app script to refer to the new exe.
3. kill the current app. The new app will start automatically.

Drew Haven

unread,
Apr 10, 2012, 9:22:38 PM4/10/12
to yeso...@googlegroups.com
I wish I could just copy the files up, but my server runs an older
version of libgmp than my devel box, so the binary complains about a
lack of libgmp.so.10 if I just copy it. As such my deployment process
looks like:

git pull && cabal clean && cabal configure && cabal build

Then I just restart the various app instances.

I haven't bothered to automate it. I'm wondering if there is a trick
to get around my library issues.

It's all behind an Apache instance through a reverse proxy. I don't
have enough load that I've had to do static content through Apache.

Drew Haven
drew....@gmail.com

Michael Snoyman

unread,
Apr 11, 2012, 12:12:19 AM4/11/12
to yeso...@googlegroups.com
My trick for the library issue is to compile in a virtual machine.
Just install the same OS as is running on your server, and there
shouldn't be any library issues. It's a bit of a pain, but it's not
too bad.

Michael

Drew Haven

unread,
Apr 11, 2012, 3:18:01 AM4/11/12
to yeso...@googlegroups.com
That's basically what I'm doing now. I build on one server (which
happens to be virtualized) and then copy to the other.

I love that I can do the whole build without affecting the running
server, so the downtime is pretty low. The differences between the
production and dev systems is small enough that I'm not worried about
the restart issue. Also, I have the alternate and my traffic isn't
large yet, otherwise I might dedicate a box for build/testing.

Drew Haven
drew....@gmail.com

Kazu Yamamoto

unread,
Apr 11, 2012, 11:25:51 PM4/11/12
to yeso...@googlegroups.com
Thank you for reply to everyone.

I would use "angel" to deploy Yesod apps.

--Kazu
Reply all
Reply to author
Forward
0 new messages