lxc-sliceimage was broken
[sliceimage.git] / initscripts / lxc-sliceimage
1 #!/bin/bash
2 # chkconfig: 345 20 80
3 # description: Create BTRFS subvolumes for LXC reference images.
4 #
5
6 # not needed -- Source function library
7 #. /etc/init.d/functions
8
9 # This is where sliceimage(s) store their reference images
10 sliceimage_dir=/vservers/.vref
11 lxc_dir=/vservers/.lvref
12
13 # Check if we are in the build environment
14 function check_node () {
15     mount | grep -q 'planetlab-vservers' || exit 0
16     [ -d $sliceimage_dir ] || { echo "No sliceimage installed" ; exit 1; }
17 }
18
19 function start () {
20
21     check_node
22
23     sliceimages=$(cd $sliceimage_dir ; ls )
24
25     for sliceimage in $sliceimages; do
26         mkdir -p $lxc_dir
27         # already known to lxc - skip it 
28         # xxx we need a smarter way to handle upgrades
29         [ -d $lxc_dir/$sliceimage ] && continue
30         
31         btrfs subvolume create $lxc_dir/$sliceimage
32         # what is that ?
33         #btrfs subvolume create $lxc_dir/lxc-squeeze-x86_64
34         # copy the slice image into the btrfs ?
35         tar -C $sliceimage_dir -cf - $sliceimage | tar -C $lxc_dir -xf -
36         # the original code trashed the ref image that came with an rpm
37         #rm -rf /vservers/lxc-reference-${VERSION}.tgz
38         # this would probably cause the image to be re-created upon yum update
39         # or prevent updates to make it to the node ?
40         #rm -rf $sliceimage_dir/$sliceimage
41     done
42 }
43
44 function status () {
45     echo -n "Checking node .. "
46     check_node
47     echo OK
48     echo "From installed sliceimage variants"
49     ls $sliceimage_dir
50     echo "Exported to lxc"
51     ls $lxc_dir
52 }
53
54 case "$1" in
55     start|restart|reload)       start ; exit 0 ;;
56     status)                     status ; exit 0 ;;
57     stop)                       exit 0 ;;
58     *)  echo $"Usage: $0 {start|stop|status}"
59         exit 1
60         ;;
61 esac
62