Commit f9b61bf9 by Julien Muchembled

Rewrite of re6st-node packaging

- With a Makefile instead of a shell script to make build files,
  it's easier to only redo the necessary parts.
- Do not bootstrap buildout in advance. This caused build failures on old
  dists when this was done with Python 2.7 (parts/buildout/site.py imported
  a module that does not exist on Python 2.6). Now everything can be prepared
  on a recent dist.
- Minimize list of build-deps. We don't need setuptools anymore.
  We also don't rely on system chrpath anymore because SLE_12 does not have it.
- Refactoring with upstream packaging.
- Debian: fix upgrade path from 're6stnet' package.
- Package re6st manpages and logrotate configuration.
- systemd integration on RPM-based dists.
- Fix shebang of OpenVPN/NetworkManager hooks.
- Do never ship *.py[co] files in packages. Remove them on uninstallation
  (not done yet for Arch).
- chrpath: Suse dists use RUNPATH instead of PATH
- Stop stripping ELF files.
- Greatly reduce size of packages by removing eggs/parts that were only useful
  during the build, like Perl.

TODO: integrate with osc working copy ?

For the record, here is an example to strip ELF files:

strip:
	cd $(DESTDIR)/$(TARGET) \
	&& s() { chmod u+w $$x && strip -v -R .comment -R .note "$$@" $$x; } \
	&& x=`find -type f -executable ! -name '*.so*' |xargs -r file | \
		sed -n 's/:.*ELF.*\(executable\|shared\).*//p'` && s \
	&& x=`find -type f -name '*.so*' |xargs -r file | \
		sed -n 's/:.*ELF.*shared.*//p'` && s --strip-unneeded
