summaryrefslogtreecommitdiff
path: root/scripts/rvi_node.sh
blob: a7cd201109bf5d68eeb58826fdf92a6bd3ac1039 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/sh
#
# Copyright (C) 2014, Jaguar Land Rover
#
# This program is licensed under the terms and conditions of the
# Mozilla Public License, version 2.0.  The full text of the 
# Mozilla Public License is at https://www.mozilla.org/MPL/2.0/
#

#
# Launch an RVI node using the build direcotriuies.
#
# This script launches the erlang runtime system and executes the RVI
# code directly from its build directory. Use ./setup_rvi_node without
# the -d flag to create an installable release that can execute
# without the use of this script.
#
# This script can be executed after a setup_node.sh has been executed to 
# create the necessary config files and erlang boot scripts.
#
alias realpath="python -c 'import os, sys; print os.path.realpath(sys.argv[1])'"
SELF_DIR=$(dirname $(realpath "$0"))

usage() {
    echo "Usage: $0 [-d] -n node_name"
    echo "  -n node_name          Specify the name of the rvi node to launch"
    echo "  -d                    Daemon mode (using start_erl)"
    echo "Configuration data is read from the configuration file"
    echo "provided to the setup_rvi_node.sh script that created the node."
    exit 1
}

mode=build
daemon=0
while getopts ":n:dbrp:s:" o; do
    case "${o}" in
        n)
            node_name=${OPTARG}
            ;;
        d)
            daemon=1
            ;;
        *)
            usage
            ;;
    esac
done

if [ -z "${node_name}" ] ; then
    echo "Missing -n flag"
    usage
fi

# check man erl for extra arguments

if [ "${mode}" = "build" ]
then
    if [ ! -f ${node_name}/sys.config ]
    then
	echo "Node ${node_name} not setup. Please run: "
	echo "$SELF_DIR/setup_rvi_node.sh -n ${node_name} -c <configuration_file>"
	exit 2
    fi
    xboot="-boot ${node_name}/start"
    xname="-sname ${node_name}"
    xcfg="-config ${node_name}/sys"
    CMD="erl ${xboot} ${xname} ${xcfg} -setcookie rvi_core"
    if [ ${daemon} = 1 ]
    then
	PIPE=/tmp/rvi_node/${node_name}
	LOG=${node_name}/log
	mkdir -p ${PIPE}
	mkdir -p ${LOG}
	echo "starting with run_erl"
        exec run_erl -daemon ${PIPE} ${LOG} "exec ${CMD}"
    else
	exec ${CMD}
    fi

elif [ "${mode}" = "release" ]
then
    echo "Not yet supported."
    exit 0
fi