summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Feuer <mfeuer@jaguarlandrover.com>2015-11-22 12:07:01 -0800
committerMagnus Feuer <mfeuer@jaguarlandrover.com>2015-11-22 12:07:01 -0800
commit7d789db3ab562e23fbd244a97722daf281714626 (patch)
tree6ca0be5bbe72b2ba8151270d8da10d40294abe14
parentc6903fb83345b43c047fd27390b6332243443876 (diff)
parent15646255321f478dd53502cb26f60b26d1339cea (diff)
downloadrvi_core-7d789db3ab562e23fbd244a97722daf281714626.tar.gz
Merged from release-0.4.0-yocto_makefile
-rw-r--r--Makefile13
-rw-r--r--rvi_yocto.config366
-rw-r--r--[-rwxr-xr-x]scripts/rvi101
-rw-r--r--scripts/rvi.service.tizen19
-rw-r--r--scripts/rvi.service.yocto18
-rw-r--r--scripts/rvi.sh168
-rwxr-xr-xscripts/rvi_install.sh73
-rwxr-xr-xscripts/setup_rvi_node.sh135
8 files changed, 715 insertions, 178 deletions
diff --git a/Makefile b/Makefile
index e98465e..39e47c3 100644
--- a/Makefile
+++ b/Makefile
@@ -15,7 +15,7 @@
SCRIPTS=scripts/setup_gen \
scripts/author
-VERSION=0.4.0
+VERSION=0.5.0
all: deps compile escript
@@ -62,11 +62,16 @@ rpm_tarball: rpmclean clean
tar czf /tmp/rvi_core-$(VERSION).tgz BUILD.md CONFIGURE.md doc \
LICENSE Makefile README.md rebar rebar.config rel \
RELEASE.md rpm scripts/setup_gen scripts/rvi \
- scripts/rvi.service scripts/rvi_node.sh components \
- rvi_sample.config scripts/setup_rvi_node.sh src \
- tizen.config TODO
+ scripts/rvi.service scripts/rvi_node.sh scripts/rvi.sh \
+ components rvi_sample.config scripts/setup_rvi_node.sh src \
+ TODO
mv /tmp/rvi-$(VERSION).tgz ./rpm/SOURCES/
rpm: rpm_tarball
rpmbuild --define "_topdir $$PWD/rpm" -ba rpm/SPECS/rvi-$(VERSION).spec
+
+install: # deps compile
+ ./scripts/rvi_install.sh $(DESTDIR)/opt/rvi
+ install --mode=0755 -d $(DESTDIR)/etc/opt/rvi/
+ install --mode=0644 rvi_yocto.config $(DESTDIR)/etc/opt/rvi/rvi.config
diff --git a/rvi_yocto.config b/rvi_yocto.config
new file mode 100644
index 0000000..e9d705e
--- /dev/null
+++ b/rvi_yocto.config
@@ -0,0 +1,366 @@
+%% -*- erlang -*-
+
+%% 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/
+%%
+%% Configuration file for the (in-vehicle) IVI used by the hvac_demo
+%%
+%% See ../hvac_demo/README.md for details on the demo.
+%%
+%% See ../CONFIGURE.md for a details on the configuration process
+%% itself.
+%%
+[
+ %% All erlang apps needed to fire up a node. Do not touch.
+ {apps,
+ [kernel,
+ stdlib,
+ sasl,
+ {setup, load},
+ syntax_tools,
+ lager,
+ crypto,
+ public_key,
+ exo,
+ compiler,
+ ssl,
+ asn1,
+ %% RVI-specific apps.
+
+ %% Do not touch unless you are replacing apps with your own
+ %% version. If you are replacing an app with a non-Erlang version,
+ %% it still has to be loaded in order to resolve.
+ %% If, for example, you want to deploy your own scheduler
+ %% outside Erlang, replace
+ %%
+ %% schedule,
+ %% with
+ %% { schedule, load },
+ %%
+ rvi,
+ rvi_common,
+ service_discovery,
+ service_edge,
+ authorize,
+ schedule,
+ dlink_tcp,
+ %%{bt,load},
+ %%{dlink_bt, load}
+ proto_bert,
+ proto_json
+ ]},
+
+ %%
+ %% Custom environment settings
+ %% for all apps running on the node.
+ %%
+ {env,
+ [
+ %% Lager is the main logging mechanism.
+ %% See https://github.com/basho/lager for details.
+ %%
+ {lager,
+ [ { handlers,
+ %% Change this to debug, info, notice, warning, or error in
+ %% order to lower the console chatter.
+ [ {lager_console_backend, notice} ]
+ }
+ ]
+ },
+
+ %% All RVI configuration is done here.
+ %%
+ %% Please note that the rvi_node.sh launch script
+ %% can still override the port range and static nodes
+ %% through its command line parameters.
+ %%
+ %% Value substitution:
+ %% All string values under the rvi tuple tree are scanned
+ %% for specific dokens during startup. If a token is
+ %% found, it will be replaced with a value referenced by it.
+ %% Tokens can one of the following:
+ %%
+ %% $rvi_file(FileName,Default) - File content
+ %% When an $rvi_file() token is encountered, the first line of
+ %% the referenced file is read. The line (without the newline)
+ %% replaces the token.
+ %%
+ %% Example:
+ %% { node_service_prefix, "jlr.com/vin/$rvi_file(/etc/vin,default_vin)"},
+ %%
+ %% will be substituted with the first line from the file
+ %% /etc/vin:
+ %%
+ %% { node_service_prefix, "jlr.com/vin/2GKEG25HXP4093669"},
+ %%
+ %% If /etc/vin cannot be opened, the value default_vin
+ %% will be used instead.
+ %%
+ %%
+ %% $rvi_env(EnvironemtnName,Default) - Environment variable
+ %% When an $rvi_env() token is encountered, the value of
+ %% the Linux process environment variable (such as $HOME) is read
+ %% to replace the token.
+ %%
+ %% Example:
+ %% { node_service_prefix, "jlr.com/vin/$rvi_env(VIN,default_vin)"},
+ %%
+ %% will be substituted with the value of the $VIN environment
+ %% variable:
+ %%
+ %% { node_service_prefix, "jlr.com/vin/2GKEG25HXP4093669"},
+ %%
+ %% If VIN is not a defined environment variable, the value
+ %% default_vin will be used instead.
+ %%
+ %%
+ %% $rvi_uuid(Default) - Unique machine identifier
+ %% When an $rvi_uuid() token is encountered, the UUID of the root
+ %% disk used by the system is read to replace the token.
+ %% The UUID of the root disk is retrieved by opening /proc/cmdline
+ %% and extracting the root=UUID=[DiskUUID] value.
+ %% This value is generated at system install time and is reasonably
+ %% world wide unique.
+ %%
+ %% Example:
+ %% { node_service_prefix, "jlr.com/vin/$uuid(default_vin)"},
+ %%
+ %% will be substituted with the value of the root disk UUID:
+ %%
+ %% { node_service_prefix,
+ %% "jlr.com/vin/afc0a6d8-0264-4f8a-bb3e-51ff8655b51c"},
+ %%
+ %% If the root UUID cannot be retrieved, the value default_vin
+ %% will be used instead.
+ %%
+
+ {rvi,
+ [
+
+ %% Specify the node address that data_link uses to listen to
+ %% incoming traffic from other rvi nodes.
+ %%
+ %% This is the address that is announced to
+ %% other rvi nodes during service discovery and should be
+ %% forwarded through firewalls and port forwarding to to the port
+ %% specified by the configuration entry rvi -> components ->
+ %% data_link -> bert_rpc_server (see below).
+ %%
+ %% If this node is sitting behind a firewall and cannot
+ %% receive incomign connections on any address, its
+ %% node_address should be set to "0.0.0.0:0" to inform
+ %% the remote node that it should not attempt to
+ %% connect back to self.
+ { node_address, "127.0.0.1:8807" },
+
+ %% Specify the prefix of all services that this rvi node is hosting.
+ %%
+ %% All local services regsitering with service edge will be prefixed with
+ %% the string below when they are announced to remote rvi nodes
+ %% that connect to this node (using the address specified
+ %% by node_address above).
+ %%
+ %% If a locally connected service registers itself as
+ %% "hvac/fan_speed", and the node_service_prefix is
+ %% "jlr.com/vin/1234/", this node will announce the service
+ %% "jlr.com/vin/1234/hvac/fan_speed" as being available
+ %% to remotely connected rvi nodes.
+ %%
+ %% Two rvi nodes should never have the same node_service_prefix
+ %% value unless all services add a system-wide unique name
+ %% to it.
+ %%
+ { node_service_prefix, "jlr.com/vin/$rvi_file(/etc/opt/rvi/device_id,default_vin)/"},
+
+
+ %% Routing rules determine how to get a message targeting a specific
+ %% service to its destination.
+ %%
+ %% Please note that if a remotely initiated (== client) data link is
+ %% available and has announced that the targeted service is available,
+ %% that data link will be used regardless of what it is.
+ %%
+ %% In other words, if you setup routing rules for how to reach out
+ %% to a vehicle using SMS, and that vehicle happens to have a 3G
+ %% connection up when the message is sent, the 3G connection will be used.
+ %%
+ %% We will add a blacklist feature in the future to optionally block
+ %% such opportunistic routing in the future.
+ %%
+ { routing_rules,
+ [
+ %% Service name prefix that rules are specified for
+ %% The service prefix with the longest match against the service targeted
+ %% by the message will be used.
+ %%
+ %% Example: Targeted service = jlr.com/backend/sota/get_updates
+ %%
+ %% Prefix1: { "jlr.com/backend", [...]}
+ %% Prefix2: { "jlr.com/backend/sota", [...]}
+ %%
+ %% Prefix2 will be used.
+ %%
+ %% This allows you, for example, to setup different servers
+ %% for different types of services (SOTA, remote door unlock,
+ %% HVAC etc).
+ %%
+
+ %% Make sure to have a default if you don't want your message
+ %% to error out immediately. With a default the message will
+ %% be queued until it times out, waiting for a remote node
+ %% to connect and announce that it can handle the targeted service.
+ { "",
+ [
+ { proto_json_rpc, dlink_tcp_rpc}
+ ]
+ },
+
+ { "jlr.com/backend/",
+ %% Which protocol and data link pair to use when transmitting the message
+ %% to the targeted service. If a pair reports a failure, the next pair is tried.
+
+ %% Use JSON-based protocol and data link. Have the data link connect
+ %% to a given target in order to reach the node hosting
+ %% "jlr.com/backend" prefixed services.
+ [
+ { proto_json_rpc, { dlink_tcp_rpc, [ { target, "38.129.64.13:8807" } ]}}
+ ]
+ },
+
+ %% Used to communicate with vehicles
+ { "jlr.com/vin/",
+ [
+ { proto_bert_rpc, { dlink_tcp_rpc, [ broadcast, { interface, "wlan0" } ] } },
+ %% server_3g is augmented with hinting, provided to
+ { bert_rpc, { server_3g, [ initiate_outbound ]} },
+
+ %% Protocols can have hinting as well.
+ %% In this case bert_rpc should only be used if the
+ %% resulting message size can fit in an SMS (140 bytes).
+
+ { { bert_rpc, [ { max_msg_size, 140 } ] } , server_sms }
+ ]
+ }
+ ]
+ },
+ { components,
+ [
+ %% A note about JSON-RPC calls vs gen_server calls:
+ %%
+ %% All locally connected services communicate with Service Edge
+ %% through JSON-RPC.
+ %%
+ %% Communication between the internal RVI components, however,
+ %% can be either JSON-RPC or gen_server calls.
+ %%
+ %% JSON-RPC calls provide compatability with replacement components
+ %% written in languages other than Erlang.
+ %%
+ %% Gen_server calls provide native erlang inter-process calls that
+ %% are about 4x faster than JSON-RPC when transmitting large data volumes.
+ %%
+ %% If one or more of the components below are replaced with external
+ %% components, use JSON-RPC by specifying IP address and port in
+ %% json_rpc_address for all interfaced by the external components.
+ %%
+ %% If you are running an all-native erlang system, use gen_server calls
+ %% by specifying gen_server for all components
+ %%
+ %% Please note that communication between two RVI nodes are
+ %% not affected by this since data_link_bert_rpc will use
+ %% BERT-RPC to communicate ( using the address/port specified
+ %% by bert_rpc_server).
+ %%
+
+ %% Service_edge.
+ %% The service_edge tuple is a top level configuration
+ %% container for everything about service edge.
+ %% In theory, we can support multiple different service edge
+ %% components (written in different languages).
+ %%
+ %% However, until we've sorted out internal routing, we will
+ %% only support the native service_edge_rpc component,
+ %% accessed either as a gen_server or through JSON-RPC.
+ %%
+ {service_edge,
+ [
+ %% Service_edge_rpc component is used as a gen_server
+ { service_edge_rpc, gen_server,
+ [
+ %% JSON-RPC address will be translated to
+ %% an URL looking like this:
+ %% http://127.0.0.1:8801
+ %%
+ %% This URL is used both for communication with
+ %% locally connected services and for intra-component
+ %% communication in case the access method for
+ %% service_edge_rpc is specified as json_rpc.
+ { json_rpc_address, { "127.0.0.1", 8801 } },
+
+ %% Websocket is used for websocket access, preferably
+ %% through the rvi.js package available for Javascript
+ %% apps in browsers and crosswalk who wants to interface
+ %% RVI.
+ { websocket, [ { port, 8808}]}
+ ]
+ }
+ ]
+ },
+ { service_discovery,
+ [ { service_discovery_rpc, gen_server,
+ [
+ { json_rpc_address, { "127.0.0.1", 8802 }}
+ ]
+ }
+ ]
+ },
+ { schedule,
+ [ { schedule_rpc, gen_server,
+ [
+ { json_rpc_address, { "127.0.0.1", 8803 }}
+ ]
+ }
+ ]
+ },
+ { authorize,
+ [ { authorize_rpc, gen_server,
+ [
+ { json_rpc_address, { "127.0.0.1", 8804 } }
+ ]
+ }
+ ]
+ },
+ { protocol,
+ [ { proto_json_rpc, gen_server,
+ [
+ { json_rpc_address, { "127.0.0.1", 8805 } }
+ ]
+ }
+ ]
+ },
+ { data_link,
+ [ { dlink_tcp_rpc, gen_server,
+ [
+ { json_rpc_address, { "127.0.0.1", 8806 } },
+ %% Bert_rpc server specifies the port we should
+ %% listen to for incoming connections
+ %% from other rvi nodes.
+ %% A specific NIC address can also be specified
+ %% through the {ip, "192.168.0.1" } tuple.
+ { server_opts, [ { port, 8807 }]},
+
+ %% Persistent connections are connected to at
+ %% startup, and will be reconnected to in case they fail
+ { persistent_connections, [ "38.129.64.13:8807" ]}
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ ]}
+ ]}
+].
diff --git a/scripts/rvi b/scripts/rvi
index 337432e..6683c52 100755..100644
--- a/scripts/rvi
+++ b/scripts/rvi
@@ -1,4 +1,4 @@
-#! /bin/sh
+#!/bin/sh
#
# Copyright (C) 2014, Jaguar Land Rover
#
@@ -6,43 +6,66 @@
# Mozilla Public License, version 2.0. The full text of the
# Mozilla Public License is at https://www.mozilla.org/MPL/2.0/
#
+
#
-# Init.d script to start and stop an RVI system installed
-# through an RPM.
+# Setup a correct configuration and launch an RVI release node.
+# If a UUID file has not been created, it will be done at this time.
#
-export PATH="/bin/:/usr/bin:/sbin:/usr/sbin"
-. /lib/lsb/init-functions
-
-set -e
-
-case "$1" in
- start)
- log_daemon_msg "Starting Remote Vehicle Interaction Node..." "rvi"
- if /opt/rvi-0.4.0/bin/rvi start; then
- log_end_msg 0
- else
- log_end_msg 1
- fi
- ;;
- stop)
- log_daemon_msg "Stopping Remote Vehicle Interaction Node..." "rvi"
- if /opt/rvi-0.4.0/bin/rvi stop; then
- log_end_msg 0
- else
- log_end_msg 1
- fi
- ;;
- restart)
- log_daemon_msg "Restarting Remote Vehicle Interaction Node..." "rvi"
- if /opt/rvi-0.4.0/bin/rvi restart; then
- log_end_msg 0
- else
- log_end_msg 1
- fi
- ;;
- *)
- log_action_msg "Usage: /etc/init.d/rvi {start|stop|restart}"
- exit 1
-esac
-
-exit 0
+
+SELF_DIR=$(dirname $(readlink -f "$0"))
+CONFIG_DIR=/etc/opt/rvi
+BIN_DIR=/opt/rvi
+
+usage() {
+ echo "Usage: $0 -c config_file"
+ echo " -c config_file Specify the configuration "
+ echo "Configuration data is read from the configuration file."
+ exit 1
+}
+
+while getopts "c:" o; do
+ case "${o}" in
+ c)
+ CONFIG_FILE=${OPTARG}
+ ;;
+ *)
+ usage
+ ;;
+ esac
+done
+
+if [ -z "${CONFIG_FILE}" ] ; then
+ echo "Missing -c flag"
+ usage
+fi
+
+# Check if we have a uuid file.
+if [ ! -f ${CONFIG_DIR}/device_id ]
+then
+ echo "Creating device ID in ${CONFIG_DIR}/device_id"
+ cat /proc/sys/kernel/random/uuid > ${CONFIG_DIR}/device_id
+fi
+
+#
+# Generate a config file that will end up as
+# /tmp/rvi/sys.config
+#
+(
+ cd /tmp/
+ rm -rf rvi
+ export ERL_LIBS=${BIN_DIR}/setup:${BIN_DIR}/lib/
+ ${BIN_DIR}/setup_gen rvi $CONFIG_FILE rvi
+)
+
+# Did we succeed with config generation?
+if [ "$?" != "0" ]
+then
+ # Nope
+ exit "$?"
+fi
+
+# Copy created config file to /etc/opt/rvi/sys.config,
+# which is symlinked to by /opt/rvi/sys.config
+cp /tmp/rvi/sys.config /etc/opt/rvi/sys.config
+
+exec /opt/rvi/bin/rvi start
diff --git a/scripts/rvi.service.tizen b/scripts/rvi.service.tizen
new file mode 100644
index 0000000..1220eb9
--- /dev/null
+++ b/scripts/rvi.service.tizen
@@ -0,0 +1,19 @@
+# systemd(8) setup usde by Tizen and others.
+[Unit]
+Description=Remote Vehicle Interaction Service
+Wants=network-online.target
+
+[Service]
+Environment="HOME=/opt/rvi-0.4.0"
+Type=forking
+StandardOutput=journal
+StandardError=journal
+ExecStartPre=/usr/bin/chsmack --access User /home/app/content/Documents/vin
+ExecStartPre=/opt/rvi-0.4.0/erts-5.10.4/bin/epmd -daemon
+ExecStart=/bin/sh /opt/rvi-0.4.0/bin/rvi start
+ExecStop=/bin/sh /opt/rvi-0.4.0/bin/rvi stop
+ExecStopPost=/opt/rvi-0.4.0/erts-5.10.4/bin/epmd -kill
+GuessMainPID=yes
+
+[Install]
+WantedBy=graphical.target multi-user.target
diff --git a/scripts/rvi.service.yocto b/scripts/rvi.service.yocto
new file mode 100644
index 0000000..1ddae5d
--- /dev/null
+++ b/scripts/rvi.service.yocto
@@ -0,0 +1,18 @@
+# systemd(8) setup usde by Tizen and others.
+[Unit]
+Description=Remote Vehicle Interaction Service
+Wants=network-online.target
+
+[Service]
+Environment="HOME=/opt/rvi"
+Type=forking
+StandardOutput=journal
+StandardError=journal
+ExecStartPre=epmd -daemon
+ExecStart=/bin/sh /opt/rvi/rvi.sh -d /etc/opt/rvi -c /etc/opt/rvi/rvi_yocto.config start
+ExecStop=/bin/sh /opt/rvi/rvi stop
+ExecStopPost=epmd -kill
+GuessMainPID=yes
+
+[Install]
+# WantedBy=graphical.target multi-user.target
diff --git a/scripts/rvi.sh b/scripts/rvi.sh
new file mode 100644
index 0000000..e713784
--- /dev/null
+++ b/scripts/rvi.sh
@@ -0,0 +1,168 @@
+#!/bin/sh
+#
+# Copyright (C) 2014, Jaguar Land Rover
+#
+# Mozilla Public License, version 2.0. The full text of the
+# Mozilla Public License is at https://www.mozilla.org/MPL/2.0/
+#
+#
+# Setup a correct configuration and launch an RVI release node.
+# If a UUID file has not been created, it will be done at this time.
+# Init.d script to start and stop an RVI system installed
+# through an RPM.
+#
+
+SELF_DIR=$(dirname $(readlink -f "$0"))
+
+ERL=${ERL:=erl}
+
+usage() {
+ echo "Usage: $0 -d config_dir -c config_file -l log_dir \\"
+ echo " start|stop|console|attach|ping"
+ echo
+ echo " -c config_file Configuration file to launch rvi node with. "
+ echo " If omitted the rvi.config in the configuration "
+ echo " directory will be used."
+ echo
+ echo " -d config_dir Directory to put generated uuid 'device_id' file and"
+ echo " processed config files."
+ echo " Defauts to the 'config' directory under the directory"
+ echo " that rvi.sh resides in."
+ echo
+ echo " -l log_dir The directory to store log files in."
+ echo " Defaults to '/tmp/rvi/[config]/log' where [config]"
+ echo " is the base name of the configuration file."
+ echo
+ echo " start Start an rvi node with the given configuration file."
+ echo
+ echo " stop Stop an rvi node previously started with 'start'."
+ echo
+ echo " console Start an rvi in foreground mode."
+ echo
+ echo " attach Attach to an rvi node previously started with 'start'."
+ echo
+ echo " ping Ping to check if an rvi node is up. Returns 0 if up."
+ exit 1
+}
+
+CONFIG_FILE=""
+
+SNAME=rvi
+COOKIE=rvi_cookie
+unset CONFIG_DIR
+unset LOG_DIR
+while getopts "c:d:" o; do
+ case "${o}" in
+ c)
+ CONFIG_FILE=${OPTARG}
+ ;;
+ d)
+ CONFIG_DIR=${OPTARG}
+ ;;
+ l)
+ LOG_DIR=${OPTARG}
+ ;;
+ *)
+ usage
+ ;;
+ esac
+done
+
+CONFIG_DIR=${CONFIG_DIR:=${SELF_DIR}/config}
+
+shift $((${OPTIND}-1))
+CMD=$1
+
+if [ "${CMD}" != "start" -a "${CMD}" != "stop" -a "${CMD}" != "console" -a "${CMD}" != "ping" ]
+then
+ usage
+fi
+
+export ERL_LIBS=${SELF_DIR}/rvi:${SELF_DIR}/rvi/deps:${SELF_DIR}/rvi/components
+TMP_DIR=/tmp/rvi/$(basename ${CONFIG_FILE} .config)
+LOG_DIR=${LOG_DIR:=${TMP_DIR}/log}
+
+
+# Check that we have a config dir
+if [ ! -d ${CONFIG_DIR} ]
+then
+ install -d --mode=0755 ${CONFIG_DIR}
+fi
+
+# Check if we have a uuid file.
+if [ ! -f ${CONFIG_DIR}/device_id ]
+then
+ echo "Creating device ID in ${CONFIG_DIR}/device_id"
+ cat /proc/sys/kernel/random/uuid > ${CONFIG_DIR}/device_id
+fi
+
+
+
+#
+# See if we need to process a config file
+#
+if [ ${CMD} = "start" -o ${CMD} = "console" ]
+then
+ # Default to rvi.config
+ CONFIG_FILE=${CONFIG_FILE:=${CONFIG_DIR}/rvi.config}
+ #
+ # Check if we need to prepend current dir
+ # to relative config file path
+ #
+ if [ $(echo ${CONFIG_FILE} | cut -c 1,1) != "/" ]
+ then
+ CONFIG_FILE=${PWD}/${CONFIG_FILE}
+ fi
+
+ # Check that config file can be read.
+ if [ ! -r "${CONFIG_FILE}" ]
+ then
+ echo "${CONFIG_FILE} cannot be opened for reading."
+ usage
+ fi
+ #
+ # Generate a config file that will end up as
+ # /tmp/rvi/sys.config
+ #
+ (
+ cd ${CONFIG_DIR}
+ ${SELF_DIR}/setup_gen rvi ${CONFIG_FILE} rvi
+ )
+
+ # Did we succeed with config generation?
+ if [ "$?" != "0" ]
+ then
+ # Nope
+ echo "Failed to process configuration file."
+ exit "$?"
+ fi
+fi
+
+
+LAUNCH="${ERL} -boot ${CONFIG_DIR}/rvi/start -sname ${SNAME} -config ${CONFIG_DIR}/rvi/sys -setcookie ${COOKIE}"
+
+case "${CMD}" in
+ start)
+ install -d --mode 0755 ${TMP_DIR}
+ install -d --mode 0755 ${LOG_DIR}
+ exec run_erl -daemon ${TMP_DIR}/ ${LOG_DIR} "exec ${LAUNCH}"
+ ;;
+
+ console)
+ exec ${LAUNCH}
+ ;;
+
+ stop)
+ exec ${SELF_DIR}/nodetool -sname ${SNAME} -setcookie ${COOKIE} stop
+ ;;
+
+ ping)
+ exec ${SELF_DIR}/nodetool -sname ${SNAME} -setcookie ${COOKIE} ping
+ ;;
+
+ attach)
+ exec to_erl ${TMP_DIR}
+ ;;
+
+esac
+
diff --git a/scripts/rvi_install.sh b/scripts/rvi_install.sh
new file mode 100755
index 0000000..7572aa9
--- /dev/null
+++ b/scripts/rvi_install.sh
@@ -0,0 +1,73 @@
+#!/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/
+#
+
+#
+# Setup an RVI release with a configuration file.
+#
+# This script will setup a directory with with the same name
+# as the release name. The script uses Ulf Wiger's setup application
+# (github.com/Feuerlabs/setup) to generate the release.
+#
+# With the -d argument, a developer release will be built with
+# only
+#
+# Once setup, the RVI node can be started with ./rvi_node <release_na,e?
+#
+# Please note that the generated release will depend on the built
+#
+# In order to create a standalone release, use create_rvi_release.sh
+#
+
+SELF_DIR=$(dirname $(readlink -f "$0"))
+SETUP_GEN=$SELF_DIR/setup_gen # Ulf's kitchen sink setup utility
+
+usage() {
+ echo "Usage: $0 binary_dir"
+ echo
+ echo "RVI will be installed in 'target_dir'."
+ echo
+ echo "The created node can be started with: 'target_dir'/rvi.sh"
+ echo "RVI in 'target_dir' will rely on a native erlang to function"
+ exit 1
+}
+
+cd ${SELF_DIR}/..
+
+shift $((${OPTIND}-1))
+
+if [ "${#}" != "1" ]
+then
+ echo "Target directory not specifiied."
+ usagee
+fi
+
+TARGET_DIR=$1
+
+rm -rf ${TARGET_DIR} > /dev/null 2>&1
+
+install --mode=0755 -d ${TARGET_DIR}/rvi
+
+FILE_SET=$(find ebin components deps -name ebin -o -name priv)
+
+echo "Installing rvi at ${TARGET_DIR}."
+
+tar cf - ${FILE_SET} | (cd ${TARGET_DIR}/rvi ; tar xf - )
+
+install --mode=0755 scripts/rvi.sh ${TARGET_DIR}
+install --mode=0755 scripts/setup_gen ${TARGET_DIR}
+install --mode=0755 rel/files/nodetool ${TARGET_DIR}
+
+echo "RVI installed under ${TARGET_DIR}"
+echo "Start: ${TARGET_DIR}/rvi.sh -c <config_file> start"
+echo "Attach started RVI: ${TARGET_DIR}/rvi.sh attach"
+echo "Stop: ${TARGET_DIR}/rvi.sh stop"
+echo "Start console mode: ${TARGET_DIR}/rvi.sh -c <config_file> console"
+
+exit 0
+
diff --git a/scripts/setup_rvi_node.sh b/scripts/setup_rvi_node.sh
deleted file mode 100755
index 92b9fe3..0000000
--- a/scripts/setup_rvi_node.sh
+++ /dev/null
@@ -1,135 +0,0 @@
-#!/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/
-#
-
-#
-# Setup an RVI release with a configuration file.
-#
-# This script will setup a directory with with the same name
-# as the release name. The script uses Ulf Wiger's setup application
-# (github.com/Feuerlabs/setup) to generate the release.
-#
-# With the -d argument, a developer release will be built with
-# only
-#
-# Once setup, the RVI node can be started with ./rvi_node <release_na,e?
-#
-# Please note that the generated release will depend on the built
-#
-# In order to create a standalone release, use create_rvi_release.sh
-#
-
-alias realpath="python -c 'import os, sys; print os.path.realpath(sys.argv[1])'"
-SELF_DIR=$(dirname $(realpath "$0"))
-TOP_DIR=$(dirname $SELF_DIR)
-
-SETUP_GEN=$SELF_DIR/setup_gen # Ulf's kitchen sink setup utility
-
-usage() {
- echo "Usage: $0 [-d] -n node_name -c config_file"
- echo " -n node_name Specify the name of the rvi node to setup"
- echo
- echo " -c config_file Specifies the setup config file to use when setting "
- echo " up the node"
- echo
- echo " -d Create a development release. See below."
- echo
- echo "The generated node will be created in a subdirectory with the same"
- echo "name as the node name."
- echo
- echo "The created node can be started with: $SELF_DIR/rvi_node -n node_name"
- echo
- echo "If the node was created with the -d flag, you need to start"
- echo "the node with $SELF_DIR/rvi_node -d -n node_name"
- echo
- echo "Configuration file examples can be found in hvac_demo/vehicle.config"
- echo
- echo "The -d flag creates a development release that uses the erlang "
- echo "binaries found in ebin/ and deps/*/ebin. This means that new builds,"
- echo "created by make, can be run directly through "
- echo "$SELF_DIR/rvi_node -n node_name without having to run ./setup_rvi_node.sh ."
- echo
- echo "If the -d flag is omitted, the release will be self-contained in the "
- echo "newly created subdirectory rel/[node_name]."
- echo "This directory, containing a standard erlang reltool release, "
- echo "including the erlang runtime system, can be copied as a stand alone"
- echo "system to a destination node."
- echo
- echo "Configuration file examples can be found in hvac_demo/vehicle.config"
- exit 1
-}
-
-
-build_type=rel
-while getopts "dn:c:" o; do
- case "${o}" in
- n)
- NODE_NAME=${OPTARG}
- ;;
- c)
- CONFIG_NAME=${OPTARG}
- ;;
- d)
- build_type=dev
- ;;
-
- *)
- usage
- ;;
- esac
-done
-
-if [ -z "${NODE_NAME}" ] ; then
- echo "Missing -n flag"
- usage
-fi
-if [ -z "${CONFIG_NAME}" ] ; then
- echo "Missing -c flag"
- usage
-fi
-
-export ERL_LIBS=$TOP_DIR/components:$TOP_DIR/deps:$ERL_LIBS:$TOP_DIR
-echo "ERL_LIBS=$ERL_LIBS"
-echo "Setting up node $NODE_NAME."
-rm -rf $NODE_NAME
-setupres=$( $SETUP_GEN $NODE_NAME $CONFIG_NAME $NODE_NAME -pa $TOP_DIR/ebin )
-if [ -z "${setupres}" ]
-then
-
- if [ "${build_type}" = "dev" ]
- then
- echo "RVI Node $NODE_NAME has been setup."
- echo "Launch with $SELF_DIR/rvi_node.sh -n $NODE_NAME"
- exit
- else
- echo "Building stand alone release for $NODE_NAME"
- # Copy the newly created config file.
- rm -rf rel/$NODE_NAME
- cp $NODE_NAME/sys.config rel/files/sys.config
- ./rebar generate
- # Rename the release after the node name
- mv rel/rvi rel/$NODE_NAME
- echo "Stand alone release for $NODE_NAME created under project "
- echo "root directory's ./rel/$NODE_NAME."
- echo
- echo "Start: ./rel/$NODE_NAME/bin/rvi start"
- echo "Attach console: ./rel/$NODE_NAME/bin/rvi attach"
- echo "Stop: ./rel/$NODE_NAME/bin/rvi stop"
- echo "Start console mode: ./rel/$NODE_NAME/bin/rvi console"
- echo
- echo "Start dev mode: ./rvi_node.sh -n $NODE_NAME"
- echo
- echo "./rel/$NODE_NAME can be copied and installed on its destination host."
- fi
-else
- >&2 echo $setupres
- exit 1
-fi
-
-exit 0
-