Commit 5a8e4186 authored by Julien Muchembled's avatar Julien Muchembled

Drop NetworkManager/ifupdown support for setups that are bound to an interface

This feature was mainly for laptops but users:
- often don't care having the daemon running all the time;
- may not want to use the 'main-interface' option because the interface that
  provides internet access is not always the same, e.g. wifi & wired;
- may want other kinds of conditions,
  e.g. only specific wifi access points.

So in practice, main-interface is currently only use to set up a DHCP server or
provide IPv6 autoconfiguration. For such case, it is preferred to start/stop
re6stnet like a normal service.
parent 4198f9d5
......@@ -4,7 +4,6 @@ MANDIR = $(PREFIX)/share/man
UNITDIR = /lib/systemd/system
MANPAGELIST := $(patsubst %,docs/%,re6st-conf.1 re6st-registry.1 re6stnet.8)
NM = /etc/NetworkManager/dispatcher.d/50re6stnet
all: $(MANPAGELIST)
......@@ -17,11 +16,9 @@ install: install-noinit
done
install-noinit: install-man
install -Dp daemon/network-manager $(DESTDIR)$(NM)
set -e $(DESTDIR)$(PREFIX) /bin/re6stnet; [ -x $$1$$2 ] || \
$(or $(PYTHON),python2) setup.py install \
--prefix=$(PREFIX) --root=$(DESTDIR); \
$(and $(PYTHON),sed -ri '1s:^#!\S+:#!$(PYTHON):' $(DESTDIR)$(NM);) \
install -d $$1/sbin; mv $$1$$2 $$1/sbin
install -Dpm 0644 daemon/README.conf $(DESTDIR)/etc/re6stnet/README
install -Dpm 0644 daemon/logrotate.conf $(DESTDIR)/etc/logrotate.d/re6stnet
......@@ -31,14 +28,6 @@ install-man: $(MANPAGELIST)
do install -Dpm 0644 $$x $(DESTDIR)$(MANDIR)/man$${x##*.}/$${x##*/}; \
done
install-ifupdown:
set -e; for a in up down; do \
set $(DESTDIR)/etc/network/if-$$a.d/re6stnet; \
install -d $${1%/*}; \
printf '#!/bin/sh -e\n[ "$$METHOD" = NetworkManager -o "$$IFACE" = lo ] ||exec $(NM) "$$IFACE" %s\n' $$a >$$1; \
chmod +x $$1; \
done
clean:
find -name '*.pyc' -delete
rm -rf build dist re6stnet.egg-info $(MANPAGELIST)
#!/usr/bin/python2 -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()
mmdb = "GeoLite2-Country.mmdb"
if os.path.isfile(mmdb):
os.environ["GEOIP2_MMDB"] = os.path.join(CONFDIR, mmdb)
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
......@@ -4,8 +4,7 @@ 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; GEOIP2_MMDB=/etc/re6stnet/GeoLite2-Country.mmdb; [ -r $GEOIP2_MMDB ] && export GEOIP2_MMDB; "$@" --test main_interface==\"lo\" || exec "$@"'
ExecStart=/bin/sh -c 'GEOIP2_MMDB=/etc/re6stnet/GeoLite2-Country.mmdb; [ -r $GEOIP2_MMDB ] && export GEOIP2_MMDB; exec re6stnet @re6stnet.conf'
Restart=on-failure
StandardOutput=null
......
......@@ -19,16 +19,14 @@ endif
override_dh_install:
make DESTDIR=$(TMP) PREFIX=/usr PYTHON=/usr/bin/python \
install-noinit install-ifupdown
install-noinit
override_dh_installinit:
install -d $(INIT)
sed 's/#NAME#/re6st-registry/; s/#DEPENDS#//; s,#DAEMON_DIR#,/usr/bin,' \
sed 's/#NAME#/re6st-registry/; s,#DAEMON_DIR#,/usr/bin,' \
<debian/init.d >$(INIT)/re6st-registry
sed 's/#NAME#/re6stnet/; s/#DEPENDS#/re6st-registry/; s,#DAEMON_DIR#,/usr/sbin,; /^case/i\
cd $$CONFDIR; PYTHONDONTWRITEBYTECODE=1 $$DAEMON @$$NAME.conf --test "main_interface != '\'lo\''" ||\
case "$$1" in start) exit 0;; restart|force-reload) set stop;; esac\
' <debian/init.d >$(INIT)/re6stnet
sed 's/#NAME#/re6stnet/; s,#DAEMON_DIR#,/usr/sbin,' \
<debian/init.d >$(INIT)/re6stnet
for x in $(INIT)/*; \
do chmod +x $$x && dh_installinit --onlyscripts --name=$${x##*/}; \
done
#!/bin/sh
### BEGIN INIT INFO
# Provides: #NAME#
# Required-Start: $network $local_fs #DEPENDS#
# Required-Start: $network $local_fs
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
......
......@@ -36,7 +36,6 @@ rm -rf "$RPM_BUILD_ROOT" INSTALLED
%files -f INSTALLED
%_mandir/*/*
/etc/NetworkManager
%post
if [ $1 -eq 1 ]; then
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment