diff --git a/.gitignore b/.gitignore index 696251f..852aec4 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ binsrc/genie-wrapper/genie-arm64 binsrc/genie/*.dist-info binsrc/genie/bin/ binsrc/genie/nsenter/ +binsrc/genie/psutil binsrc/genie/python_hosts/ # Built binaries diff --git a/Makefile b/Makefile index 1c25a88..31a396b 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,8 @@ default: # # make package # make package-debian - # make package-debian-arm64 + # make package-debian-amd64 + # make package-debian-arm64 # make package-tar # make package-arch (requires Arch packaging environment) # make package-fedora (requires Fedora packaging environment) @@ -68,12 +69,12 @@ package-debian: package-debian-amd64 package-debian-arm64 package-debian-amd64: make-output-directory mkdir -p out/debian - debuild -us -uc + debuild --no-sign mv ../systemd-genie_* out/debian package-debian-arm64: make-output-directory mkdir -p out/debian - debuild -aarm64 -us -uc + debuild -aarm64 -b --no-sign mv ../systemd-genie_* out/debian clean-debian: @@ -148,9 +149,6 @@ internal-package: # Unit files. install -Dm 0644 -o root "othersrc/lib-systemd-system/user-runtime-dir@.service.d/override.conf" -t "$(SVCDIR)/user-runtime-dir@.service.d" - # binfmt.d - install -Dm 0644 -o root "othersrc/usr-lib/binfmt.d/WSLInterop.conf" -t "$(USRLIBDIR)/binfmt.d" - # tmpfiles.d install -Dm 0644 -o root "othersrc/usr-lib/tmpfiles.d/wslg.conf" -t "$(USRLIBDIR)/tmpfiles.d" @@ -169,6 +167,8 @@ internal-supplement: mkdir -p "$(MAN8DIR)" # this bit would ordinarily be handed by debuild, etc. + + cp "othersrc/docs/genie.8" /tmp/genie.8 gzip -f9 "/tmp/genie.8" install -Dm 0644 -o root "/tmp/genie.8.gz" -t "$(MAN8DIR)" diff --git a/PKGBUILD b/PKGBUILD index 517642a..8f7316a 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -4,13 +4,14 @@ # Contributor: facekapow, rayfalling, Ducksoft _pkgname=genie pkgname=${_pkgname}-systemd -pkgver=2.4 +pkgver=2.5 pkgrel=1 pkgdesc="A quick way into a systemd \"bottle\" for WSL" arch=('x86_64') url="https://github.com/arkane-systems/genie" license=('Unlicense') depends=('daemonize' 'python>=3.7' 'python-psutil' 'systemd>=232.25' 'inetutils') +conflicts=('bottle-imp') makedepends=('git' 'python-pip') options=(!strip) source=("git+https://github.com/arkane-systems/genie.git") diff --git a/binsrc/genie/__main__.py b/binsrc/genie/__main__.py index c184a27..dd0bc5e 100755 --- a/binsrc/genie/__main__.py +++ b/binsrc/genie/__main__.py @@ -233,6 +233,10 @@ def inner_do_initialize(): if configuration.resolved_stub(): resolved.configure(verbose) + # Update binfmts config file. + flags = binfmts.check_flags(verbose) + binfmts.write_interop_file(verbose, flags) + # Unmount the binfmts fs before starting systemd, so systemd can mount it # again with all the trimmings. binfmts.umount(verbose) @@ -290,7 +294,7 @@ def inner_do_initialize(): state = 'initializing' timeout = configuration.system_timeout() - while ('running' not in state) and timeout > 0: + while ('running' not in state and 'degraded' not in state) and timeout > 0: time.sleep(1) state = helpers.get_systemd_state(sdp) diff --git a/binsrc/genie/binfmts.py b/binsrc/genie/binfmts.py index ac9d751..f9c129b 100644 --- a/binsrc/genie/binfmts.py +++ b/binsrc/genie/binfmts.py @@ -40,3 +40,47 @@ def umount(verbose): else: if verbose: print("no binfmt_misc filesystem present") + + +def check_flags(verbose): + """Check the flags for the current binfmt filesystem.""" + if os.path.exists('/proc/sys/fs/binfmt_misc/WSLInterop'): + with open('/proc/sys/fs/binfmt_misc/WSLInterop', 'rt') as wif: + for wl in wif: + if wl.startswith('flags: '): + flags = wl.rstrip()[7:] + + if verbose: + print(f'genie: WSL interop flags detected: {flags}') + + return flags + + if verbose: + print("genie: could not find WSLInterop flags") + + return None + + else: + if verbose: + print("genie: no WSLInterop configuration present") + + return None + + +def write_interop_file(verbose, flags): + """Write out a new WSL interop file with the specified flags.""" + if os.path.exists('/usr/lib/binfmt.d'): + + if flags is None: + if verbose: + print ('genie: no WSLInterop configuration available; assuming PF') + flags = 'PF' + + with open('/usr/lib/binfmt.d/WSLInterop.conf', 'w') as f: + f.write(f':WSLInterop:M::MZ::/init:{flags}') + + if verbose: + print ('genie: written new WSLInterop config') + + else: + print ('genie: systemd binfmt.d is not available') diff --git a/binsrc/genie/helpers.py b/binsrc/genie/helpers.py index 0623a0c..f1d71b8 100644 --- a/binsrc/genie/helpers.py +++ b/binsrc/genie/helpers.py @@ -67,7 +67,7 @@ def prelaunch_checks(): # Is this WSL 2? if not os.path.exists('/run/WSL'): - if 'microsoft' not in os.uname(): + if 'microsoft' not in os.uname().release: sys.exit("genie: not executing under WSL 2 - how did we get here?") # Are we effectively root? diff --git a/binsrc/genie/requirements.txt b/binsrc/genie/requirements.txt index 35ee90e..c353f60 100644 --- a/binsrc/genie/requirements.txt +++ b/binsrc/genie/requirements.txt @@ -1,3 +1,2 @@ git+https://github.com/zalando/python-nsenter@b7fd78fef24c456d88130c75fe734417728e97e8 python_hosts>=1.0.1 -# psutil>=5.9.0 (should be handled by apt package) diff --git a/debian/changelog b/debian/changelog index d0a1699..1334203 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,14 @@ +systemd-genie (2.5) bullseye bookworm sid focal jammy; urgency=medium + + * Fixed Debian multiarch packaging. + * Dynamically build WSLInterop.conf based on existing (fixes #287, #295). + * Fix for schrödinbug (fixes #298). + * Allow for faster timeout when system in degraded state. + * Added note and referrer about native systemd support. + * Added bottle-imp conflict to packages. + + -- Alistair Young Fri, 23 Sep 2022 15:00:00 -0500 + systemd-genie (2.4) bullseye bookworm sid focal jammy; urgency=medium * Deprecated support for Debian buster and Ubuntu bionic. diff --git a/debian/control b/debian/control index e2ff059..ef87909 100644 --- a/debian/control +++ b/debian/control @@ -11,6 +11,7 @@ Vcs-Browser: https://github.com/arkane-systems/genie Package: systemd-genie Architecture: amd64 arm64 Depends: ${misc:Depends}, ${shlibs:Depends}, dbus, policykit-1, daemonize, systemd (>= 232-25), python3 (>= 3.7), python3-pip, python3-psutil, systemd-container (>= 232-25), gawk +Conflicts: bottle-imp Description: quick way into a systemd "bottle" under Windows Subsystem for Linux Automates the process of starting up, entering into, and shutting down a container within which systemd is pid 1, effectively enabling the use diff --git a/debian/systemd-genie.lintian-overrides b/debian/systemd-genie.lintian-overrides index cdce15c..9a34656 100644 --- a/debian/systemd-genie.lintian-overrides +++ b/debian/systemd-genie.lintian-overrides @@ -1,2 +1,2 @@ # Must be setuid -elevated-privileges usr/bin/genie 6755 root/root +elevated-privileges 6755 root/root [usr/bin/genie] diff --git a/genie.spec b/genie.spec index 9cfd4f1..a49f28b 100644 --- a/genie.spec +++ b/genie.spec @@ -1,5 +1,5 @@ %global project https://github.com/arkane-systems/genie/ -%global version 2.4 +%global version 2.5 %global debug_package %{nil} %global _enable_debug_package 0 @@ -23,6 +23,7 @@ Requires: python3-pip Requires: python3-psutil Requires: systemd >= 232.25 Requires: systemd-container >= 232.25 +Conflicts: bottle-imp # BuildRequires: git BuildRequires: make @@ -43,7 +44,6 @@ install -d -p %{buildroot}%{_exec_prefix}/lib/%{name} install -d -p %{buildroot}%{_exec_prefix}/lib/systemd/system-environment-generators install -d -p %{buildroot}%{_exec_prefix}/lib/systemd/user-environment-generators install -d -p %{buildroot}%{_exec_prefix}/lib/tmpfiles.d -install -d -p %{buildroot}%{_exec_prefix}/lib/binfmt.d install -d -p %{buildroot}%{_bindir} install -d -p %{buildroot}%{_unitdir} install -d -p %{buildroot}%{_unitdir}/user-runtime-dir@.service.d @@ -57,7 +57,6 @@ if [ $1 -eq 0 ]; then rm -f %{_bindir}/%{name} rm -rf %{_exec_prefix}/lib/%{name}/* rm -f %{_unitdir}/user-runtime-dir@.service.d/override.conf -rm -f %{_exec_prefix}/lib/binfmt.d/WSLInterop.conf rm -f %{_exec_prefix}/lib/tmpfiles.d/wslg.conf rm -f %{_exec_prefix}/lib/systemd/system-environment-generators/80-genie-envar.sh rm -f %{_exec_prefix}/lib/systemd/user-environment-generators/80-genie-envar.sh @@ -73,13 +72,20 @@ rm -rf %{buildroot} %{_exec_prefix}/lib/%{name}/* %config %{_sysconfdir}/genie.ini %{_unitdir}/user-runtime-dir@.service.d/override.conf -%{_exec_prefix}/lib/binfmt.d/WSLInterop.conf %{_exec_prefix}/lib/tmpfiles.d/wslg.conf %{_exec_prefix}/lib/systemd/system-environment-generators/80-genie-envar.sh %{_exec_prefix}/lib/systemd/user-environment-generators/80-genie-envar.sh %doc %{_mandir}/man8/genie.8.gz %changelog +* Fri Sep 23 2022 Alistair Young 2.5-1 +- Fixed Debian multiarch packaging. +- Dynamically build WSLInterop.conf based on existing (fixes #287, #295). +- Fix for schrödinbug (fixes #298). +- Allow for faster timeout when system in degraded state. +- Added note and referrer about native systemd support. +- Added bottle-imp conflict to packages. + * Sat Jun 25 2022 Alistair Young 2.4-1 - Fixed missing dependency versions. - Python refactoring. diff --git a/othersrc/docs/readme.md b/othersrc/docs/readme.md index 4711532..dd1aab3 100644 --- a/othersrc/docs/readme.md +++ b/othersrc/docs/readme.md @@ -10,6 +10,14 @@ What does that even mean? Well, this gives you a way to run systemd as pid 1, with all the trimmings, inside WSL 2. It does this by creating a pid namespace, the eponymous poor-man's-container "bottle", starting up systemd in there, and entering it, and providing some helpful shortcuts to do so. +## WSL NOW HAS NATIVE SYSTEMD SUPPORT + +[As explained here](https://devblogs.microsoft.com/commandline/systemd-support-is-now-available-in-wsl/), if you are running Windows 11 and a version of WSL 0.67.6 or above. If this is available to you, you should use it instead of _genie_, because it's a much more elegant way of getting systemd to run. + +It's not quite perfect, however, so you should also check out _[bottle-imp](https://github.com/arkane-systems/bottle-imp)_, my friendly helper to make working with WSL's native systemd support a little easier. + +Using _genie_ on systems that have native _systemd_ support is not supported. + ## REQUIREMENTS **NOTE:** Before you install _genie_ for the first time, read **ALL** of this page. This will save you a great deal of trouble later on. Especially, please note that on many distributions you **will** encounter the problem described under "Warning: Timing Out" below when you first run genie, and will need to resolve it before your system will operate correctly. diff --git a/othersrc/lib-systemd-system/user-runtime-dir@.service.d/override.conf b/othersrc/lib-systemd-system/user-runtime-dir@.service.d/override.conf index b98357a..4e33f65 100644 --- a/othersrc/lib-systemd-system/user-runtime-dir@.service.d/override.conf +++ b/othersrc/lib-systemd-system/user-runtime-dir@.service.d/override.conf @@ -1,3 +1,7 @@ [Service] -ExecStartPost=/usr/lib/genie/map-user-runtime-dir.sh %i +ExecStart= +ExecStart=/lib/systemd/systemd-user-runtime-dir start %i +ExecStart=/usr/lib/genie/map-user-runtime-dir.sh %i +ExecStop= ExecStop=/usr/lib/genie/unmap-user-runtime-dir.sh %i +ExecStop=/lib/systemd/systemd-user-runtime-dir stop %i diff --git a/othersrc/usr-lib/binfmt.d/WSLInterop.conf b/othersrc/usr-lib/binfmt.d/WSLInterop.conf deleted file mode 100644 index 705a15d..0000000 --- a/othersrc/usr-lib/binfmt.d/WSLInterop.conf +++ /dev/null @@ -1 +0,0 @@ -:WSLInterop:M::MZ::/init:PF