Commit 5f89b4cc authored by David Mondou's avatar David Mondou
Browse files

Initial commit rigtools 2.0.0

parents
# RigTool
A tool for the gateway which changes functionality based on how it is linked. For example:
`ln -sf rigtool boot_counter`
Using a central application like this allows us to reuse code that multiple applications need access to, thus shrinking the total installation size. It also allows us to make core modifications to the central code without having to duplicate the modifications on multiple code bases.
Rigtool currently has the following functionality:
## boot_counter
Called on boot, this will reset the boot counter and modify the boot partition flags as needed.
boot_counter has the following options:
- `reset` Resets the boot counter if active. If the counter indicates a failed boot, the boot flags will be updated.
- `status` Returns the current counter status as one of the following:
1. "**FAIL**" The system failed to boot after an update.
2. "**SUCCESS**" The system succeeded in booting after an update.
3. "**NORMAL**" The system booted normally.
## boot_toggle
Called after a successful installation, this will toggle the boot flags and set the backup partition flags. If called without any parameters, it will display the current boot flags.
boot_toggle has the following options:
- `k` or `b`
Toggle the kernel / boot flag
- `f` or `r`
Toggle the file system / rootfs flag
Each time a flag is toggled, the previous boot flags are copied to the restore flags position. Because of this, the flags should only be toggled once, either a single flag, or both together, before a reboot.
If no parameters are supplied, the output will be in the format:
- `Current Flags: <k> <f> <k2> <f2>`
Where:
- `<k>` The currently booted kernel
- `<f>` The currently booted file system
- `<k2>` The kernel to restore to on a failed boot
- `<f2>` The file system to restore to on a failed boot
The flags are represented by a `0` or `1` indicating `main` and `alt` respectively.
## dgua
(Device-Ops Gateway Update Agent)
The Rigado interface to Device Ops over the DDI API.
dgua looks for the configuration file in the following order:
- /etc/vesta/dgua/dgua.conf
- /etc/dguc.conf
The following configurations are stored in dgua.conf:
- Settings to use when downloading updates for end devices:
- **MAX_INSTANCES** The maximum number of instances allowed
- **DEVICE_URI** The uri
- **DEVICE_TENANT** The tenant
- Settings to use when downloading updates for the gateway:
- **GATEWAY_URI** The uri
- **GATEWAY_TENANT** The tenant
- **GATEWAY_TARGET_TOKEN** The target token
dgua has the following options:
- `-u gateway [<uri> [<tenant>]]`
Update the gateway, outputs the following:
1. "**Update started**" When the program starts
2. "**Download started**" When the program starts downloading the update file
3. "**Installing update**" After the update file has finished downloading
4. "**Update successful**" After the update was successfully applied
5. "**Update not successful**" If the update could not be applied
6. "**Update not needed**" If the update is not needed for the hardware
7. "**Error: &lt;error message&gt;**" If an error occurred
- `-u <controller id> <security token> [<uri> [<tenant>]]`
Downloads the files needed to update a controller id. Will return a colon delimited list of files that were downloaded.
- `-q gateway [<uri> [<tenant>]]`
Query if an update is available for the gateway. Will return:
1. "**Update available**" If an update is available
2. "**Update not available**" If an update is not available
- `-q <controller id> <security token> [<uri> [<tenant>]]`
Query if an update is available for a specific controller id. Will return:
1. "**Update available**" If an update is available
2. "**Update not available**" If an update is not available
- `-s <controller id> <token> <execution> <status> <progress> [<uri> [<tenant>]]`
Send the current status to the server for a specific controller id
* `<execution>` is one of:
1. "**canceled**" The update was canceled
2. "**rejected**" The update was rejected
3. "**closed**" The update was completed and closed
4. "**proceeding**" The update is being worked on
5. "**scheduled**" The update is scheduled for a later time
6. "**resumed**" Work has resumed on the update
* `<status>` is one of:
1. "**success**" The update was completed successfully
2. "**failure**" The update has failed
3. "**none**" The update has not finished yet
* `<progress>` is the percentage done from 0 to 100
## dgua_service
A service that can be run in the background to check the server at set intervals for gateway updates.
dgua_service looks for the configuration file in the following order:
- /etc/vesta/dgua/dgua.conf
- /etc/dguc.conf
The following configurations are stored in dgua.conf:
- **GATEWAY_UPDATE_INTERVAL** The number of minutes between checks for updates. The default value is 60.
- **GATEWAY_URI** The uri
- **GATEWAY_TENANT** The tenant
- **GATEWAY_TARGET_TOKEN** The target token
dgua_service has the following option:
- `-s [<uri> [<tenant>]]` Start the service with the optional uri and tenant. These values will override those in the `dgua.conf` file.
dgua_service will listen for the signals, `SIGINT` (2) and `SIGTERM` (15). If either signal is detected, the service will exit gracefully.
## board_serial_number
Returns the unit serial number that's burned into the gateway's fuses.
## unit_serial_number
Returns the unit serial number that's burned into the gateway's fuses. This is the value used as the controller id when communicating with device ops. If this value is not set, then board_serial_number is used. If that is not set, then hostname is used.
## Other rigtool features:
- For testing, the compiled app can be called with the name of the link as the first parameter. ie:
`a.out boot_counter -h`
- To display help for a function, all functions support the `-h` and `--help` options.
- Internally, code exists to support the flowing functionality:
1. Reading / Erasing / Writing to nor flash.
2. Sending and receiving from https servers.
3. Reading and Writing JSON data.
4. Printing JSON data to the screen in a human readable form.
5. Flattening a JSON structure to make it easier to access values.
6. Read uboot variables
###################################
# SETTINGS FOR END DEVICE UPDATES #
###################################
# The maximum number of dgua instances allowed when downloading updates for end devices
# Attempts to call additional instances will return an error. The default is 10
MAX_INSTANCES=10
# The maximum number of seconds to wait for data before the connection
# is considered to be timed out
CONNECTION_TIMEOUT=60
# The uri of the server
DEVICE_URI="https://ops.rigado.com"
# The tenant to use when connecting to the server. The default is "default"
DEVICE_TENANT="29428c19-0154-43e8-b83a-bc019115d04e"
# The TargetToken to be added to the header
# ie: "Authorization: TargetToken $DEVICE_TARGET_TOKEN"
# DEVICE_TARGET_TOKEN=""
################################
# SETTINGS FOR GATEWAY UPDATES #
################################
# How often the gateway should look for forced gateway updates, in minutes
GATEWAY_UPDATE_INTERVAL=60
# The uri of the server
GATEWAY_URI=$DEVICE_URI
# The tenant to use when connecting to the server. The default is "default"
GATEWAY_TENANT=$DEVICE_TENANT
# The TargetToken to be added to the header
# ie: "Authorization: TargetToken $GATEWAY_TARGET_TOKEN"
GATEWAY_TARGET_TOKEN=$DEVICE_TARGET_TOKEN
DGUA
----
(Device-Ops Gateway Update Agent)
The Rigado interface to Device Ops over the DDI API.
DGUA can be configured using the configuration file located either at
``/etc/vesta/dgua/dgua.conf or /etc/dgua.conf``.
The following configurations are used:
- Settings to use when downloading updates for end devices:
- **MAX_INSTANCES** The maximum number of instances allowed
- **DEVICE_URI** The uri
- **DEVICE_TENANT** The tenant
- Settings to use when downloading updates for the gateway:
- **GATEWAY_URI** The uri
- **GATEWAY_TENANT** The tenant
- **GATEWAY_TARGET_TOKEN** The target token
DGUA has the following options. Options in square brackets ``[]`` are optional if they are supplied in a configuration file or uboot variable.
- ``-u gateway [<uri> [<tenant>]]`` Update the gateway, outputs the
following:
1. "**Update started**" When the program starts
2. "**Download started**" When the program starts downloading the
update file
3. "**Installing update**" After the update file has finished
downloading
4. "**Update successful**" After the update was successfully applied
5. "**Update not successful**" If the update could not be applied
6. "**Update not needed**" If the update is not needed for the
hardware
7. "**Error: <error message>**" If an error occurred
- ``-u <controller id> <security token> [<uri> [<tenant>]]`` Downloads the
files needed to update a controller id. Returns a colon delimited list
of files that were downloaded.
- ``-q gateway [<uri> [<tenant>]]`` Query if an update is available for
the gateway. Returns:
1. "**Update available**" If an update is available
2. "**Update not available**" If an update is not available
- ``-q <controller id> <security token> [<uri> [<tenant>]]`` Query if an
update is available for a specific controller id. Returns:
1. "**Update available**" If an update is available
2. "**Update not available**" If an update is not available
- ``-s <controller id> <token> <execution> <status> <progress> [<uri> [<tenant>]]``
Send the current status to the server for a specific controller id
- ``<execution>`` is one of:
1. "**canceled**" The update was canceled
2. "**rejected**" The update was rejected
3. "**closed**" The update was completed and closed
4. "**proceeding**" The update is being worked on
5. "**scheduled**" The update is scheduled for a later time
6. "**resumed**" Work has resumed on the update
- ``<status>`` is one of:
1. "**success**" The update was completed successfully
2. "**failure**" The update has failed
3. "**none**" The update has not finished yet
- ``<progress>`` is the percentage done from 0 to 100
dgua_service
-------------
A service that can be run in the background to check the server at set
intervals for gateway updates.
dgua_service can be configured using the configuration file located either at
``/etc/vesta/dgua/dgua.conf or /etc/dgua.conf``.
The following configurations are used:
- **GATEWAY_UPDATE_INTERVAL** The number of minutes between checks
for updates. The default value is 60.
- **GATEWAY_URI** The uri
- **GATEWAY_TENANT** The tenant
- **GATEWAY_TARGET_TOKEN** The target token
dgua_service has the following option:
- ``-s [<uri> [<tenant>]]`` Start the service with the optional uri and
tenant. These values will override those in the ``dgua.conf``
file.
dgua_service will listen for the signals, ``SIGINT`` (2) and
``SIGTERM`` (15). If either signal is detected, the service will exit
gracefully.
Examples
--------
Update the gateway using the default values
``dgua -u gateway``
Check if any updates exist for the device "``bt_pen``", the security token "``abc``", polling the website at "``https://devOps.com``", and the tenent id "``123``"
``dgua -q "bt_pen" "abc" "https://devOps.com" "123"``
Tell the server an update was successful
``dgua -s "bt_pen" "abc" "closed" "success" 100 "https://devOps.com" "123"``
Start the dgua service in the background
``dgua_service -s &``
An example dgua.conf file:
.. code-block::
###################################
# SETTINGS FOR END DEVICE UPDATES #
###################################
# The maximum number of dgua instances allowed when downloading updates for end devices
# Attempts to call additional instances will return an error. The default is 10
MAX_INSTANCES=10
# The uri of the server
DEVICE_URI="https://deviceOps.com"
# The tenant to use when connecting to the server. The default is "default"
DEVICE_TENANT="12345a12-0123-9ab8-b77a-ef012345678d"
################################
# SETTINGS FOR GATEWAY UPDATES #
################################
# How often the gateway should look for forced gateway updates, in minutes
GATEWAY_UPDATE_INTERVAL=60
# The uri of the server
GATEWAY_URI=$DEVICE_URI
# The tenant to use when connecting to the server. The default is "default"
GATEWAY_TENANT=$DEVICE_TENANT
# The TargetToken to be added to the header
# ie: "Authorization: TargetToken $GATEWAY_TARGET_TOKEN"
GATEWAY_TARGET_TOKEN="ABcDef1abcd2345G0HIjklmnOPqRSTU"
\ No newline at end of file
#! /bin/sh
### BEGIN INIT INFO
# Provides: swupdate
# Required-Start: $local_fs
# Should-Start:
# Required-Stop: $local_fs
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start swupdate application
### END INIT INFO
# The definition of actions: (From LSB 3.1.0)
# start start the service
# stop stop the service
# restart stop and restart the service if the service is already running,
# otherwise start the service
# try-restart restart the service if the service is already running
# reload cause the configuration of the service to be reloaded without
# actually stopping and restarting the service
# force-reload cause the configuration to be reloaded if the service supports
# this, otherwise restart the service if it is running
# status print the current status of the service
# The start, stop, restart, force-reload, and status actions shall be supported
# by all init scripts; the reload and the try-restart actions are optional
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="DGUA Service"
NAME="dgua_service"
DAEMON=/usr/bin/dgua_service
. /etc/init.d/functions || exit 1
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
#
# Function that starts the daemon/service
#
do_start() {
exec $DAEMON -s &
}
#
# Function that stops the daemon/service
#
do_stop() {
local pid status
status=0
pid=`pidofproc $NAME` || status=$?
case $status in
0)
# Exit when fail to stop, the kill would complain when fail
kill -s 15 $pid >/dev/null && \
echo "Stopped $DESC ($pid)." || exit $?
;;
*)
echo "$DESC is not running; none killed." >&2
;;
esac
return $status
}
#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
local pid status
status=0
# If the daemon can reload its configuration without
# restarting (for example, when it is sent a SIGHUP),
# then implement that here.
pid=`pidofproc $NAME` || status=$?
case $status in
0)
echo "Reloading $DESC ..."
kill -s 1 $pid || exit $?
;;
*)
echo "$DESC is not running; none reloaded." >&2
;;
esac
exit $status
}
#
# Function that shows the daemon/service status
#
status_of_proc () {
local pid status
status=0
pid=`pidofproc $NAME` || status=$?
case $status in
0)
echo "$DESC is running ($pid)."
exit 0
;;
*)
echo "$DESC is not running." >&2
exit $status
;;
esac
}
case "$1" in
start)
do_start
;;
stop)
do_stop || exit $?
;;
restart)
# Always start the service regardless the status of do_stop
do_stop
do_start
;;
force-reload)
# Only start the service when do_stop succeeds
do_stop && do_start
;;
status)
status_of_proc
;;
*)
echo "Usage: $0 {start|stop|restart|force-reload|status}" >&2
exit 3
;;
esac
File added
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment