From Rails to Erlyweb - Part II

Updated Aug 23: Please see From Rails to Erlyweb - Part II Manage Project - Reloaded

Updated July 15: store the database configuration in <opaque> session of yaws.conf

Updated May 2: erlweb:compile(AppDir::string(), Options::[option()]) has option: {auto_compile, Val}, where Val is 'true', or 'false'. In case of development, you can turn on {auto_compile, true}. So, you only need to run erlyweb_app:boot(myapp) once.

2. Manage project

Erlyweb provides erlyweb:compile(App, ..) to compile the source files under app directory. To start an app, you usually should erlydb:start(mysql, ....) and compile app files first. To make life easy, you can put some scripting like code under myproject\script directory. Here's my project source tree:

myproject
  + apps
  |   + myapp
  |       + ebin   
  |       + include
  |       + nbproject
  |       + src
  |           + components
  |           + lib
  |           + services
  |       + test
  |       + www
  + config
  |   * yaws.conf
  + script
      + ebin
      + src
           * erlyweb_app.erl

Where, config/yaws.conf contains the confsiguration that will copy/paste to your real yaws.conf file. Here's mine:

## This is the configuration of apps that will copy/paste to your yaws.conf.

ebin_dir = D:/myapp/trunk/script/ebin
ebin_dir = D:/myapp/trunk/apps/myapp/ebin

<server localhost>
	port = 8000
	listen = 0.0.0.0
	docroot = D:/myapp/trunk/apps/myapp/www
	appmods = </myapp, erlyweb>
	<opaque>
		appname = myapp
		hostname = "localhost"
		username = "mememe"
		password = "pwpwpw"
		database = "myapp_development"	
        </opaque>
</server>

You may have noticed, all beams under D:/myapp/trunk/script/ebin and D:/myapp/trunk/apps/myapp/ebin will be auto-loaded by yaws.

erlyweb_app.erl is the boot scripting code, which will be used to start db connection and compile the code. Currently I run these scripts manually. I'll talk later.

-module(erlyweb_app).

-export([start/1]).

-export([main/1, 
	 boot/1, 
	 build/1, 
	 decompile/2
        ]).

-include("yaws.hrl").

%% @doc call back funtion when yaws start an app  
%% @see man yaws.conf
%%      start_mod = Module
%%          Defines  a  user  provided  callback  module.  At startup of the
%%          server, Module:start/1 will  be  called.   The  #sconf{}  record
%%          (defined  in  yaws.hrl) will be used as the input argument. This
%%          makes it possible for  a  user  application  to  syncronize  the
%%          startup  with  the  yaws  server as well as getting hold of user
%%          specific  configuration  data,  see  the  explanation  for   the
%%          

To build it,

> erlc -I /opt/local/lib/yaws/include erlyweb_app.erl

The erlyweb_app.erl is almost escript ready, but I use it as module functions currently. It's pre-compiled and erlyweb_app.beam is placed under script/ebin

So, I start myapp by steps:

cd \myproject
yaws -i -sname yaws
1> erlyweb_app:build(myapp).

The erlyweb_app.erl is almost escript ready, but I use it as module functions currently. It's pre-compiled and erlyweb_app.beam is placed under script/ebin

After I made changes to myapp, I run above erlyweb_app:build(myapp). again, then everything is up to date.

This is surely not the best way to handle the write-compile-run-test cycle, I'll improve the scripting to let starting yaws as a node, then hot-swap the compiled code to it.

It's a good experience to play with Rails, I like rake db:migrate, script, config folders of Rails. And Grails also brings some good idea to manage web app project tree. I'll try to bring them into project manager of ErlyBird.

Next part, I'll talk about the magic behind Erlyweb, and why I prefer the magic of Erlyweb to Rails.

Comments

1. malcontent -- 2007-05-01 16:00

One thing I don't like about rails is the "one project per machine" presumption it makes. Does erlyweb allow you to set up multiple projects under the same root with each one responding to a different subdomain?

2. Caoyuan -- 2007-05-01 16:00

malcontent,

I think so.

First, you can create multiple-apps under erlyweb apps directory, for instance: apps/myapp1 apps/myapp2

Second, you can configure your apps via yaws.conf as virtual servers, by giving them different 'listen = www.domain1.com', 'listen = www.domain2.com' with corresponding 'docroot = .../myapp1/www', 'docroot = .../myapp2/www' etc.

I did not test this upon real domains yet, correct me if I'm wrong.

3. malcontent -- 2007-05-01 16:00

Is there a development, testing and production yaws.conf file? For example if I am developing on windows and deploying to linux or mac I might have different paths to erlang bin directory.

4. Caoyuan -- 2007-05-01 16:00

malcontent,

Not yet. Currently, you need to switch the dev, test, production environment manually . But, we can add these features via Erlware, which uses json as the configuration files format.

5. El Mocomabo -- 2007-05-01 16:00

I think copying Rail's horrible direcotry strucutre and "philosophy" (if it can even be called that) is a mistake from the git-go .

I wish ErlyWeb? would build on the strengths of Erlang rather than just "following" the rails MVC fad. I hope they are not trying to attract the rails crowd because believe me, its no picnic and you will regret it!

Anyhoo, the only thing rails really offers is a little moresensible way of organizing your code, but lately due to proliferation of genration, things are getting out of hand.

Maybe ErlyWeb? devs (mainly Yariv right now) can be inspired by it but not follow it (rails) to the hilt.

6. Pierre R -- 2007-05-03 16:00

