Skip to content

Instantly share code, notes, and snippets.

@alban
Created July 24, 2018 15:18
Show Gist options
  • Save alban/793274bd3fc063c3ff51a2c795b15669 to your computer and use it in GitHub Desktop.
Save alban/793274bd3fc063c3ff51a2c795b15669 to your computer and use it in GitHub Desktop.
ctroci.sh
#!/bin/bash
CTR=/home/alban/go/src/github.com/containerd/containerd/bin/ctr
NS=ocitests
echo "$@" >> /tmp/ctroci.log
verb=$1
shift
if [ "$1" == "--pid-file" ] ; then
pidfileparam="--pid-file $2"
shift 2
fi
if [ "$1" == "--bundle" ] ; then
bundle=$2
configfile=$bundle/config.json
rootfs=`jq -r '.root.path' < $configfile`
if ! [[ "$rootfs" =~ ^/ ]]; then
rootfs=`readlink -f $bundle/$rootfs`
fi
shift 2
fi
docreate () {
mkdir -p /tmp/ctroci-fifo
mkfifo /tmp/ctroci-fifo/$1-stdout
echo $CTR -n $NS containers create $pidfileparam --config $configfile --rootfs $rootfs $@ >> /tmp/ctroci.log
$CTR -n $NS containers create $pidfileparam --config $configfile --rootfs $rootfs $@
echo $CTR -n $NS tasks create $@ >> /tmp/ctroci.log
$CTR -n $NS tasks create $@
cat < /tmp/ctroci-fifo/$1-stdout &
}
dostart () {
echo $CTR -n $NS tasks start $@ >> /tmp/ctroci.log
$CTR -n $NS tasks start $@ | tee /tmp/ctroci-fifo/$1-stdout &>> /tmp/ctroci.log
}
dostate () {
runc --root=/run/containerd/runc/$NS list >> /tmp/ctroci.log
$CTR -n $NS task list >> /tmp/ctroci.log
echo runc --root=/run/containerd/runc/$NS state $@ >> /tmp/ctroci.log
runc --root=/run/containerd/runc/$NS state $@
}
dodelete () {
echo $CTR -n $NS containers delete $@ >> /tmp/ctroci.log
$CTR -n $NS containers delete $@
}
case $verb in
create)
docreate "$@"
;;
start)
dostart "$@"
;;
state)
dostate "$@"
;;
delete)
dodelete "$@"
;;
*)
echo "unknown command $verb" >> /tmp/ctroci.log
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment