From 2f4a2de298c5f4b552007ca72810f3f6f4f83313 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Tue, 10 Apr 2012 18:41:02 +0200 Subject: [PATCH] new package lxc-sliceimage --- cron.d/lxc-sliceimage | 9 +++++++ initscripts/lxc-sliceimage | 54 ++++++++++++++++++++++++++++++++++++++ logrotate/lxc-sliceimage | 8 ++++++ lxc-sliceimage.spec | 51 +++++++++++++++++++++++++++++++++++ 4 files changed, 122 insertions(+) create mode 100644 cron.d/lxc-sliceimage create mode 100644 initscripts/lxc-sliceimage create mode 100644 logrotate/lxc-sliceimage create mode 100644 lxc-sliceimage.spec diff --git a/cron.d/lxc-sliceimage b/cron.d/lxc-sliceimage new file mode 100644 index 0000000..a47096f --- /dev/null +++ b/cron.d/lxc-sliceimage @@ -0,0 +1,9 @@ +# +# Runs once a day to update the VServer reference images and system +# slice configuration files +# +# Mark Huang +# Copyright (C) 2006 The Trustees of Princeton University +# + +@M@ @H@ * * * root /etc/init.d/lxc-sliceimage start >/dev/null 2>&1 diff --git a/initscripts/lxc-sliceimage b/initscripts/lxc-sliceimage new file mode 100644 index 0000000..8d078d3 --- /dev/null +++ b/initscripts/lxc-sliceimage @@ -0,0 +1,54 @@ +#!/bin/bash +# chkconfig: 345 20 80 +# description: Create BTRFS subvolumes for LXC reference images. +# + + +case "$1" in + start|restart|reload) + ;; + force) + FORCE=true;; + stop|status) + exit 0 + ;; + *) + echo $"Usage: $0 {start|stop|restart|reload|status|force}" + exit 1 + ;; +esac + +# Check if we are in the build environment +mount | grep -q 'planetlab-vservers' || exit 0 + +# Source function library +. /etc/init.d/functions + +# xxx get version some other way +# might just want to scan /vservers/.vref instead +# upgrades (from the real image to the .lvref area) might be challenging +# xxx + +sliceimage_dir=/vservers/.vref + +[ -d $sliceimage_dir ] || exit 0 + +sliceimages=$(cd $sliceimage_dir ; ls ) + +for sliceimage in $sliceimages; do + mkdir -p /vservers/.lvref + [ -d /vservers/.lvref/$sliceimage ] && continue + btrfs subvolume create /vservers/.lvref/$sliceimage +# what is that ? +# btrfs subvolume create /vservers/.lvref/lxc-squeeze-x86_64 + # copy the slice image into the btrfs ? + tar -C $sliceimage_dir -cf - $sliceimage | tar -C /vservers/.lvref -xf - +# we need a smarter way to handle upgrades +# the original code trashed the ref image that came with an rpm +# rm -rf /vservers/lxc-reference-${VERSION}.tgz +# this would probably cause the image to be re-created upon yum update +# or prevent updates to make it to the node ? +# rm -rf $sliceimage_dir/$sliceimage +fi + +exit 0 diff --git a/logrotate/lxc-sliceimage b/logrotate/lxc-sliceimage new file mode 100644 index 0000000..b624c58 --- /dev/null +++ b/logrotate/lxc-sliceimage @@ -0,0 +1,8 @@ +/var/log/lxc-sliceimage { + copytruncate + compress + daily + notifempty + rotate 5 + missingok +} diff --git a/lxc-sliceimage.spec b/lxc-sliceimage.spec new file mode 100644 index 0000000..10e5aa4 --- /dev/null +++ b/lxc-sliceimage.spec @@ -0,0 +1,51 @@ +%define name lxc-sliceimage +%define version 5.1 +%define taglevel 0 + +%define release %{taglevel}%{?pldistro:.%{pldistro}}%{?date:.%{date}} + +Vendor: PlanetLab +Packager: PlanetLab Central +Distribution: PlanetLab %{plrelease} +URL: %{SCMURL} + +Summary: lxc-specific node code for slice families +Name: %{name} +Version: %{version} +Release: %{release} +Source0: %{name}-%{version}.tar.bz2 +License: GPL +Group: Applications/System +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot +Requires: btrfs-progs +BuildArch: noarch + +%description +A simple package to deploy reference images for lxc + +%prep +%setup -q + +%build + +%install +rm -rf $RPM_BUILD_ROOT +install -D -m 755 initscripts/lxc-sliceimage ${RPM_BUILD_ROOT}/%{_initrddir}/lxc-sliceimage +install -D -m 644 cron.d/lxc-sliceimage $RPM_BUILD_ROOT/%{_sysconfdir}/cron.d/lxc-sliceimage +install -D -m 644 logrotate/lxc-sliceimage $RPM_BUILD_ROOT/%{_sysconfdir}/logrotate.d/lxc-sliceimage + +%clean +rm -rf $RPM_BUILD_ROOT + +%files +%{_initrddir}/lxc-sliceimage +%{_sysconfdir}/cron.d/lxc-sliceimage +%{_sysconfdir}/logrotate.d/lxc-sliceimage + +%post +chkconfig --add lxc-sliceimage +chkconfig lxc-sliceimage on +# Randomize daily run time +M=$((60 * $RANDOM / 32768)) +H=$((24 * $RANDOM / 32768)) +sed -i -e "s/@M@/$M/" -e "s/@H@/$H/" %{_sysconfdir}/cron.d/lxc-sliceimage -- 2.43.0