Skip to content

Commit

Permalink
Merge pull request #301 from arkane-systems/dev-2.5
Browse files Browse the repository at this point in the history
Dev 2.5
  • Loading branch information
cerebrate authored Sep 23, 2022
2 parents 9225f28 + 171e60b commit c0a2e7b
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -148,9 +149,6 @@ internal-package:
# Unit files.
install -Dm 0644 -o root "othersrc/lib-systemd-system/[email protected]/override.conf" -t "$(SVCDIR)/[email protected]"

# 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"

Expand All @@ -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)"
Expand Down
3 changes: 2 additions & 1 deletion PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 5 additions & 1 deletion binsrc/genie/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
44 changes: 44 additions & 0 deletions binsrc/genie/binfmts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
2 changes: 1 addition & 1 deletion binsrc/genie/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
1 change: 0 additions & 1 deletion binsrc/genie/requirements.txt
Original file line number Diff line number Diff line change
@@ -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)
11 changes: 11 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -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 <[email protected]> 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.
Expand Down
1 change: 1 addition & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion debian/systemd-genie.lintian-overrides
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Must be setuid
elevated-privileges usr/bin/genie 6755 root/root
elevated-privileges 6755 root/root [usr/bin/genie]
14 changes: 10 additions & 4 deletions genie.spec
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand All @@ -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}/[email protected]
Expand All @@ -57,7 +57,6 @@ if [ $1 -eq 0 ]; then
rm -f %{_bindir}/%{name}
rm -rf %{_exec_prefix}/lib/%{name}/*
rm -f %{_unitdir}/[email protected]/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
Expand All @@ -73,13 +72,20 @@ rm -rf %{buildroot}
%{_exec_prefix}/lib/%{name}/*
%config %{_sysconfdir}/genie.ini
%{_unitdir}/[email protected]/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 <[email protected]> 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 <[email protected]> 2.4-1
- Fixed missing dependency versions.
- Python refactoring.
Expand Down
8 changes: 8 additions & 0 deletions othersrc/docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion othersrc/lib-systemd-system/[email protected]/override.conf
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion othersrc/usr-lib/binfmt.d/WSLInterop.conf

This file was deleted.

0 comments on commit c0a2e7b

Please sign in to comment.