From da7971c60d079a66d58045b46fd2ad9fe5779b24 Mon Sep 17 00:00:00 2001 From: mis Date: Sat, 20 Aug 2016 18:49:24 +0200 Subject: [PATCH] - initial version (docker.spec based); please add gid 331 to PLD-doc - I have no access to CVS probably --- lxd.init | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++ lxd.service | 18 ++++++++ lxd.spec | 71 ++++++++++++++++++++++++++--- lxd.sysconfig | 11 +++++ 4 files changed, 217 insertions(+), 5 deletions(-) create mode 100755 lxd.init create mode 100644 lxd.service create mode 100644 lxd.sysconfig diff --git a/lxd.init b/lxd.init new file mode 100755 index 0000000..329d74a --- /dev/null +++ b/lxd.init @@ -0,0 +1,122 @@ +#!/bin/sh +# +# Container hypervisor and a new user experience for LXC +# +# chkconfig: 345 20 80 +# +# processname: lxd +# pidfile: /var/run/lxd.pid +# + +# Source function library +. /etc/rc.d/init.d/functions + +# Get network config +. /etc/sysconfig/network + +# Check that networking is up. +if is_yes "${NETWORKING}"; then + if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then + msg_network_down "lxd" + exit 1 + fi +else + exit 0 +fi + +# Get service config - may override defaults +[ -f /etc/sysconfig/lxd ] && . /etc/sysconfig/lxd +OPTIONS="$OPTIONS --group lxd --logfile /var/log/lxd/lxd.log" + +pidfile="/var/run/lxd.pid" + +start() { + if status --pidfile $pidfile lxd lxd >/dev/null; then + msg_already_running "lxd" + return + fi + + msg_starting "lxd" + daemon --fork --waitforname lxd /usr/sbin/lxd daemon $OPTIONS + + # lxd does not write pidfile, so create one + show "Checking lxd daemon status" + busy + pid="" + ntry=0 + while [ -z "$pid" -a $ntry -lt 5 ]; do + [ -z "$pid" ] && sleep 1 + pid=$(lxc info 2>/dev/null | grep serverpid: | awk '{print $2}') + echo $pid > $pidfile + ntry=$(expr $ntry+1) + done + + if [ -n "$pid" ]; then + touch /var/lock/subsys/lxd + ok + RETVAL=0 + else + fail + RETVAL=1 + fi +} + +stop() { + if [ ! -f /var/lock/subsys/lxd ]; then + msg_not_running "lxd" + return + fi + + # Stop daemons. + msg_stopping "lxd" + /usr/sbin/lxd shutdown + busy + sleep 1 + if status --pidfile $pidfile lxd lxd >/dev/null; then + killproc --pidfile $pidfile lxd + else + ok + fi + rm -f /var/lock/subsys/lxd +} + +condrestart() { + if [ ! -f /var/lock/subsys/lxd ]; then + msg_not_running "lxd" + RETVAL=$1 + return + fi + + stop + start +} + +RETVAL=0 +# See how we were called. +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart) + stop + start + ;; + try-restart) + condrestart 0 + ;; + force-reload) + condrestart 7 + ;; + status) + status --pidfile $pidfile lxd lxd + RETVAL=$? + ;; + *) + msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}" + exit 3 +esac + +exit $RETVAL diff --git a/lxd.service b/lxd.service new file mode 100644 index 0000000..f82286b --- /dev/null +++ b/lxd.service @@ -0,0 +1,18 @@ +[Unit] +Description=LXD Container Hypervisor +Documentation=http://linuxcontainers.org +After=network.target + +[Service] +Type=notify +ExecStart=/usr/sbin/lxd daemon --syslog +ExecReload=/bin/kill -s HUP $MAINPID +LimitNOFILE=infinity +LimitNPROC=infinity +LimitCORE=infinity +TimeoutStartSec=0 +Delegate=yes +KillMode=process + +[Install] +WantedBy=multi-user.target diff --git a/lxd.spec b/lxd.spec index b9bf7e6..4adebc0 100644 --- a/lxd.spec +++ b/lxd.spec @@ -1,16 +1,34 @@ Summary: Fast, dense and secure container management Name: lxd -Version: 2.0.3 +Version: 2.1 Release: 0.1 License: Apache v2.0 -Group: Applications/Networking -URL: https://linuxcontainers.org/lxd/introduction/ +Group: Applications/System +Source0: https://linuxcontainers.org/downloads/%{name}/%{name}-%{version}.tar.gz +# Source0-md5: 7990440b022e93f3e7036bcfd12970f2 +Source1: %{name}.service +Source2: %{name}.init +Source3: %{name}.sysconfig +URL: http://linuxcontainers.org +BuildRequires: golang >= 1.6 +BuildRequires: rpmbuild(macros) >= 1.228 +Requires(post,preun): /sbin/chkconfig +Requires(postun): /usr/sbin/groupdel +Requires(pre): /usr/bin/getgid +Requires(pre): /usr/sbin/groupadd +Requires: rc-scripts >= 0.4.0.10 +Requires: squashfs +Requires: uname(release) >= 4.1 +Provides: group(lxd) BuildRoot: %{tmpdir}/%{name}-%{version}-root-%(id -u -n) +# binary stripped or something +%define _enable_debug_packages 0 + %description LXD is a container "hypervisor" and a new user experience for LXC. -Specifically, it's made of three components: +Specifically, it is made of three components: - A system-wide daemon (lxd) - A command line client (lxc) - An OpenStack Nova plugin (nova-compute-lxd) @@ -22,7 +40,7 @@ The command line tool is designed to be a very simple, yet very powerful tool to manage all your containers. It can handle connect to multiple container hosts and easily give you an overview of all the containers on your network, let you create some more where you want -them and even move them around while they're running. +them and even move them around while they are running. The OpenStack plugin then allows you to use your lxd hosts as compute nodes, running workloads on containers rather than virtual machines. @@ -31,12 +49,55 @@ nodes, running workloads on containers rather than virtual machines. %setup -q %build +export GOPATH=$(pwd)/dist +cd $GOPATH/src/github.com/lxc/lxd/ +go install -v ./lxd +go install -v ./lxc %install rm -rf $RPM_BUILD_ROOT +install -d $RPM_BUILD_ROOT{%{_bindir},%{_sbindir},%{_mandir}/man1,/etc/{rc.d/init.d,sysconfig},%{systemdunitdir}} \ + $RPM_BUILD_ROOT/var/lib/%{name} \ + $RPM_BUILD_ROOT/var/log/%{name} + +install -p dist/bin/lxd $RPM_BUILD_ROOT%{_sbindir}/ +install -p dist/bin/lxc $RPM_BUILD_ROOT%{_bindir}/ + +cp -p %{SOURCE1} $RPM_BUILD_ROOT%{systemdunitdir} +install -p %{SOURCE2} $RPM_BUILD_ROOT/etc/rc.d/init.d/%{name} +cp -p %{SOURCE3} $RPM_BUILD_ROOT/etc/sysconfig/%{name} + +%pre +%groupadd -g 297 %{name} + +%post +/sbin/chkconfig --add %{name} +%service -n %{name} restart +%systemd_post %{name}.service + +%preun +if [ "$1" = "0" ]; then + %service -q %{name} stop + /sbin/chkconfig --del %{name} +fi +%systemd_preun %{name}.service + +%postun +if [ "$1" = "0" ]; then + %groupremove %{name} +fi +%systemd_reload %clean rm -rf $RPM_BUILD_ROOT %files %defattr(644,root,root,755) +%doc README.md CONTRIBUTING.md AUTHORS +%config(noreplace) %verify(not md5 mtime size) /etc/sysconfig/%{name} +%attr(754,root,root) /etc/rc.d/init.d/%{name} +%attr(755,root,root) %{_bindir}/lxc +%attr(755,root,root) %{_sbindir}/%{name} +%{systemdunitdir}/%{name}.service +%dir %attr(700,root,root) /var/lib/%{name} +%dir %attr(750,root,logs) /var/log/%{name} diff --git a/lxd.sysconfig b/lxd.sysconfig new file mode 100644 index 0000000..fdae0d0 --- /dev/null +++ b/lxd.sysconfig @@ -0,0 +1,11 @@ +# Customized settings for LXD + +# Define nice level for lxd +SERVICE_RUN_NICE_LEVEL="+0" + +# Setup bigger Max open files and Max processes +SERVICE_LIMITS="-n 1048576 -u 1048576" + +# Modify these options if you want to change the way the lxd daemon runs +#OPTIONS="" + -- 2.44.0