Moved disco-ball to universe, added functions necessary for fetching, templating, and executing a given disco ball. Made all existing scripts aware of NOOP and how to change their DISCOROOT accordingly. Added skeleton restricted.d/* files for a semi-safe base system. Added disco-param that allows management of parameters on the client (currently isn't smart enough to manage them on the server, or per-module). Added client/bin/disco that actually allows the entire thing to come together and get executed. Still lots of bugs to work out.

This commit is contained in:
2012-08-08 05:30:03 -04:00
parent f51124252e
commit 7d6d94ae3d
10 changed files with 433 additions and 41 deletions

48
client/bin/disco Executable file
View File

@@ -0,0 +1,48 @@
#!/bin/bash
DISCOCFG=/etc/disco
if [ "$NOOP" != "" ]; then
DISCOROOT=/var/disco/testfs/noop
else
DISCOROOT=/var/disco/testfs/real
fi
function main() {
mount | grep $DISCOROOT >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "error: disco filesystem does not appear to be mounted, please exec disco-fs-init, disco-fs-mount, and try again."
exit 1
fi
disco-ball fetch_params
if [ $? -ne 0 ]; then
echo "error: Unable to fetch parameters for this host from remote server"
exit 1
fi
# Create the toposort of all the modules
for module in $(disco-param keys $(hostname)/modules)
do
NOOP="true" disco-ball fetch $module
disco-ball requires $module >> /tmp/$$.tsort
done
for module in $(cat /tmp/$$.tsort | tsort | tac)
do
echo "info: Processing ${module}"
NOOP="true" disco-ball template $module
disco-fs-diff
if [ "$NOOP" == "" ]; then
rsync -aWH /var/disco/testfs/noop/* /
fi
NOOP="$NOOP" disco-ball exec $module
RETVAL=$?
rm -rf /var/disco/testfs/noop/scratchfs/*
if [ $RETVAL -ne 0 ]; then
echo "error: Failed to apply $module."
fi
done
}
main $@

View File

@@ -1,8 +1,13 @@
import os
import sys
DISCOROOT="/var/disco/testfs/real"
if ("NOOP" in os.environ) and (os.environ["NOOP"] != ""):
DISCOROOT="/var/disco/testfs/noop"
def file_is_text(fname):
os.system("file %s > /tmp/%s.typeof" % (os.path.abspath("/var/disco/testfs/scratchfs/" + fname), os.getpid()))
global DISCOROOT
os.system("file %s > /tmp/%s.typeof" % (os.path.abspath(DISCOROOT + "/scratchfs/" + fname), os.getpid()))
with open("/tmp/%s.typeof" % os.getpid(), "r") as ifile:
line = ifile.readline()
if "ASCII" in line:
@@ -10,6 +15,7 @@ def file_is_text(fname):
return False
def main(argc, argv):
global DISCOROOT
for line in sys.stdin.readlines():
line = line.strip("\n")
pid = os.getpid()
@@ -18,13 +24,13 @@ def main(argc, argv):
if file_is_text(fname):
content = ""
with open(os.path.abspath("/var/disco/testfs/scratchfs/%s" % fname), "r") as ifile:
with open(os.path.abspath(DISCOROOT + "/scratchfs/%s" % fname), "r") as ifile:
content = "> " + "> ".join(ifile.readlines())
line = line.replace("(CONTENT)", "\n%s" % (content))
elif os.path.isdir("/var/disco/testfs/scratchfs/" + fname):
elif os.path.isdir(DISCOROOT + "/scratchfs/" + fname):
line = line.replace("(CONTENT)", "directory")
else:
os.system("md5sum /var/disco/testfs/scratchfs/%s > /tmp/%s" % (fname, pid))
os.system("md5sum " + os.path.abspath(DISCOROOT + "/scratchfs/" + fname) + " > /tmp/%s" % (pid))
content = ""
with open("/tmp/%s" % (pid), "r") as ifile:
content = ifile.readline().split(" ")[0]
@@ -32,14 +38,14 @@ def main(argc, argv):
line = line.strip("\n")
if "(OLDMD5SUM)" in line:
fname = line.split(" ")[3]
os.system("md5sum /var/disco/testfs/rootfs/%s > /tmp/%s" % (fname, pid))
os.system("md5sum " + os.path.abspath(DISCOROOT + "/rootfs/" + fname) + " > /tmp/%s" % (pid))
content = ""
with open("/tmp/%s" % (pid), "r") as ifile:
content = ifile.readline().split(" ")[0]
line = line.replace("(OLDMD5SUM)", content).strip("\n")
if "(NEWMD5SUM)" in line:
fname = line.split(" ")[3]
os.system("md5sum /var/disco/testfs/scratchfs/%s > /tmp/%s" % (fname, pid))
os.system("md5sum " + os.path.abspath(DISCOROOT + "/scratchfs/" + fname) + " > /tmp/%s" % (pid))
content = ""
with open("/tmp/%s" % (pid), "r") as ifile:
content = ifile.readline().split(" ")[0]

View File

@@ -1,6 +1,10 @@
#!/bin/bash
DISCOROOT=/var/disco/testfs
if [ "$NOOP" == "" ]; then
DISCOROOT=/var/disco/testfs/real
else
DISCOROOT=/var/disco/testfs/noop
fi
mount | grep $DISCOROOT > /dev/null 2>&1
if [ $? -ne 0 ]; then

View File

@@ -1,14 +1,18 @@
#!/bin/bash
DISCOROOT=/var/disco/testfs
if [ "$NOOP" == "" ]; then
DISCOROOT=/var/disco/testfs/real
else
DISCOROOT=/var/disco/testfs/noop
fi
mount | grep $DISCOROOT >/dev/null 2>&1
if [ $? -ne 0 ]; then
./disco-fs-mount
./disco-fs-mount || exit 1
fi
# Strip out any shebang and put the script in the root
mkdir -p ${DISCOROOT}/restricted/$(dirname $2)
cat $1 | sed s/'^#!.*'/''/g > ${DISCOROOT}/restricted/$2
$(dirname $0)/disco-sh-shell ${DISCOROOT}/restricted/$2
NOOP="$NOOP" $(dirname $0)/disco-sh-shell ${DISCOROOT}/restricted/$2
exit $?

View File

@@ -9,13 +9,12 @@ fi
mount | grep $DISCOROOT >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "disco filesystem is not mounted"
exit 0
exit 1
fi
if [ "$NOOP" != "" ]; then
#chroot ${DISCOROOT}/chroot /bin/env PATH=${DISCOROOT}/restricted/bin:${DISCOROOT}/munge/mungebin /bin/bash --login --restricted $@
chroot ${DISCOROOT}/chroot //bin/bash --login --restricted $@
chroot ${DISCOROOT}/chroot /bin/env PATH=${DISCOROOT}/restricted/bin:${DISCOROOT}/munge/mungebin /bin/bash --restricted $@
else
chroot ${DISCOROOT}/chroot /bin/bash --login $@
chroot ${DISCOROOT}/chroot /bin/bash $@
fi
exit $?