Coder Social home page Coder Social logo

subsystemctl's Introduction

subsystemd: Run systemd in WSL2

Maintanence Note: You may want to use nullpo-head/wsl-distrod which provides better compatibility with systemd and easier installation, and well maintained.

Run systemd under Linux namespace in WSL2. Heavily inspired by arkane-systems/genie, but written in Rust.

Difference with arkane-systems/genie

Slightly following genie's behavior, but noted below...

  • Interface
    • Command line interface is not compatible.
  • Behavior
    • Hostname altertion is optional with --hostname, --hostname-suffix
      • /etc/hosts are not updated. Users are encouraged to use nss-myhostname.
    • Uses machinectl shell to launch a user shell; this allows running systemd user session
  • Internal
    • Removed dependency to unshare, daemonize, nsenter command line tools
    • systemd-wide environment variables are set via systemd.conf drop-in, using DefaultEnvironment=
    • systemd PID from root namespace is stored at /run/subsystemctl/systemd.pid

Install

Arch Linux

PKGBUILD: https://github.com/sorah/arch.sorah.jp/tree/master/aur-sorah/PKGBUILDs/subsystemctl

(PKGBUILD originally submitted to AUR (https://aur.archlinux.org/packages/subsystemctl) was deleted as they unwelcomes WSL-exclusive packages.)

Debian/Ubuntu

Refer to https://github.com/nkmideb/subsystemctl for debian source.

Pre-built package binaries available at https://github.com/nkmideb/subsystemctl/releases for your convenient.

Self build

cargo install subsystemctl

or from git source:

cargo build --release
install -m6755 -oroot -groot ./target/release/subsystemctl /usr/local/bin/subsystemctl

Usage

subsystemctl start: Start systemd environment

PS> wsl -u root -- subsystemctl start

subsystemctl shell: shell login to systemd-enabled environment

PS> wsl subsystemctl shell
Connected to the local host. Press ^] three times within 1s to exit session.
someone@hostname$ ...

Specifying uid to login

PS> wsl -u root -- subsystemctl shell --uid=1000
Connected to the local host. Press ^] three times within 1s to exit session.
someone@hostname$ ...

Automatically starting and entering a user shell

PS> wsl -u root -d Arch -- subsystemctl shell --uid=1000 --start
[2021-06-27T16:32:20Z INFO  subsystemctl] Starting systemd
Connected to the local host. Press ^] three times within 1s to exit session.

someone@hostname$ ...

subsystemctl exec: Raw nsenter like interface

PS> wsl subsystemctl exec id
uid=1000(sorah) gid=1000(sorah) groups=1000(sorah),116(admin)

Specifying uid (and gid)

PS> wsl -u root -- subsystemctl exec id
uid=0(root) gid=0(root) groups=0(root)

PS> wsl -u root -- subsystemctl exec --uid=1000 id
uid=1000(sorah) gid=1000(sorah) groups=1000(sorah),116(admin)

PS> wsl -u root -- subsystemctl exec --uid=1000 --gid=116 id
uid=1000(sorah) gid=116(admin) groups=116(admin)

subsystemctl is-running

#!/bin/bash
if subsystemctl is-running; then
  echo "running"
else
  echo "not-running"
fi

subsystemctl is-inside

#!/bin/bash
if subsystemctl is-inside; then
  echo "inside"
else
  echo "outside"
fi

Tips

systemd-resolved, networkd are recommended to be disabled

otherwise /etc/resolv.conf might get overwritten to resolved stub-resolver.

Author

Sorah Fukumori https://sorah.jp/

License

MIT

subsystemctl's People

Contributors

absolucy avatar godeater avatar mame avatar qaston avatar sorah avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.