1 parent ea302488
......@@ -2,8 +2,7 @@ obs/*/home:VIFIBnexedi*
obs/slapos/slapos-node_*
obs/slapos/slapos-recipe-version
obs/slapos/slapos-version
obs/re6st/re6st-node_*
obs/*/templates/debian.tar.gz
debian.tar.gz
obs/slapos/templates/debian/cron.d
obs/slapos/templates/debian/slapos-node.logrotate
debian-preseed/*.iso
......@@ -13,6 +12,6 @@ slapprepare/dist
slapprepare/slapprepare.egg-info
*.egg-info
.*.swp
build
build/
dist
playbook/install
/re6stnet/
/slapos/
/upstream.mk
/re6st-node_*.tar.gz
/re6st-node_*.dsc
/debian/control
/debian/changelog
/re6stnet.spec
/PKGBUILD
# This file doesn't force specific versions of re6stnet or slapos.
# It automatically clones missing repositories but doesn't automatically pull.
# You have to choose by using git manually.
# Run with SLAPOS_EPOCH=<N> (where <N> is an integer > 1)
# if rebuilding for new SlapOS version but same re6stnet.
# Non-obvious dependencies:
# - Debian: python-debian, python-docutils | python3-docutils
# We could avoid them by doing like for setuptools, but I'd rather go the
# opposite way: simplify the upload part by using the system setuptools and
# recent features from Make 4.
# This Makefile tries to be smart by only rebuilding the necessary parts after
# some change. But as always, it does not handle all cases, so once everything
# works, you should clean up everything before the final prepare+upload.
# TODO:
# - Arch probably needs clean up of *.py[co] files on uninstallation.
# This is done already for DEB/RPM.
# - RPM: automatic deps to system libraries.
# - Each built package should have its own dist version (something like
# -<dist-name><dist-version> suffix), at least to know which one is installed
# after a dist upgrade.
# On the other side, Debian should normally suggest to reinstall because
# package metadata usually differ (e.g. installed size or dependencies), even
# if there's nothing like checksum comparisons. Maybe other dists do as well.
# - Split tarball in several parts (for Debian, this is doable with
# "debtransform" tag):
# - 1 file for each one in download-cache
# - 1 tarball with everything else
# For faster release after re6st development, an intermediate split could be:
# - re6stnet sdist
# - a tarball of remaining download-cache
# - 1 tarball with everything else
# - Make tarballs "reproducible". If the contents does not change, and we don't
# really care about modification times, the result should always be the same.
# It's really annoying that we can't rely on 'osc status' to know whether
# there are real changes or not. 2 ways:
# - This is doable with a very recent of tar (not even in Jessie), in order
# to sort files by name (--sort option). Then there are timestamps:
# see -n option of gzip, and --mtime option of tar.
# - But the best one is probably to use Python instead of tar+gzip.
# And in fact, such Python script should not be limited to that, since many
# intermediate files like re6stnet.spec are so quick to generate that they
# should be produced in RAM.
#
# Note that package don't contain *.py[co] files and they're not generated
# at installation. For this package, it's better like this because it minimizes
# disk usage without slowness (executables are either daemons or run as root).
# If this way of packaging is reused for other software, postinst scripts
# should be implemented.
BOOTSTRAP_URL = http://downloads.buildout.org/1/bootstrap.py
RE6STNET_URL = http://git.erp5.org/repos/re6stnet.git
SLAPOS_URL = http://git.erp5.org/repos/slapos.git
PACKAGE = re6st-node
BIN = re6st-conf re6st-registry re6stnet
NOPART = chrpath flex glib lunzip m4 patch perl popt site_perl xz-utils
TARGET = opt/re6st
ROOT = build
BUILD = $(ROOT)/$(TARGET)
BUILD_KEEP = buildout.cfg extends-cache download-cache
all: tarball debian.tar.gz re6stnet.spec PKGBUILD re6stnet.install
re6stnet:
git clone $(RE6STNET_URL) $@
slapos:
git clone $(SLAPOS_URL) $@
$(BUILD)/buildout.cfg: buildout.cfg.in
mkdir -p $(@D)
python2 -c 'import os; cfg = open("$<").read() % dict( \
SLAPOS="$(CURDIR)/slapos", ROOT="$${buildout:directory}/" \
+ os.path.relpath("$(ROOT)", "$(BUILD)"), \
TARGET="/$(TARGET)"); open("$@", "w").write(cfg)'
$(BUILD)/bin/python: $(BUILD)/buildout.cfg slapos
if [ -e $@ ]; then touch $@; else cd $(BUILD) \
&& rm -rf extends-cache && mkdir -p download-cache extends-cache \
&& wget -qO - $(BOOTSTRAP_URL) | python2 -S \
&& bin/buildout buildout:parts=$(@F); fi
re6stnet/re6stnet.egg-info: $(BUILD)/bin/python re6stnet
rm -f $(BUILD)/download-cache/dist/re6stnet-*
cd re6stnet && ../$< setup.py sdist -d ../$(BUILD)/download-cache/dist
# Touch target because the current directory is used as temporary
# storage, and it is cleaned up after that setup.py runs egg_info.
touch $@
$(BUILD)/.installed.cfg: re6stnet/re6stnet.egg-info
cd $(BUILD) && bin/buildout
# Touch target in case that buildout had nothing to do.
touch $@
$(ROOT)/Makefile: Makefile.in Makefile
($(foreach x,BIN NOPART BUILD_KEEP TARGET, \
echo $(x) = $($(x)) &&) cat $<) > $@
prepare: $(BUILD)/.installed.cfg $(ROOT)/Makefile
$(eval VERSION = $(shell cd $(BUILD)/download-cache/dist \
&& set re6stnet-* && set $${1#*-} \
&& echo -n $${1%.tar.*}+slapos$(SLAPOS_EPOCH).g \
&& cd $(CURDIR)/slapos && git rev-parse --short HEAD))
make -C re6stnet
upstream.mk: re6stnet Makefile
(echo 'override PYTHON = /$(TARGET)/parts/python2.7/bin/python' \
&& cat $</Makefile) > $@
tarball: upstream.mk prepare
tar -caf $(PACKAGE)_$(VERSION).tar.gz \
--xform s,^re6stnet/,, \
--xform s,^,$(PACKAGE)-$(VERSION)/, \
cleanup install-eggs rebootstrap $< \
re6stnet/daemon re6stnet/docs/*.1 re6stnet/docs/*.8 \
-C $(ROOT) Makefile $(patsubst %,$(TARGET)/%,$(BUILD_KEEP))
debian/changelog: prepare
cd re6stnet && sed s,$@,../$@, debian/common.mk | \
make -f - PACKAGE=$(PACKAGE) VERSION=$(VERSION) ../$@
debian/control: debian/source/format prepare Makefile
$(eval DSC = $(PACKAGE)_$(VERSION).dsc)
python2 -c 'from debian.deb822 import Deb822; d = Deb822(); \
b = open("re6stnet/$@"); s = Deb822(b); b = Deb822(b); \
d["Format"] = open("$<").read().strip(); \
d["Source"] = s["Source"] = b["Package"] = "$(PACKAGE)"; \
d["Version"] = "$(VERSION)"; \
d["Architecture"] = b["Architecture"] = "any"; \
d["Build-Depends"] = s["Build-Depends"] = \
"python (>= 2.6), debhelper (>= 8)"; \
b["Depends"] = "$${shlibs:Depends}, iproute2 | iproute"; \
b["Conflicts"] = b["Provides"] = b["Replaces"] = "re6stnet"; \
open("$@", "w").write("%s\n%s" % (s, b)); \
open("$(DSC)", "w").write(str(d))'
debian.tar.gz: $(patsubst %,debian/%,changelog control prerm postinst rules source/*)
# Unfortunately, OBS does not support symlinks.
set -e; cd re6stnet; [ ! -e debian/postinst ]; \
x=`find debian ! -type d $(patsubst %,! -path %,$^))`; \
tar -chaf ../$@ $$x -C .. $^
define SED_SPEC
# https://fedoraproject.org/wiki/Packaging:Python_Appendix#Manual_byte_compilation
1i%global __os_install_post %(echo '%{__os_install_post}' |grep -v brp-python-bytecompile)
/^%define (_builddir|ver)/d
s/^(Name:\s*).*/\1$(PACKAGE)/
s/^(Version:\s*).*/\1$(VERSION)/
s/^(Release:\s*).*/\11/
/^BuildArch:/cAutoReqProv: no\nBuildRequires: gcc-c++, make, python\n#!BuildIgnore: rpmlint-Factory\nSource: %{name}_%{version}.tar.gz
/^Requires:/{/iproute/!d}
/^Recommends:/d
s/^(Conflicts:\s*).*/\1re6stnet/
/^%description$$/a%prep\n%setup -q
/^%preun$$/,/^$$/{/^$$/ifind /$(TARGET) -type f -name '*.py[co]' -delete
}
endef
re6stnet.spec: prepare
$(eval export SED_SPEC)
sed -r "$$SED_SPEC" re6stnet/$@ > $@
PKGBUILD: PKGBUILD.in prepare
sed 's/%VERSION%/$(VERSION)/' $< > $@
clean:
rm -rf "$(ROOT)" *.dsc *.tar.gz re6stnet.spec \
upstream.mk debian/control debian/changelog
# Note that this file and related scripts (rebootstrap, install-eggs) don't
# contain anything specific to re6stnet. They could be reused as is for SlapOS.
# We don't strip ELF files because all dists automatically do it.
# For those that produce debug packages, these packages are anyway quite small
# (debug information also compresses quite well).
BUILD = $(TARGET)
PATH := $(patsubst %,$(CURDIR)/$(BUILD)/parts/%/bin:,chrpath file perl)$(PATH)
PYTHON2 = $(firstword $(wildcard /usr/bin/python2 /usr/bin/python))
all: $(BUILD)/.installed.cfg
ifneq ($(wildcard upstream.mk),)
make -f upstream.mk
%: _%
make -f upstream.mk $@
_install%: _install;
Makefile:;
else
install: _install
endif
$(BUILD)/bin/buildout:
cd $(BUILD) && $(PYTHON2) -S $(CURDIR)/rebootstrap
$(BUILD)/.installed.cfg: $(BUILD)/bin/buildout $(BUILD)/buildout.cfg
cd $(BUILD) && bin/buildout
touch $@
PROGS = $(patsubst %,$(DESTDIR)/usr/bin/%,$(BIN))
_install: $(DESTDIR)/$(TARGET) $(PROGS);
$(PROGS): $(BUILD)/.installed.cfg
mkdir -p $(@D)
sed s,$(CURDIR)/$(BUILD),/$(TARGET),g $(BUILD)/bin/$(@F) > $@
chmod +x $@
$(DESTDIR)/$(TARGET): $(BUILD)/.installed.cfg
rm -rf $@ && mkdir -p $@/parts
cd $(BUILD) && $(PYTHON2) $(CURDIR)/install-eggs $@ $(BIN)
for x in $(filter-out $(NOPART),$(shell cd $(BUILD)/parts && echo *)); \
do cp --preserve=links -r $(BUILD)/parts/$$x $@/parts; done
cd $@ && $(CURDIR)/cleanup && chmod -R u+w .
# Fix paths in files, first ELF, then non-binary
set -e $(CURDIR)/$(BUILD) /$(TARGET); set $$* "s:\\Q$$1\\E:$$2:g"; \
x=`find $@ -type f \( -executable -o -name '*.so*' \) | \
xargs -r file |sed -n 's/:.*ELF.*\(executable\|shared\).*//p' | \
xargs -r chrpath -k |perl -ne "$$3"'; \
s/(.*): R(UN)?PATH=(.*)/chrpath -r $$3 $$1/ and print'`; \
eval "$$x"; \
if x=`grep -rIlF $$1 $@`; then \
echo "Fixing path to $$2 rather than $$1:" $$x; \
perl -pi -e "$$3" $$x; fi
# Fix symlinks at the end because they'll become broken inside DESTDIR.
# Maybe we should generate relative symlinks, or let dists do it.
set -e $(CURDIR)/$(BUILD)/; \
find $@ -type l -lname "$$1*" -printf '%l %p\n' |cut -c"$${#1}"- | \
while read s d; do echo "Fixing symlink $$d"; \
rm $$d; ln -s /$(TARGET)$$s $$d; \
done
clean:
find $(BUILD) -mindepth 1 -maxdepth 1 \
$(patsubst %,! -name %,$(BUILD_KEEP)) |xargs rm -rf
# Maintainer: Rafael Monnerat <rafael@nexedi.com>
pkgname=re6st-node
pkgver=%VERSION%+%RECIPE_VERSION%+%RELEASE%
pkgdesc="re6stnet"
pkgver=%VERSION%
pkgdesc="resilient, scalable, IPv6 network application"
pkgrel=1
arch=('x86_64' 'i686')
url="http://www.re6st.net"
license=('GPL')
depends=('gcc' 'make' 'patch' 'wget' 'python2' 'python2-distribute' 'bridge-utils')
makedepends=('gcc' 'make' 'patch' 'wget' 'python2' 'python2-distribute' 'chrpath' 'inetutils')
depends=('iproute2')
makedepends=('gcc' 'make' 'python2')
install='re6stnet.install'
source=(${pkgname}_${pkgver}.tar.gz)
md5sums=(%SOURCEMD5)
SKIPCHECKSUMS=1
build() {
cd "${srcdir}/${pkgname}_${pkgver}"
make PYTHON=python2
cd "${srcdir}/${pkgname}-${pkgver}"
make
}
package() {
cd "${srcdir}/${pkgname}_${pkgver}"
make DESTDIR="$pkgdir/" install
cd "${srcdir}/${pkgname}-${pkgver}"
make DESTDIR="$pkgdir" PREFIX=/usr install
}
[buildout]
extends =
file://%(SLAPOS)s/stack/slapos.cfg
file://%(SLAPOS)s/component/chrpath/buildout.cfg
file://%(SLAPOS)s/component/re6stnet/buildout.cfg
extends-cache = extends-cache
download-cache = download-cache
develop =
extensions =
newest = false
parts += chrpath python
[python]
recipe = zc.recipe.egg
interpreter = ${:_buildout_section_name_}
eggs = setuptools
python = buildout
scripts =
# Uguu, upstream buildout.cfg must be patched as it works the other way
# around from a packager point of view at least, thus at the end static
# path, such as Python HOME directory, are wrong...
#
# Currently:
# ./configure --prefix=BUILD_DIRECTORY && make install
# Instead of:
# ./configure --prefix=INSTALL_DIRECTORY && make install DESTDIR=BUILD_DIRECTORY
[python2.7]
configure-options +=
--prefix=%(TARGET)s/parts/${:_buildout_section_name_}
environment +=
DESTDIR=%(ROOT)s
#!/bin/sh -e
(cd parts
# Buildout files
rm -r *-patch-download *-hooks-download || :
# Removing gdb, locales, terminfo and base_completion.d directories
find -type d \
\( -name gdb -name locale -o -name terminfo -o -name bash_completion.d \) \
-print0 -prune |xargs -0 rm -rf
rm ncurses/lib/terminfo || :
# Removing gettext archive tarball containing all versions
rm gettext/share/gettext/archive.dir.tar.* || :
# Removing include/pkgconfig files
find -name 'python*' -prune -o \
\( -type d \( -name include -o -name pkgconfig \) \
-o -type f -executable -name '*-config' \
\) -print0 -prune |xargs -0 rm -rf
)
# Removing documentations
find -regextype posix-extended -type d \
-iregex '.*/(gtk-)?(doc[s]?|man|info|test[s]?)$' \
-print0 -prune |xargs -0 rm -rf
find -regextype posix-extended -type f \
-iregex '.*(COPYING|LICENSE).*' -delete
# Removing Python byte-compiled files (as it will be done upon
# package installation) and static libraries
find -regextype posix-extended -type f \
-iregex '.*/*\.(py[co]|[l]?a|exe|bat)$' -delete
# Removing empty directories
find -type d -empty -delete
#!/bin/sh
set -e
# https://lists.debian.org/debian-mentors/2015/12/msg00367.html
x=/var/lib/dpkg/info/re6stnet.postrm
if [ "$1" = "configure" ] && grep -q DPKG_MAINTSCRIPT_PACKAGE $x 2>/dev/null
then sed -ri '1s,^(#!/bin/)sh,\1true\n\0,' $x
fi
#DEBHELPER#
#!/bin/sh
set -e
# BBB: service renamed from 're6st-node' to 're6stnet'
dpkg-maintscript-helper rm_conffile /etc/init.d/re6st-node -- "$@"
#DEBHELPER#
#!/bin/sh
set -e
pyclean() {
local x IFS='
'
x=`dpkg -L $1`
rm -f `for x in $x; do
case $x in *.py) echo $x[co];; esac
done`
}
pyclean $DPKG_MAINTSCRIPT_PACKAGE
#DEBHELPER#
#!/usr/bin/make -f
# -*- makefile -*-
#export DH_VERBOSE=1
include debian/common.mk
override_dh_auto_install:
override_dh_link:
override_dh_makeshlibs:
dh_makeshlibs -n
override_dh_shlibdeps:
dh_shlibdeps -- -x$(PACKAGE)
rm $(TMP)/DEBIAN/shlibs
%:
dh $@
#!/usr/bin/python2
import errno, os, shutil, sys
path = set()
class Stop(Exception):
pass
class SysPath(tuple):
def __setitem__(self, i, v):
path.update(v)
raise Stop
sys_path = sys.path
try:
sys.path = SysPath(sys_path)
for x in sys.argv[2:]:
try:
execfile(os.path.join("bin", x))
except Stop:
pass
finally:
sys.path = sys_path
dest = sys.argv[1]
for x in path:
x = os.path.relpath(x)
d = os.path.join(dest, x)
try:
os.mkdir(os.path.basename(x))
except OSError as e:
if e.errno != errno.EEXIST:
raise
shutil.copytree(x, d, True)
#!/bin/sh -e
# Edit for release
VERSION=0.435
# Edit for release
RECIPE_VERSION=1.0.18
# Edit for release
RELEASE=1
GITHASH=ded003246fc9a65d6030a8f77a770c33bf9d254b
CURRENT_DIRECTORY="$(pwd)"
# Define URL to compile
BUILDOUT_URL=http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-$RECIPE_VERSION:/component/re6stnet/buildout.cfg
OBS_DIRECTORY=$CURRENT_DIRECTORY/home:VIFIBnexedi/Re6stnet
# Development Section [Uncomment for use]
OBS_DIRECTORY=$CURRENT_DIRECTORY/home:VIFIBnexedi:branches:home:VIFIBnexedi/Re6stnet
BUILDOUT_URL=http://git.erp5.org/gitweb/slapos.git/blob_plain/$GITHASH:/component/re6stnet/buildout.cfg
VERSION_REGEX="s!\%BUILDOUT_URL\%!$BUILDOUT_URL!g;s/\%RECIPE_VERSION\%/$RECIPE_VERSION/g;s/\%VERSION\%/$VERSION/g;s/\%RELEASE\%/$RELEASE/g"
TEMPLATES_DIRECTORY=$CURRENT_DIRECTORY/templates
RE6ST_ORGINAL_DIRECTORY=re6st-node
RE6ST_DIRECTORY=re6st-node_$VERSION+$RECIPE_VERSION+$RELEASE
function prepare_template_files
{
# Prepare directory for new version if needed
mkdir -p $CURRENT_DIRECTORY/$RE6ST_DIRECTORY
cp -rf $CURRENT_DIRECTORY/$RE6ST_ORGINAL_DIRECTORY/* $CURRENT_DIRECTORY/$RE6ST_DIRECTORY
sed $VERSION_REGEX $TEMPLATES_DIRECTORY/Makefile.in > $CURRENT_DIRECTORY/$RE6ST_DIRECTORY/re6stnet/Makefile
sed $VERSION_REGEX $TEMPLATES_DIRECTORY/offline.sh.in > $CURRENT_DIRECTORY/$RE6ST_DIRECTORY/re6stnet/offline.sh
}
function prepare_download_cache
{
cd $CURRENT_DIRECTORY/$RE6ST_DIRECTORY/re6stnet/
rm -rf build/
bash offline.sh || (echo "Impossible to build Re6stnet, exiting." && exit 1)
# Go back to starting point
cd $CURRENT_DIRECTORY
}
function prepare_tarball
{
tar -czf $RE6ST_DIRECTORY.tar.gz $RE6ST_DIRECTORY
}
function prepare_deb_packaging
{
# Add entry to changelog
cd $TEMPLATES_DIRECTORY/debian
#dch -pm -v $VERSION+$RECIPE_VERSION+$RELEASE --check-dirname-level=0 "New version of re6st ($VERSION+$RECIPE_VERSION+$RELEASE)"
# Add cron and logrotate files
cd $TEMPLATES_DIRECTORY
tar -czf debian.tar.gz debian
cd $OBS_DIRECTORY
cp $TEMPLATES_DIRECTORY/debian.tar.gz .
}
function obs_upload
{
cd $OBS_DIRECTORY
# Update directory
osc up
# Remove former configuration
osc rm -f $RE6ST_ORGINAL_DIRECTORY*.tar.gz
osc rm -f re6stnet.spec
# Prepare new tarball
cp $CURRENT_DIRECTORY/$RE6ST_DIRECTORY.tar.gz .
osc add $RE6ST_DIRECTORY.tar.gz
# Prepare new specfile
sed $VERSION_REGEX $TEMPLATES_DIRECTORY/re6stnet.spec.in > re6stnet.spec
osc add re6stnet.spec
# Prepare new .dsc file
osc rm -f re6st*.dsc
sed $VERSION_REGEX $TEMPLATES_DIRECTORY/re6stnet.dsc.in > $RE6ST_DIRECTORY.dsc
osc add $RE6ST_DIRECTORY.dsc
osc rm -f PKGBUILD
SOURCEMD5=`md5sum $RE6ST_DIRECTORY.tar.gz | cut -d\ -f1`
sed "$VERSION_REGEX;s/\%SOURCEMD5\%/$SOURCEMD5/g" $TEMPLATES_DIRECTORY/PKGBUILD.in > PKGBUILD
cp $TEMPLATES_DIRECTORY/re6stnet.install .
osc add PKGBUILD re6stnet.install
## Upload new Package
osc commit -m "New Re6stnet Recipe $RECIPE_VERSION"
}
prepare_template_files
prepare_download_cache
prepare_tarball
prepare_deb_packaging
obs_upload
#!/usr/bin/make -f
# -*- makefile -*-
build:
cd re6stnet; make build
all: build
install: all
cd re6stnet; make install
mkdir -p $(DESTDIR)/usr/bin/
mkdir -p $(DESTDIR)/usr/sbin/
cp $(DESTDIR)/opt/re6st/bin/re6st* $(DESTDIR)/usr/bin/
mkdir -p $(DESTDIR)/var/lib/re6stnet
mkdir -p $(DESTDIR)/var/log/re6stnet
mkdir -p $(DESTDIR)/etc/re6stnet
install -Dpm 0644 daemon/README.conf $(DESTDIR)/etc/re6stnet/README
install -Dp daemon/network-manager $(DESTDIR)/etc/NetworkManager/dispatcher.d/50re6stnet
clean:
# cd slapos; make clean
re6stnet configuration files
re6stnet is started automatically if /etc/re6stnet contains a 're6stnet.conf'
file with all parameters to pass to the daemon.
Same for the registry: all parameters must be specified in 're6st-registry.conf'
So for a normal node, you should have the following files:
re6stnet.conf ca.crt cert.crt cert.key dh2048.pem
And if you also host the registry:
re6st-registry.conf ca.key
/var/log/re6stnet/babeld.log {
compress
delaycompress
missingok
notifempty
postrotate
[ -r /var/run/re6st-babeld.pid ] && kill -USR2 $(cat /var/run/re6st-babeld.pid)
endscript
}
#!/usr/bin/python -S
import errno, glob, os, signal, socket, subprocess, sys, time
DAEMON = "re6stnet"
CONFDIR = "/etc/re6stnet"
os.environ["PATH"] = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
iface = sys.argv[1]
action = sys.argv[2]
lock_name = DAEMON + ':' + iface
if action in ("up", "vpn-up"):
os.chdir(CONFDIR)
if os.path.exists("re6stnet.conf") and not subprocess.call(
(DAEMON, "@re6stnet.conf", "--test", "main_interface != %r" % iface)):
s = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
try:
s.bind('\0' + lock_name)
except socket.error, e:
if e[0] != errno.EADDRINUSE:
raise
sys.stderr.write("daemon already started\n")
sys.exit()
if not os.fork():
os.setsid()
os.execlp(DAEMON, DAEMON, "@re6stnet.conf")
elif action in ("down", "vpn-down"):
pattern = " @%s\n" % lock_name
with open("/proc/net/unix") as f:
for line in f:
if line.endswith(pattern):
sock_path = "socket:[%s]" % line.split()[-2]
break
else:
sys.exit()
pattern = "(%s)" % DAEMON
for path in glob.glob("/proc/*/stat"):
try:
pid = int(path[6:-5])
with open(path) as f:
stat = f.read().split()
if stat[1] == pattern and sock_path in (os.readlink(path)
for path in glob.glob(path[:-4] + "fd/*")):
break
except (EnvironmentError, ValueError):
pass
else:
sys.exit()
try:
os.kill(pid, signal.SIGTERM)
sleep = .1
while sleep < 5:
time.sleep(sleep)
os.kill(pid, 0)
sleep *= 1.5
# we waited for about 11 seconds
os.kill(-int(stat[4]), signal.SIGKILL)
except OSError, e:
if e.errno != errno.ESRCH:
raise
[Unit]
Description=Server application for re6snet
ConditionPathExists=/etc/re6stnet/re6st-registry.conf
[Service]
WorkingDirectory=/etc/re6stnet
ExecStart=/usr/bin/env re6st-registry @re6st-registry.conf
Restart=on-failure
[Install]
WantedBy=multi-user.target
[Unit]
Description=Resilient, Scalable, IPv6 Network application
ConditionPathExists=/etc/re6stnet/re6stnet.conf
[Service]
WorkingDirectory=/etc/re6stnet
# systemd plans to "introduce ExecCondition= in services" (cf its TODO file)
ExecStart=/bin/sh -c 'set re6stnet @re6stnet.conf; "$@" --test main_interface==\"lo\" || exec "$@"'
Restart=on-failure
StandardOutput=null
[Install]
WantedBy=multi-user.target
[buildout]
extends =
%BUILDOUT_URL%
# Don't load extensions
extensions =
extends-cache = extends-cache
download-cache = download-cache
develop =
parts =
babeld
re6stnet
# Uguu, upstream buildout.cfg must be patched as it works the other way
# around from a packager point of view at least, thus at the end static
# path, such as Python HOME directory, are wrong...
#
# Currently:
# ./configure --prefix=BUILD_DIRECTORY && make install
# Instead of:
# ./configure --prefix=INSTALL_DIRECTORY && make install DESTDIR=BUILD_DIRECTORY
[python2.7]
configure-options +=
--prefix=%TARGET_DIRECTORY%/parts/${:_buildout_section_name_}
environment +=
DESTDIR=%BUILD_ROOT_DIRECTORY%
[gettext]
# Add gettext library path to RPATH as its binaries are used to build
# glib for example
environment =
PATH=${perl:location}/bin:${lunzip:location}/bin:%(PATH)s
CPPFLAGS=-I${libxml2:location}/include -I${zlib:location}/include -I${ncurses:location}/include
LDFLAGS=-L${libxml2:location}/lib -Wl,-rpath=${libxml2:location}/lib -L${zlib:location}/lib -Wl,-rpath=${zlib:location}/lib -L${ncurses:location}/lib -Wl,-rpath=${ncurses:location}/lib -Wl,-rpath=%BUILD_DIRECTORY%/parts/${:_buildout_section_name_}/lib
[bison]
configure-options +=
--prefix=%TARGET_DIRECTORY%/parts/${:_buildout_section_name_}
make-options +=
DESTDIR=%BUILD_ROOT_DIRECTORY%
[python-cryptography-prep]
recipe = zc.recipe.egg
eggs =
${python-cffi:egg}
enum34
pycparser
six
pyasn1
#!/usr/bin/python2 -S
import glob, os, sys, zipfile
d = "download-cache/dist"
p = "setuptools-*"
x, = glob.glob(d + "/" + p)
zipfile.ZipFile(x).extractall()
sys.path[:0] = p = glob.glob(p)
from setuptools.command.easy_install import main
for x in "bin", "eggs":
try:
os.mkdir(x)
except OSError, e:
pass
main(["-f", d, "-mxd", x, "zc.buildout"])
p.append(*glob.glob("eggs/zc.buildout-*"))
os.write(os.open("bin/buildout", os.O_CREAT|os.O_WRONLY|os.O_TRUNC, 0777), """\
#!%s -S
import os, sys
d = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
d = os.path.dirname(d) + os.sep
sys.path[:0] = (%s)
from zc.buildout.buildout import main
sys.exit(main())
""" % (sys.executable, ", ".join("d + %r" % p for p in p)))
#!/usr/bin/make -f
# -*- makefile -*-
VERSION = %VERSION%
RECIPE_VERSION = %RECIPE_VERSION%
PY = $(PYTHON)
INSTALL_DIRECTORY = $(DESTDIR)/opt/re6st
TARGET_DIRECTORY = /opt/re6st
BUILD_ROOT_DIRECTORY := $(shell pwd)/build
BUILD_DIRECTORY := $(BUILD_ROOT_DIRECTORY)$(TARGET_DIRECTORY)
PATCHES_DIRECTORY := $(shell pwd)/patches
#Use to get path of buildout correct
ORIGINAL_DIRECTORY := $(shell cat ./original_directory)
BOOTSTRAP_URL := 'http://svn.zope.org/*checkout*/zc.buildout/trunk/bootstrap/bootstrap.py?rev=127518'
build: build-stamp
build-stamp:
@echo "Fixing buildout path to $(BUILD_ROOT_DIRECTORY) rather than $(ORIGINAL_DIRECTORY) for buildout"
grep -rIl '$(ORIGINAL_DIRECTORY)' $(BUILD_ROOT_DIRECTORY) 2> /dev/null | \
xargs sed -i 's#$(ORIGINAL_DIRECTORY)#$(BUILD_ROOT_DIRECTORY)#g' || \
echo "No path to fix."
@echo 'Preparing source tarball (recipe version: $(RECIPE_VERSION))'
cd $(BUILD_DIRECTORY) && \
$(PY) ./bin/buildout -v
@touch build-stamp
cleanup-build: cleanup-build-stamp
cleanup-build-stamp: build
@echo "Deleting unecessary files to reduce source tarball size"
# TODO: Figure out why there is no write permission even for
# the owner
chmod -R u+w $(BUILD_DIRECTORY)
# Buildout files
rm -rfv $(BUILD_DIRECTORY)/downloads
rm -fv $(BUILD_DIRECTORY)/bootstrap.py $(BUILD_DIRECTORY)/buildout.cfg \
$(BUILD_DIRECTORY)/bin/buildout $(BUILD_DIRECTORY)/.installed.cfg \
$(BUILD_DIRECTORY)/environment.*
rm -rfv $(BUILD_DIRECTORY)/parts/*-patch-download/ \
$(BUILD_DIRECTORY)/parts/*-hooks-download/
rm -rfv $(BUILD_DIRECTORY)/extends-cache/ \
$(BUILD_DIRECTORY)/download-cache/
# Removing locales, terminfo and base_completion.d directories
find $(BUILD_DIRECTORY) -type d \
\( -name locale -o -name terminfo -o -name bash_completion.d \) \
-prune -exec rm -rfv '{}' ';'
rm -rf $(BUILD_DIRECTORY)/parts/glib/share/glib-2.0/gdb/ \
$(BUILD_DIRECTORY)/parts/glib/share/gdb
rm -rf $(BUILD_DIRECTORY)/parts/ncurses/lib/terminfo
# Removing gettext archive tarball containing all versions
rm -fv $(BUILD_DIRECTORY)/parts/gettext/share/gettext/archive.dir.tar.gz
# Removing documentations
find $(BUILD_DIRECTORY)/parts -regextype posix-extended -type d \
-iregex '.*/(gtk-)?(doc[s]?|man|info|test[s]?)$$' \
-prune -exec rm -rfv '{}' ';'
find $(BUILD_DIRECTORY) -regextype posix-extended -type f \
-iregex '.*(COPYING|LICENSE).*' -exec rm -f '{}' ';'
# Removing include directories
find $(BUILD_DIRECTORY) -type d \( -name include -o -name pkgconfig \) | \
grep -v python | xargs rm -rfv
find $(BUILD_DIRECTORY) -type f -executable -name '*-config' | \
grep -v python | xargs rm -fv
# Removing Python byte-compiled files (as it will be done upon
# package installation) and static libraries
find $(BUILD_DIRECTORY) -regextype posix-extended -type f \
-iregex '.*/*\.(py[co]|[l]?a|exe|bat)$$' -exec rm -fv '{}' ';'
# Removing empty directories
find $(BUILD_DIRECTORY) -type d -empty -prune -exec rmdir '{}' ';'
@touch cleanup-build-stamp
strip-binaries: strip-binaries-stamp
strip-binaries-stamp: build
set -e; \
for f in `find $(BUILD_DIRECTORY) -type f -executable ! -name '*.so*'`; do \
if file $$f | grep -Eq '.*ELF.*(executable|shared).*'; then \
echo "Stripping executable $$f"; \