Skip to content

Commit

Permalink
Example lets user interact
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-krolik committed Sep 14, 2016
1 parent 3741138 commit deb3d24
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 13 deletions.
6 changes: 5 additions & 1 deletion examples/tasks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ Running the sample is as *easy* as running the script `./run-mock-psutil.sh`.
## Files

- [run-mock-psutil.sh](run-mock-psutil.sh)
- The example is launched with this script
- The example is launched with this script
- [mock-psutil.sh](mock-psutil.sh)
- Downloads `snapd`, `snapctl`, `snap-plugin-collector-psutil`,
`snap-plugin-publisher-mock-file`, `snap-plugin-processor-passthru` and starts the task
[task-psutil.json](task-mpsutil.json).
- [task-psutil.json](task-psutil.json)
- Snap task definition
- [.setup.sh](.setup.sh)
Expand Down
53 changes: 53 additions & 0 deletions examples/tasks/mock-psutil.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash

set -e
set -u
set -o pipefail

# get the directory the script exists in
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# source the common bash script
. "${__dir}/../../scripts/common.sh"

# ensure PLUGIN_PATH is set
TMPDIR=${TMPDIR:-"/tmp"}
PLUGIN_PATH=${PLUGIN_PATH:-"${TMPDIR}/snap/plugins"}
mkdir -p $PLUGIN_PATH

_info "downloading plugins"
(cd $PLUGIN_PATH && curl -sSO http://snap.ci.snap-telemetry.io/snap/master/latest/snap-plugin-publisher-mock-file && chmod 755 snap-plugin-publisher-mock-file)
(cd $PLUGIN_PATH && curl -sSO http://snap.ci.snap-telemetry.io/snap/master/latest/snap-plugin-processor-passthru && chmod 755 snap-plugin-processor-passthru)
(cd $PLUGIN_PATH && curl -sSO http://snap.ci.snap-telemetry.io/plugin/build/latest/snap-plugin-collector-psutil && chmod 755 snap-plugin-collector-psutil)

SNAP_FLAG=0

# this block will wait check if snapctl and snapd are loaded before the plugins are loaded and the task is started
for i in `seq 1 5`; do
if [[ -f /usr/local/bin/snapctl && -f /usr/local/bin/snapd ]];
then

_info "loading plugins"
snapctl plugin load "${PLUGIN_PATH}/snap-plugin-publisher-mock-file"
snapctl plugin load "${PLUGIN_PATH}/snap-plugin-collector-psutil"
snapctl plugin load "${PLUGIN_PATH}/snap-plugin-processor-passthru"

_info "creating and starting a task"
snapctl task create -t "${__dir}/task-psutil.json"

SNAP_FLAG=1

break
fi

_info "snapctl and/or snapd are unavailable, sleeping for 3 seconds"
sleep 3
done


# check if snapctl/snapd have loaded
if [ $SNAP_FLAG -eq 0 ]
then
echo "Could not load snapctl or snapd"
exit 1
fi
20 changes: 8 additions & 12 deletions examples/tasks/run-mock-psutil.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@ set -u
set -o pipefail

# get the directory the script exists in
__dir="$(cd ../../scripts/docker/large && pwd)"
__proj_dir="$(cd ../../ && pwd)"
#__dir="$(cd ../../scripts/docker/large && pwd)"
__dir=$(cd $(dirname ${BASH_SOURCE[0]})/../../scripts/docker/large && pwd)
__proj_dir="$(cd $(dirname ${BASH_SOURCE[0]})/../../ && pwd)"
__proj_name="$(basename $__proj_dir)"

export PLUGIN_SRC="${__proj_dir}"

# verifies dependencies and starts influxdb
. "${__proj_dir}/examples/tasks/.setup.sh"

# start the influxdb container
(cd $__dir && docker-compose up)

# clean up containers on exit
function finish {
(cd $__dir && docker-compose down)
}
trap finish EXIT INT TERM


# downloads plugins, starts snap, load plugins and start a task
__id=$(docker run -e SNAP_VERSION=latest -d -v ${PLUGIN_SRC}:/${__proj_name} --net=host intelsdi/snap:alpine)
docker exec -it ${__id} bash -c "PLUGIN_PATH=/etc/snap/plugins /${__proj_name}/examples/tasks/mock-psutil.sh && printf \"\n\nhint: type 'snapctl task list'\ntype 'exit' when your done\n\n\" && bash"
docker kill ${__id}

0 comments on commit deb3d24

Please sign in to comment.