[erlang-questions] HEART

Daniil Churikov <>
Wed May 20 19:30:28 CEST 2015


Sorry Roberto, forgot to cc the list.

If you will use heart be aware of OOM. We had some issues with it,
in essence OOM kills both heart and VM.

2015-05-13 15:08 GMT+01:00 Roberto Ostinelli <>:

> Ok,
> After a while of experimenting I want to provide some feedback to the
> great help that was provided here.
> I've come up with a init.d script (currently running on Ubuntu) that
> provides me with what I needed.
>
> As a reminder:
>
>    - I have an Erlang 17.4 release generated with rebar.
>    - I want to have the release started on system boot.
>    - I want to the VM monitored and restarted it if it crashes.
>
>
> First, ensure that the `-heart` option is used in your `vm.args` file.
> Heart will monitor the VM and restart it if needed.
>
> Second, create the file `/etc/init.d/myapp`:
>
>
> ########################################################################
>
> #!/usr/bin/env bash
> # myapp daemon
> # chkconfig: 345 20 80
> # description: myapp daemon
> # processname: myapp
>
> NAME=myapp
> PROJECT_ROOT_PATH=/usr/local/$NAME
> APP_SCRIPT="bin/$NAME"
>
> # export
> export HOME=/root
>
> case "$1" in
> start)
>     printf "%-50s" "Starting $NAME..."
>
>     # start
>     cd $PROJECT_ROOT_PATH
>     $APP_SCRIPT start > /dev/null 2>&1;
>
>     # wait for pid
>     for (( i=0; i<10; ++i )); do
>         OUT=`$APP_SCRIPT getpid`;
>         if [ $? == 0 ]; then PID=$OUT; break; fi
>         sleep 1;
>     done
>
>     if [ -z "$PID" ]; then
>         printf "%s\n" "Failsd"
>     else
>         printf "%s\n" "Ok"
>     fi
> ;;
> status)
>     printf "%-50s" "Checking $NAME..."
>
>     # wait for pid
>     cd $PROJECT_ROOT_PATH
>     $APP_SCRIPT getpid > /dev/null 2>&1;
>
>     if [ $? != 0 ]; then
>         printf "%s\n" "Node is not running!"
>     else
>         printf "%s\n" "Ok"
>     fi
> ;;
> stop)
>     printf "%-50s" "Stopping $NAME..."
>
>     # cd and stop
>     cd $PROJECT_ROOT_PATH
>     $APP_SCRIPT stop > /dev/null 2>&1;
>
>     if [ $? != 0 ]; then
>         printf "%s\n" "Node is not running!"
>     else
>         printf "%s\n" "Ok"
>     fi
> ;;
>
> restart)
>     $0 stop
>     $0 start
> ;;
>
> *)
>     echo "Usage: $0 {status|start|stop|restart}"
>     exit 1
> esac
>
>
> ########################################################################
>
> You can use this file as normal services:
>
> ```
> $ sudo service cometa start
> Starting myapp...                                Ok
> ```
>
>
> Third, ensure this script is used at boot time:
>
> `sudo update-rc.d myapp defaults`
>
>
>
> Side note: you can see that the script waits to exit the start function
> until the PID is retrieved from the VM.
> This is not strictly necessary, although in this way you can even consider
> dumping it into PID files or perform other types of monitoring actions
> instead of using HEART.
>
>
> Hope this helps someone in my same spot.
>
> Best,
> r.
>
>
>
>
> On Wed, May 13, 2015 at 3:54 PM, Tristan Sloughter <>
> wrote:
>
>>  Use remote_console instead of attach.
>>
>> --
>> Tristan Sloughter
>> 
>>
>>
>>
>> On Wed, May 13, 2015, at 06:41 AM, Roberto Ostinelli wrote:
>>
>> Hi,
>> Still experiencing weirdnesses though.
>>
>> My upstart script is:
>>
>> script
>> export HOME=/root
>> cd /usr/local/myapp
>>     exec bin/myapp foreground > /dev/null 2>&1
>> end script
>>
>>
>> When I start to attach to the app's node, I get:
>>
>> $ /usr/local/myapp/bin/myapp attach
>> pong
>> Can't access pipe directory /tmp//usr/local/myapp/: No such file or
>> directory
>>
>>
>> However, if I start my app manually:
>>
>> $ /usr/local/myapp/bin/myapp start
>>
>> Then everything works fine:
>>
>> $ /usr/local/cometa/bin/cometa attach
>> pong
>> Attaching to /tmp//usr/local/myapp/erlang.pipe.1 (^D to exit)
>>
>> ()1>
>>
>>
>> Can some kind soul explain to me what is going on?
>>
>> Thank you,
>> r.
>>
>>
>>
>>
>>
>>
>>
>> On Tue, May 12, 2015 at 8:44 PM, Roger Lipscombe <>
>> wrote:
>>
>> On 12 May 2015 at 18:45, Roberto Ostinelli
>> <> wrote:
>> > Right. Unfortunately I can't find a way to oass this pid to the
>> original script that starts it (using upstart).
>>
>> We use relx-generated releases with upstart. Simply run "bin/myapp
>> foreground" from the upstart script.
>>
>>
>>
>>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150520/52b7607f/attachment.html>


More information about the erlang-questions mailing list