Starting Erlang service at boot time (using Relx for creating release)

646 Views Asked by At

I have a server written in Erlang, compiled with Rebar, and I make a release with Relx. Starts nicely with

/root/rel/share3/bin/share3 start

The next step is to start when the server boots.

I have tried different approaches, the last one is using the /etc/init.d/skeleton where I changed the following

NAME=share3
DAEMON=/root/rel/share3/bin/share3
DAEMON_ARGS="$1"

After that, I run update-rc.d, but I have not gotten it too work. (Ubuntu 14.04)

The service runs until the machine reboots, and I need to login and start it again.

For Windows, it is really elegant, since it can create the Windows service.

2

There are 2 best solutions below

0
On

At last, I solved it!

I have told to relx to place the result at /home/mattias/rel. The script from relx is /home/mattias/rel/share3/bin/share3

Replace the row

SCRIPT_DIR="$(dirname "$0")"

by (you need to fix the path /home/mattias/rel)

HOME=/home/mattias
export HOME
SCRIPT_DIR="/home/mattias/rel/share3/bin"

Copy the file to /etc/init.d/share3 using

sudo cp ~/rel/share3/bin/share3 /etc/init.d/

Test that it works using

/etc/init.d/share3 start

and

/etc/init.d/share3 stop

In order to make it start at boot, install sysv-rc-conf

sudo apt-get install sysv-rc-conf

Enable boot at start using

sudo sysv-rc-conf share3 on

and disable

sudo sysv-rc-conf share3 off

Alternatives are welcome.

0
On

Ubuntu uses upstart as init system, so you could try something like that:

description "Start my awesome service"
start on runlevel [2345]
stop on runlevel [!2345]

respawn
exec /root/rel/share3/bin/share3

You have to place this script in /etc/init/ directory with '.conf' extension like '/etc/init/share3.coinf'. To start it invoke sudo start share3.