Erlang start application in production
Asked Answered
N

3

6

When I'm testing my erlang application on localhost, I have a script that starts the server that looks like the following:

#!/bin/sh
PWD="$(pwd)"
NAME="$(basename $PWD)"
erl -pa "$PWD/ebin" deps/*/ebin -boot start_sasl \
    -name [email protected] \
    -s reloader \
    -s $NAME \
    -setcookie some_random_cookie \
    +K true \
    +P 65536 

This prompts open the Erlang shell and from there I would type something like:

application:start(myapp)

This is fine for development purposes, but how do I deploy this in production? As of right now, the only way I can think of doing this is by starting a screen process and detaching from it. I don't think that should be the case. I am using rebar, if that helps at all.

Narcosis answered 11/8, 2011 at 20:51 Comment(0)
L
7

Sounds like you want to use a custom boot script. A boot script tells the erlang system what to start. In the script you're using, you're setting the boot script with:

-boot start_sasl

http://www.erlang.org/doc/system_principles/system_principles.html, look for the section "User-Defined Boot Scripts"

An easier option may be to convert your application to use rebar: https://github.com/basho/rebar. You would then be able to do the following:

./rebar compile generate

This will create a release for the application, allowing you to then:

./rel/<app_name>/bin/<app_name>

Same principles, just all wrapped up for easy use.

Least answered 11/8, 2011 at 22:29 Comment(1)
Note that he already mentions that rebar is being used. Your answer would be a lot better if you explained how to write a rebar reltool.config.Ironsmith
K
5

Add the parameter -detached. The documentation summarizes this nicely:

Starts the Erlang runtime system detached from the system console. Useful for running daemons and backgrounds processes.

Once you do that, you can get your application to start with the -s parameter. Assuming $NAME = myapp, init will attempt to call myapp:start/0 (you can customize this if you want). That function should end with a call to application:start(myapp).

If you can get all of those puzzle pieces in place, you should have a working script.

Kerplunk answered 11/8, 2011 at 21:7 Comment(0)
C
-8

Well, you could try hooking it in to Apache (see here), or a simple solution that's not quite as hacky as screen sessions is to use nohup. If you're actually implementing this on a production server, and don't want to take the Apache route, you might consider an init script.

Carlina answered 11/8, 2011 at 20:56 Comment(3)
What does Apache have to do with anything here? My Erlang nodes do not run a web server.Narcosis
Ah, based on the information you provided to the script I assumed it was behaving as a webserver, but I guess it could also just be interacting with another web server. In that case apache is less helpful ;) nohup is still a good solution, although using the -detached option as otherwise mentioned is probably better.Carlina
-1. A confusing answer. Apache has nothing to do with it, and nohup is not necessary for a detached erlang node.Ironsmith

© 2022 - 2024 — McMap. All rights reserved.