From fb7b684cd9235f6c870893a61685a3f6b9ba857e Mon Sep 17 00:00:00 2001 From: Brian Seymour Date: Fri, 2 Nov 2018 00:21:22 -0500 Subject: [PATCH] file locking --- .gitignore | 1 + lxc/execute | 7 ++++++- lxc/notes.txt | 6 +++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 2686a19..764c63f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ api/api lxc/i +lxc/lockfile diff --git a/lxc/execute b/lxc/execute index 84e2741..019ed94 100755 --- a/lxc/execute +++ b/lxc/execute @@ -2,6 +2,8 @@ dir="$( cd "$( dirname "$0" )" && pwd )" +touch $dir/lockfile + if [ -z "$1" ]; then echo "invalid args" exit @@ -12,7 +14,7 @@ if [ -z "$2" ]; then fi lang=$1 -epoch=$(date +%s%3N) +epoch=$(date +%s%N) basepath="/var/lib/lxc/piston/rootfs" filepath="/tmp/$epoch/code.code" argpath="/tmp/$epoch/args.args" @@ -25,6 +27,8 @@ cat $2 > $basepath$filepath echo "${@:3}" > $basepath$argpath # process incrementor +exec 200>$dir/lockfile +flock -x 200 oldinc=$(cat $dir/i | awk '{$1=$1};1') newinc=$(expr $oldinc + 1) @@ -34,6 +38,7 @@ if (( newinc >= 151 )); then else echo $newinc > $dir/i fi +exec 200>&- bin= case "$lang" in diff --git a/lxc/notes.txt b/lxc/notes.txt index 683a2d1..41bcf7f 100644 --- a/lxc/notes.txt +++ b/lxc/notes.txt @@ -13,11 +13,11 @@ lxc-attach -n piston export PATH=/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin sed -i 's/http:\/\/archive.ubuntu.com\/ubuntu/http:\/\/mirror.math.princeton.edu\/pub\/ubuntu/' /etc/apt/sources.list apt-get update -apt-get -y install ubuntu-make apt-get -y install git tzdata nano dpkg-dev build-essential python python3 ruby nodejs golang php7.2 r-base mono-complete nasm openjdk-8-jdk +apt-get -y install ubuntu-make umake swift -set dir to /opt -ln -s /opt/swift/usr/bin/swift /usr/bin/swift +set dir to /opt/swift/swift-lang +ln -s /opt/swift/swift-lang/usr/bin/swift /usr/bin/swift # create users and apply limits