I have trouble using the standalone erlybird plugin on linux. The script seems full of mistakes. I have tried to solve some of them but it cascades everywhere. I have a strange error with a meta character (I need to copy/paste another #!/bin/sh and then I have lot of errors with closing strings. These ones are real script error I would think.

If you have some time to look at your unix script file ...

Looks promising.

Thanks

7. Zigo -- 2007-05-04 16:00

Caoyuan,

What is meant by hot-deploying (?) in Erlang? Isn't it the same things as in Ruby (modify code, F5, see changes)?

Also, isn't the scalability problems of Ruby due to its inability to talk to more than one database, and not threading, etc. issues?

Cheers, Zigo

8. 思迷思 -- 2007-05-05 16:00

http://tsking.cn/ 建议大家下载使用,绝不逊于一般国外工具,其中的策略部分更具中国特色。 其中实现了将数据通过ODBC导入专业数据库的功能。 (受兄的影响,我们也在进步啊)

9. Caoyuan -- 2007-05-08 16:00

Pierre,

escript source file is not supported yet, I'll support it in next release.

10. anonymous -- 2007-05-08 16:00

Zigo,

Hot-deploying in Erlang means a lot of things. In Erlang, you can run an Erlang application as a "node", which is actually a standalone vm, there can be a lot of nodes in your local computer or remote hosts. Then, you can hot-deploying new code to any local/remote nodes from any trusted nodes.

11. Caoyuan -- 2007-05-08 16:00

思迷思,

我有空会去看看你们的工作。

12. coach factory outlet -- 2012-03-31 05:55

No one can deny the shopping at the coach factory outlet is satisfactory. For the low prices and good quality.Over the years, coach factory online has added a multitude of new handbag shapes, styles and materials to their collection. However, the highest care is taken that every Coach handbags is both aesthetically beautiful and functional.Many fashionable women match with practical Coach Purses which will make the street shopping become relaxed,and make every person can enjoy more diversiform combination in coach factory outlet online.

http://www.ccoachfactoryoutlet.com

13. louis vuitton sale -- 2012-03-31 05:56

Don't feel upset, there will be a great conversion to this kind of situation because there are a large number of louis vuitton sale now!louis vuitton outlet,welcome to buy urban louis vuitton on our online shop.discount price is our special offer, durability and high quality is our promise.louis vuitton Outlets offer famous classic brand for LV,Channel, with perfect service.So become to the VIP soon.They offer more new styles,like LV purses,LV wallets etc. And are tested by product quality monitoring center .

http://www.louisvuittonoutletsaleo.com

14. coach outlet online -- 2012-03-31 05:56

Turn your attention to such discount coach sneakers for women from coach outlet online, you will find something unique and special of such authentic coach for sale at coach factory outlet store online.coach outlet store sells goods that are constructed to meet the highest standards of quality and functionality.You can trust it 100 percent.coach outlet has become a popular shopping experience for consumers around the world, and a desirable distribution channel for manufacturer's and retailers.

http://www.coachoutletonlinesl.com

15. louis vuitton uk -- 2012-03-31 06:13

Our online store offers you discounted Designer louis vuitton replica wallet at present. You could find them in desirable quality and price. If you don't mind high class louis vuitton uk, have a good time here.These is the first time your visit our louis vuit Louis vuitton online shop ,welcome.

http://www.louisvuittonukk.org.uk

16. louis vuitton outlet -- 2012-03-31 06:14

any louis vuitton outlet New backpack features usa a function grownup overall look. Varied piece allows that it is captivated me within the approve and also further than your body.It’s induced by way of severe hardworking liver diseases, and also the most familiar factors behind constant louis vuitton bags outlet hard working liver disorder usually are excessive drinking and also liver disease Chemical.Ladies have an ardent love for the Louis Vuitton handbags outlet because Louis Vuitton enjoys a worldwide reputation of high quality and fashionable designs.

http://www.louisvuittonoutletbagsc.com

17. coach outlet store online -- 2012-03-31 06:18

coach outlet store online marketed properly all greater compared to earth and earn cozy praise from customers. They are made from the finest leather and fabric.coach outlet store have Coach handbags,Coach Shoulder Bags,Coach Briefcases and so on,these bags are so perfectly reproduced,you won't even be able to tell the difference!Coach Outlet Online Store would dynamically change your overall styles right away. The amazing knack about the unique coach handbag is that it would never disappoint your individual styles at all. Rather, it would instantly change your ultimate fashions in a remarkable manner.

http://www.coachoutletstoreonlineeo.com

18. anonymous -- 2012-04-09 08:42

Thanks a lot for providing the great info is visible in this blog that to using the great info is visible in this blog. I am really satisfied by the great info is visible in this blog that to using the great technology in this blog Link:sha1 vs md5

19. christian louboutin uk -- 2012-04-18 01:39
20. louis vuitton uk -- 2012-04-18 01:46
21. mulberry sale -- 2012-04-18 01:54
22. anonymous -- 2012-05-02 07:07

Gucci GG Running Medium Hobo 247185 Beige Fabric Blue Bag no decoration of luxurious materials and dazzling diamonds, vivid three-dimensional detail for Smart exquisite evening bag more. Romantic flowers, bead tassels elegance and distributed from the fingers. Black GUCCI 201480 Briefcase Tote Bag soft lines, feel comfortable wearing, elegant mix of cute flat shoes to be a timeless classic. Even if there is no conspicuous eye-catching brilliance, reveals a hint of low-key luxury is also an elegant charm to enjoy the show. Thin white T-shirt full of the feeling of a writer of books aroma, with this year's hot wide leg pants, the same good-looking, energetic movement with very good-looking, with the last Brown GUCCI 201480 Briefcase Tote Bag, cotton fabric is very a sporty appearance with very http://www.guccibagtopsale.com/

Add New Comment