Created
July 5, 2011 17:41
Revisions
-
kylef created this gist
Jul 5, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ pkgname=lxc pkgver=0.7.4.2 pkgrel=1 pkgdesc="Linux Containers" arch=('i686' 'x86_64') url="http://lxc.sourceforge.net/" depends=('bash' 'perl') license=('LGPL') source=("http://lxc.sourceforge.net/download/lxc/$pkgname-$pkgver.tar.gz" lxc.rcd lxc.confd) md5sums=('36fcb0f6a39d2f55130421f342f24ef3' '520594461912e084c220ca37eb97afd2' 'efb0c46839136842e9d3617924a9b5b5') optdepends=('debootstrap: lxc-debian, lxc-lenny, lxc-lucid, lxc-maverick and lxc-natty templates' 'busybox: lxc-busybox template' 'febootstrap: lxc-fedora template') build() { cd "$srcdir/$pkgname-$pkgver" ./configure --localstatedir=/var --prefix=/usr --libexecdir=/usr/bin --sysconfdir=/etc --disable-doc make } package() { cd "$srcdir/$pkgname-$pkgver" make DESTDIR="$pkgdir" install install -d -m755 "$pkgdir/var/lib/lxc" install -d -m755 "$pkgdir/var/run/lxc" install -Dm755 "${srcdir}"/lxc.rcd "${pkgdir}"/etc/rc.d/lxc install -Dm755 "${srcdir}"/lxc.confd "${pkgdir}"/etc/conf.d/lxc cd doc find . -type f -name '*.1' -exec install -D -m644 "{}" "$pkgdir/usr/share/man/man1/{}" \; find . -type f -name '*.5' -exec install -D -m644 "{}" "$pkgdir/usr/share/man/man5/{}" \; find . -type f -name '*.7' -exec install -D -m644 "{}" "$pkgdir/usr/share/man/man7/{}" \; } # vim:set ts=2 sw=2 et: This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ # ----------------------------------------------------------------------- # LXC CONTAINERS # ----------------------------------------------------------------------- # # Containers to start at boot-up (in this order) # - prefix a container with a ! to disable it # CONTAINERS=(!vm0) #end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,90 @@ #!/bin/bash . /etc/rc.conf . /etc/rc.d/functions [ -f /etc/conf.d/lxc ] && source /etc/conf.d/lxc add_lxc() { >| /var/run/lxc/"$1" } rm_lxc() { /bin/rm -f /var/run/lxc/"$1" } ck_lxc() { [[ ! -f /var/run/lxc/$1 ]] } start_lxc() { container=$1 stat_busy "Starting Linux container: $container" /usr/bin/lxc-start -n $container -q -d sleep 0.5 # lxc-info will not say we are running if we ask it right after lxc-start state="$(lxc-info -n "${container}" | sed -e 's/.* is //')" if [ "$state" = "RUNNING" ]; then stat_done add_lxc $container else stat_fail fi } stop_lxc() { container=$1 stat_busy "Stopping Linux container: $container" /usr/bin/lxc-stop -n $container state="$(lxc-info -n "${container}" | sed -e 's/.* is //')" if [ "$state" = "RUNNING" ]; then stat_fail else stat_done rm_lxc $container fi } case "$1" in start) if [ -z "$2" ] ; then for container in "${CONTAINERS[@]}"; do if [ "${container}" = "${container#!}" ]; then start_lxc $container fi done add_daemon lxc else start_lxc $2 fi ;; stop) if [ -z "$2" ] ; then # Stop all lxc not in the CONTAINERS array for container in /var/run/lxc/*; do [[ -f $container ]] || continue container=${container##*/} in_array "$container" "${CONTAINERS[@]}" || stop_lxc "$container" done # Stop the containers from $CONTAINERS (in reverse order) for (( i=${#CONTAINERS[@]}-1; i>=0; i-- )); do [[ ${CONTAINERS[i]} = '!'* ]] && continue ck_lxc ${CONTAINERS[i]} || stop_lxc ${CONTAINERS[i]} done rm_daemon lxc else stop_lxc $2 fi ;; restart) $0 stop $2 $0 start $2 ;; *) echo "usage: $0 {start|stop|restart} [container-name]" esac