diff options
Diffstat (limited to 'global/overlay/usr/local')
-rwxr-xr-x | global/overlay/usr/local/bin/run-cosmos | 52 | ||||
-rwxr-xr-x | global/overlay/usr/local/sbin/cosmos_vm | 8 |
2 files changed, 42 insertions, 18 deletions
diff --git a/global/overlay/usr/local/bin/run-cosmos b/global/overlay/usr/local/bin/run-cosmos index a37d49f..5f2cbc1 100755 --- a/global/overlay/usr/local/bin/run-cosmos +++ b/global/overlay/usr/local/bin/run-cosmos @@ -1,22 +1,46 @@ -#!/bin/sh +#!/bin/bash # # Simplify running cosmos, with serialization if flock is available. # -set -e +readonly PROGNAME=$(basename "$0") +readonly LOCKFILE_DIR=/tmp +readonly LOCK_FD=200 -FLOCK=`which flock` +lock() { + local prefix=$1 + local fd=${2:-$LOCK_FD} + local lock_file=$LOCKFILE_DIR/$prefix.lock -if [ -x "$FLOCK" ]; then - ($FLOCK --exclusive --wait 60 9 || exit 1 - cosmos $* update - cosmos $* apply - )9>/var/lock/run-cosmos -else - cosmos $* update - cosmos $* apply -fi + # create lock file + eval "exec $fd>$lock_file" + + # acquier the lock + flock -n $fd \ + && return 0 \ + || return 1 +} + +eexit() { + local error_str="$@" + + echo $error_str + exit 1 +} -touch /var/run/last-cosmos-ok.stamp +main () { + lock $PROGNAME || eexit "Only one instance of $PROGNAME can run at one time." + cosmos $* update + cosmos $* apply -find /var/lib/puppet/reports/ -type f -mtime +10 | xargs rm -f + touch /var/run/last-cosmos-ok.stamp + + find /var/lib/puppet/reports/ -type f -mtime +10 | xargs rm -f +} + +main $* + +if [ -f /cosmos-reboot ]; then + rm -f /cosmos-reboot + reboot +fi diff --git a/global/overlay/usr/local/sbin/cosmos_vm b/global/overlay/usr/local/sbin/cosmos_vm index bf27576..5eec8f7 100755 --- a/global/overlay/usr/local/sbin/cosmos_vm +++ b/global/overlay/usr/local/sbin/cosmos_vm @@ -9,8 +9,8 @@ hostname="default" bridge="br0" cpus="1" mem="1024" -repo="git://code.mnt.se/mnt-cosmos.git" -tag="eduid-cosmos" +repo="https://yourhost/myproj-cosmos.git" +tag="cosmos-ops" ip="" gateway="" netmask="" @@ -63,7 +63,7 @@ ssh_authorized_keys: runcmd: - ["mkdir","/tmp/seed"] - ["mount","/dev/vdb","/tmp/seed"] - - ["cp","/tmp/seed/bootstrap-cosmos.sh","/tmp/seed/cosmos_1.2-2_all.deb","/root"] + - ["cp","/tmp/seed/bootstrap-cosmos.sh","/tmp/seed/cosmos_1.5-1_all.deb","/root"] - ["cd","/root"] - "cd /root && /root/bootstrap-cosmos.sh ${hostname} ${repo} ${tag}" @@ -112,7 +112,7 @@ fi mcopy -i ${seed} ${user_data} ::user-data 2>/dev/null mcopy -i ${seed} ${meta_data} ::meta-data 2>/dev/null -mcopy -i ${seed} /etc/cosmos/apt/bootstrap-cosmos.sh /etc/cosmos/apt/cosmos_1.2-2_all.deb :: +mcopy -i ${seed} /etc/cosmos/apt/bootstrap-cosmos.sh /etc/cosmos/apt/cosmos_1.5-1_all.deb :: mv ${seed} /var/lib/libvirt/images/ virsh pool-refresh default |