Skip to content

Commit

Permalink
Add snap packaging
Browse files Browse the repository at this point in the history
This commit adds a new directory called /snap which contains
the packaging for the edgexfoundry snap.  The snap builds and
includes all of the microservices from the mono-repo, as well
as the two Java-based supports services and device-virtual.
The snap also includes consul, mongodb, and the Java-based
core-config-seed.

Signed-off-by: Tony Espy <[email protected]>
  • Loading branch information
tonyespy committed Jun 19, 2018
1 parent 676f4ef commit 0bc9041
Show file tree
Hide file tree
Showing 9 changed files with 1,026 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ cd $GOPATH/src/github.com/edgexfoundry/edgex-go
glide install
make build
```
## Snap Package
Edgex Foundry is also available as a snap package, for more details
on the snap, including how to install it, please refer to [EdgeX snap](https://github.com/edgexfoundry/edgex-go/snap/README.md)


## Community
- Chat: https://chat.edgexfoundry.org/home
Expand Down
70 changes: 70 additions & 0 deletions snap/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# EdgeX Foundry Core Snap
This project contains snap packaging for the EgdeX Foundry reference implementation.

The snap contains consul, mongodb, all of the EdgeX Go-based micro services from
this repository, and three Java-based services, support-notifications and support-
scheduler, and device-virtual. The snap also contains a single OpenJDK JRE used to
run the Java-based services.

## Installation Requirements
The snap can be installed on any system running snapd, however for full confinement,
the snap must be installed on an Ubuntu 16.04 LTS or later Desktop or Server, or a
system running Ubuntu Core 16.

## Installation
There are amd64 and arm64 versions of both releases available in the store. You can
see the revisions available for your machine's architecture by running the command:

`$ snap info edgexfoundry`

The snap can be installed using this command:

`$ sudo snap install edgexfoundry --channel=california/edge`

**Note** - this snap has only been tested on Ubuntu 16.04 LTS Desktop/Server and Ubuntu Core 16.

## Configuration
The hardware-observe, process-control, and system-observe snap interfaces needs to be
connected after installation using the following commands:

`$ snap connect edgexfoundry-core:hardware-observe core:hardware-observe`

`$ snap connect edgexfoundry-core:process-control core:process-control`

`$ snap connect edgexfoundry-core:system-observe core:system-observe`

## Starting/Stopping EdgeX
To start all the EdgeX microservices, use the following command:

`$ edgexfoundry.start-edgex`

To stop all the EdgeX microservices, use the following command:

`$ edgexfoundry.stop-edgex`

**WARNING** - don't start the EdgeX snap on a system which is already running mongoDB or Consul.

### Enabling/Disabling service startup
It's possible to a effect which services are started by the start-edgex script by
editing a file called `edgex-services-env` which can be found in the directory `/var/snap/edgexfoundry/current` (aka $SNAP_DATA).

**Note** - this file is created by the start-edgex script, so the script needs to be run at least once to copy the default version into place.

## Limitations

* none of the services are actually defined as such in snapcraft.yaml, instead shell-scripts are used to start and stop the EdgeX microservices and dependent services such as consul and mongo.

* some of the new Go-based core services (export-*) currently don't load configuration from Consul

* the new Go-based export services don't generate local log files

## Building

This snap can be built on an Ubuntu 16.04 LTS system:

* install snapcraft
* clone this git repo
* cd edgex-core-snap
* snapcraft

This should produce a binary snap package called edgex-core-snap_<latest version>_<arch>.snap.
47 changes: 47 additions & 0 deletions snap/bin/start-config-seed.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/sh
set -x

if [ `arch` = "aarch64" ] ; then
ARCH="arm64"
elif [ `arch` = "x86_64" ] ; then
ARCH="amd64"
else
echo "Unsupported architecture: `arch`"
exit 1
fi

JAVA="$SNAP/usr/lib/jvm/java-8-openjdk-$ARCH/jre/bin/java"

MAX_TRIES=10

while [ "$MAX_TRIES" -gt 0 ] ; do
CONSUL_RUNNING=`curl http://localhost:8500/v1/catalog/service/consul`

if [ $? -ne 0] ||
[ -z $CONSUL_RUNNING ] ||
[ "$CONSUL_RUNNING" = "[]" ] || [ "$CONSUL_RUNNING" = "" ]; then
echo "core-config-seed: consul not running; remaing tries: $MAX_TRIES\n"
sleep 5
MAX_TRIES=`expr $MAX_TRIES - 1`
else
break
fi
done

# start config-seed if consul is up
#
# TODO: this success check could be improved...
if [ $CONSUL_RUNNING != "[]" ] ; then
cd $SNAP/jar/config-seed/

$JAVA -jar -Djava.security.egd=file:/dev/urandom -Xmx100M \
$SNAP/jar/config-seed/core-config-seed.jar


fi






51 changes: 51 additions & 0 deletions snap/bin/start-consul.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/sh
#
# This script includes some configuration copied from the
# core-config-seed's Dockerfile, and is otherwise based
# on two shell scripts which exist in the same directory.
#
# - launch-consul-config.sh
# - docker-entrypoint.sh
#
set -e

CONSUL_ARGS="-server -client=0.0.0.0 -bind=127.0.0.1 -bootstrap -ui"

CONSUL_DATA_DIR=$SNAP_DATA/consul/data
CONSUL_CONFIG_DIR=$SNAP_DATA/consul/config
LOG_DIR=$SNAP_COMMON

