diff options
| author | Magnus Feuer <mfeuer@jaguarlandrover.com> | 2015-12-14 16:47:25 -0800 |
|---|---|---|
| committer | Magnus Feuer <mfeuer@jaguarlandrover.com> | 2015-12-14 16:47:25 -0800 |
| commit | 8d8d38105b654ee46b9857de0003ef787bc8584e (patch) | |
| tree | 99e58e68294e04300ba3a1924f7f3d07cb17fe3e /scripts | |
| parent | 475ae65e54c58d8e1c51a6f7256c6f670a583668 (diff) | |
| download | rvi_core-8d8d38105b654ee46b9857de0003ef787bc8584e.tar.gz | |
First stab at 0.5.0 ubuntu build
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/rvi | 71 | ||||
| -rwxr-xr-x | scripts/rvi.init.ubuntu | 71 | ||||
| -rwxr-xr-x | scripts/rvi.init.yocto | 73 | ||||
| -rw-r--r-- | scripts/rvi.service | 9 | ||||
| -rw-r--r-- | scripts/rvi_ctl | 143 | ||||
| -rwxr-xr-x | scripts/rvi_install.sh | 78 |
6 files changed, 344 insertions, 101 deletions
diff --git a/scripts/rvi b/scripts/rvi deleted file mode 100644 index 6683c52..0000000 --- a/scripts/rvi +++ /dev/null @@ -1,71 +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 a correct configuration and launch an RVI release node. -# If a UUID file has not been created, it will be done at this time. -# - -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.init.ubuntu b/scripts/rvi.init.ubuntu new file mode 100755 index 0000000..a4b62e8 --- /dev/null +++ b/scripts/rvi.init.ubuntu @@ -0,0 +1,71 @@ +#!/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/ +# +# +# Init.d script to start and stop an RVI system installed +# through an RPM. +# +### BEGIN INIT INFO +# Provides: rvi +# Required-Start: $networking $syslog +# Required-Stop: $networking $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Start/Stop RVI node at boot time +# Description: Manage Remote Vehicle Interaction Node run state. +### END INIT INFO + +export PATH="/bin/:/usr/bin:/sbin:/usr/sbin" +export HOME=/tmp/rvi +install -d -D --mode=0755 ${HOME} +. /lib/lsb/init-functions + +set -e + +case "$1" in + start) + log_daemon_msg "Starting Remote Vehicle Interaction Node..." "rvi" + if /usr/bin/rvi_ctl -c /etc/rvi/rvi.config start; then + log_end_msg 0 + else + log_end_msg 1 + fi + ;; + stop) + log_daemon_msg "Stopping Remote Vehicle Interaction Node..." "rvi" + if /usr/bin/rvi_ctl stop; then + log_end_msg 0 + else + log_end_msg 1 + fi + ;; + + restart) + log_daemon_msg "Restarting Remote Vehicle Interaction Node..." "rvi" + if /usr/bin/rvi_ctl restart; then + log_end_msg 0 + else + log_end_msg 1 + fi + ;; + + force-reload) + log_daemon_msg "Restarting Remote Vehicle Interaction Node..." "rvi" + if /usr/bin/rvi_ctl 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 + diff --git a/scripts/rvi.init.yocto b/scripts/rvi.init.yocto new file mode 100755 index 0000000..adbeef5 --- /dev/null +++ b/scripts/rvi.init.yocto @@ -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/ +# +# +# Init.d script to start and stop an RVI system installed +# through an RPM. +# +### BEGIN INIT INFO +# Provides: rvi +# Default-Start: 3 5 +# Default-Stop: 0 1 2 6 +# Short-Description: RVI Framework +### END INIT INFO + + +export PATH="/bin/:/usr/bin:/sbin:/usr/sbin" +. /etc/init.d/functions + +set -e + +DAEMON_PATH="/opt/rvi" +DAEMON_NAME="rvi" + +case "$1" in + start) + echo -n "Starting $DAEMON_NAME: " + $DAEMON_PATH/rvi_ctl start + RETVAL=$? + if [ $RETVAL -eq 0 ] ; then + echo "OK" + else + echo "FAIL" + fi + ;; + + stop) + echo -n "Stopping $DAEMON_NAME: " + $DAEMON_PATH/rvi_ctl stop + RETVAL=$? + if [ $RETVAL -eq 0 ] ; then + echo "OK" + else + echo "FAIL" + fi + ;; + + restart) + echo -n "Restarting $DAEMON_NAME: " + $DAEMON_PATH/rvi_ctl restart + RETVAL=$? + if [ $RETVAL -eq 0 ] ; then + echo "OK" + else + echo "FAIL" + fi + ;; + + status) + status $DAEMON_NAME + RETVAL=$? + ;; + + *) + echo "usage: $0 { start | stop | status | restart | status }" + ;; +esac + +exit $RETVAL diff --git a/scripts/rvi.service b/scripts/rvi.service index 1220eb9..d58dae0 100644 --- a/scripts/rvi.service +++ b/scripts/rvi.service @@ -4,15 +4,12 @@ Description=Remote Vehicle Interaction Service Wants=network-online.target [Service] -Environment="HOME=/opt/rvi-0.4.0" +Environment="HOME=/opt/rvi" 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 +ExecStart=/bin/sh /opt/rvi/rvi_ctl start +ExecStop=/bin/sh /opt/rvi/rvi_ctl stop GuessMainPID=yes [Install] diff --git a/scripts/rvi_ctl b/scripts/rvi_ctl new file mode 100644 index 0000000..7deedf5 --- /dev/null +++ b/scripts/rvi_ctl @@ -0,0 +1,143 @@ +#!/bin/sh +# + +# +# 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. +# + +# Assignment of default values done by rvi_install.sh +echo ${RVI_LIBDIR:="__RVI_LIBDIR__"} > /dev/null +echo ${RVI_BINDIR:="__RVI_BINDIR__"} > /dev/null +echo ${RVI_LOGDIR:="__RVI_LOGDIR__"} > /dev/null +echo ${ERL:=erl} > /dev/null + + + +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 " Mandatory for start and console. Ignored for" + echo " all other commands." + 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 "Environennt variables. Default value in paranthesis::" + echo "\$RVI_LIBDIR ($RVI_LIBDIR) Location of RVI library files." + echo "\$RVI_BINDIR ($RVI_BINDIR) Location of binary files." + echo "\$RVI_LOGDIR ($RVI_LOGDIR) Location of log files." + exit 1 +} + +CONFIG_FILE="" +SNAME=rvi +COOKIE=rvi_cookie +while getopts "c:" o; do + case "${o}" in + c) + CONFIG_FILE=${OPTARG} + ;; + *) + usage + ;; + esac +done + +shift $((${OPTIND}-1)) +CMD=$1 + + +if [ "${CMD}" != "start" -a "${CMD}" != "stop" -a "${CMD}" != "console" -a "${CMD}" != "ping" ] +then + usage +fi + +RUNDIR=${RVI_RUNDIR:-"/tmp/rvi"}/$(basename ${CONFIG_FILE} .config) + +export ERL_LIBS=${RVI_LIBDIR}:${RVI_LIBDIR}/deps:${RVI_LIBDIR}/components + +# +# See if we need to process a config file +# +if [ ${CMD} = "start" -o ${CMD} = "console" ] +then + if [ -z "${CONFIG_FILE}" ] + then + echo "Missing -c <config_file> argument." + usage + fi + # + # 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/[cfg]/sys.config + # + ( + rm -rf ${RUNDIR} + install -D -d --mode=0755 ${RUNDIR} + cd ${RUNDIR} + ${RVI_BINDIR}/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 ${RUNDIR}/rvi/start -sname ${SNAME} -config ${RUNDIR}/rvi/sys -setcookie ${COOKIE}" + +case "${CMD}" in + start) + install -D -d --mode 0755 ${RVI_LOGDIR} + exec run_erl -daemon ${RUNDIR}/ ${RVI_LOGDIR} "exec ${LAUNCH}" + ;; + + console) + exec ${LAUNCH} + ;; + + stop) + exec ${RVI_BINDIR}/nodetool -sname ${SNAME} -setcookie ${COOKIE} stop + ;; + + ping) + exec ${RBI_BINDIR}/nodetool -sname ${SNAME} -setcookie ${COOKIE} ping + ;; + + attach) + exec to_erl ${RUNDIR} + ;; + +esac + diff --git a/scripts/rvi_install.sh b/scripts/rvi_install.sh index 7e949a1..03d325d 100755 --- a/scripts/rvi_install.sh +++ b/scripts/rvi_install.sh @@ -8,32 +8,33 @@ # # -# Setup an RVI release with a configuration file. +# Setup an RVI release # -# 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 "Usage: $0 binary_dir library_dir log_dir [prefix_strip]" echo - echo "RVI will be installed in 'target_dir'." + echo "RVI binaries will be installed in 'binary_dir'." + echo "RVI libraries will be installed in 'library_dir'." + echo "RVI logging will be done in 'log_dir'." + echo + echo "If 'prefix_strip' is provided, that part of the directories above" + echo "will be stripped of the given prefix in all internlal references." + echo + echo "If, for example, 'binary_dir' is './build/root/usr/bin', and" + echo "'perfix_strip' is './build/root', all internal references" + echo "in the files installed udner './build/root/usr/bin' will" + echo "reference '/usr/bin'." + echo "Useful in build systems where packages are built up" + echo "in subdirectories." 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" + echo "The created node can be started with: 'binary_dir'/rvi_ctl" + echo "The RVI installation will rely on a separate erlang install" + echo "to run." exit 1 } @@ -41,7 +42,7 @@ usage() { shift $((${OPTIND}-1)) -if [ "${#}" != "1" ] +if [ "${#}" != "3" -a "${#}" != "4" ] then echo "Target directory not specifiied." usage @@ -67,7 +68,9 @@ install --mode=0755 -d ${TARGET_DIR}/scripts FILE_SET=$(find priv ebin components deps -name ebin -o -name priv) -echo "Installing rvi at ${TARGET_DIR}." +install --mode=0755 -d ${BIN_DIR} +install --mode=0755 -d ${LIB_DIR} +install --mode=0755 -d ${LOG_DIR} tar cf - ${FILE_SET} | (cd ${TARGET_DIR}/rvi_core ; tar xf - ) install --mode=0755 scripts/rvi.sh ${TARGET_DIR} @@ -78,11 +81,38 @@ install --mode=0755 scripts/rvi_create_device_key.sh ${TARGET_DIR}/scripts install --mode=0755 scripts/rvi_create_certificate_key.sh ${TARGET_DIR}/scripts -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" +# Patch up the rvi with the correct directories. +if [ -s "${PREFIX_STRIP}" ] +then + STRIP_BIN_DIR=$(echo ${BIN_DIR} | sed "s|^${PREFIX_STRIP}||") + STRIP_LIB_DIR=$(echo ${LIB_DIR} | sed "s|^${PREFIX_STRIP}||") + STRIP_LOG_DIR=$(echo ${LOG_DIR} | sed "s|^${PREFIX_STRIP}||") +else + STRIP_BIN_DIR=${BIN_DIR} + STRIP_LIB_DIR=${LIB_DIR} + STRIP_LOG_DIR=${LOG_DIR} +fi +sed -e "s|__RVI_LIBDIR__|${STRIP_LIB_DIR}|g" \ + -e "s|__RVI_BINDIR__|${STRIP_BIN_DIR}|g" \ + -e "s|__RVI_LOGDIR__|${STRIP_LOG_DIR}|g" < scripts/rvi_ctl > /tmp/rvi_ctl + +install --mode=0755 /tmp/rvi_ctl ${BIN_DIR} +install --mode=0755 scripts/setup_gen ${BIN_DIR} +install --mode=0755 rel/files/nodetool ${BIN_DIR} +install --mode=0755 python/rvi_service.py ${BIN_DIR}/rvi_service +install --mode=0755 python/rvi_call.py ${BIN_DIR}/rvi_call +install --mode=0644 python/rvilib.py ${BIN_DIR} +install --mode=0755 python/rvi_get_services.py ${BIN_DIR}/rvi_get_services + +echo "RVI binary files installed under ${BIN_DIR}" +echo "RVI library files installed under ${LIB_DIR}" +echo "RVI log files installed under ${LOG_DIR}" +echo +echo "Start: ${BIN_DIR}/rvi_ctl -c <config_file> start" +echo "Attach started RVI: ${BIN_DIR}/rvi_ctl attach" +echo "Stop: ${BIN_DIR}/rvi_ctl stop" +echo "Start console mode: ${BIN_DIR}/rvi_ctl -c <config_file> console" +echo exit 0 |