# Handle directory creation & data cleanup
if [ -e $CONSUL_DATA_DIR ] ; then
rm -rf $CONSUL_DATA_DIR/*
else
mkdir -p $CONSUL_DATA_DIR
fi

if [ ! -e $CONSUL_CONFIG_DIR ] ; then
mkdir -p $CONSUL_CONFIG_DIR
fi

if [ ! -e $LOG_DIR ] ; then
mkdir -p $LOG_DIR
fi

# Run available startup hooks to have a point to store custom
# logic outside of this script. More of the things from above
# should be moved into these.
#for hook in $SNAP/startup-hooks/* ; do
# [ -x "$hook" ] && /bin/sh -x "$hook"
#done

# TODO: remove trailing '&' if/when services are actually
# enabled in snap/snapcraft.yaml
exec $SNAP/bin/consul agent \
-data-dir="$CONSUL_DATA_DIR" \
-config-dir="$CONSUL_CONFIG_DIR" \
$CONSUL_ARGS | tee $LOG_DIR/core-consul.log &






142 changes: 142 additions & 0 deletions snap/bin/start-edgex.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#!/bin/sh
set -ex

if [ `arch` = "aarch64" ] ; then
ARCH="arm64"
elif [ `arch` = "x86_64" ] ; then
ARCH="amd64"
else
echo "Unsupported architecture: `arch`"
exit 1
fi

JAVA="$SNAP/usr/lib/jvm/java-8-openjdk-$ARCH/jre/bin/java"

# Bootstrap service env vars
if [ ! -e $SNAP_DATA/edgex-services-env ]; then
cp $SNAP/config/edgex-services-env $SNAP_DATA
fi

. $SNAP_DATA/edgex-services-env

echo "Starting config-registry (consul)..."
$SNAP/bin/start-consul.sh

sleep 60

MONGO_DATA_DIR=$SNAP_DATA/mongo/db

echo "Starting config-seed..."
$SNAP/bin/start-config-seed.sh

echo "Starting mongo..."
if [ -e $MONGO_DATA_DIR ] ; then
rm -rf $MONGO_DATA_DIR/*
else
mkdir -p $MONGO_DATA_DIR
fi

$SNAP/mongo/launch-edgex-mongo.sh

if [ $SUPPORT_LOGGING = "y" ] ; then
sleep 60
echo "Starting logging"

cd $SNAP/config/support-logging
$SNAP/bin/support-logging -consul &
fi

if [ $SUPPORT_NOTIFICATIONS = "y" ] ; then
sleep 65
echo "Starting notifications"

$JAVA -jar -Djava.security.egd=file:/dev/urandom -Xmx100M \
-Dspring.cloud.consul.enabled=true \
-Dlogging.file=$SNAP_COMMON/edgex-notifications.log \
$SNAP/jar/support-notifications/support-notifications.jar &
fi


if [ $CORE_METADATA = "y" ] ; then
sleep 33
echo "Starting metadata"

cd $SNAP/config/core-metadata
$SNAP/bin/core-metadata -consul &
fi

if [ $CORE_DATA = "y" ] ; then
sleep 60
echo "Starting core-data"

cd $SNAP/config/core-data
$SNAP/bin/core-data -consul &
fi


if [ $CORE_COMMAND = "y" ] ; then
sleep 60
echo "Starting command"

cd $SNAP/config/core-command
$SNAP/bin/core-command -consul &
fi


if [ $SUPPORT_SCHEDULER = "y" ] ; then
sleep 60
echo "Starting scheduler"

# workaround consul.host=edgex-core-consul bug:
# https://github.com/edgexfoundry/support-scheduler/issues/23

$JAVA -jar -Djava.security.egd=file:/dev/urandom -Xmx100M \
-Dspring.cloud.consul.enabled=true \
-Dspring.cloud.consul.host=localhost \
-Dlogging.file=$SNAP_COMMON/edgex-support-scheduler.log \
$SNAP/jar/support-scheduler/support-scheduler.jar &
fi

if [ $EXPORT_CLIENT = "y" ] ; then
sleep 60
echo "Starting export-client"

# TODO: fix log file in res/configuration.json
cd $SNAP/config/export-client
$SNAP/bin/export-client &
fi

if [ $EXPORT_DISTRO = "y" ] ; then
sleep 60
echo "Starting export-distro"

# TODO: fix log file in res/configuration.json
cd $SNAP/config/export-distro
$SNAP/bin/export-distro &
fi

if [ $DEVICE_VIRTUAL = "y" ] ; then
sleep 60
echo "Starting device-virtual"

# first-time, create sample profile dirs in $SNAP_COMMON
if [ ! -e "$SNAP_COMMON"/bacnet_profiles ]; then
mkdir "$SNAP_COMMON"/bacnet_profiles
cp "$SNAP"/jar/device-virtual/bacnet_sample_profiles/*.yaml \
"$SNAP_COMMON"/bacnet_profiles
fi

if [ ! -e "$SNAP_COMMON"/modbus_profiles ]; then
mkdir "$SNAP_COMMON"/modbus_profiles
cp "$SNAP"/jar/device-virtual/modbus_sample_profiles/*.yaml \
"$SNAP_COMMON"/modbus_profiles
fi

cd $SNAP/jar/device-virtual
$JAVA -jar -Djava.security.egd=file:/dev/urandom -Xmx100M \
-Dspring.cloud.consul.enabled=false \
-Dlogging.level.org.edgexfoundry=DEBUG \
-Dlogging.file=$SNAP_COMMON/edgex-device-virtual.log \
-Dapplication.device-profile-paths=$SNAP_COMMON/bacnet_profiles,$SNAP_COMMON/modbus_profiles \
$SNAP/jar/device-virtual/device-virtual.jar &
fi
Loading

0 comments on commit 0bc9041

Please sign in to comment.