All Projects → sr229 → wsl-systemd

sr229 / wsl-systemd

Licence: MIT license
A script that spawns a namespace with systemd as PID1, and allows you to spawn interactive sessions or exec commands inside it

Programming Languages

shell
77523 projects

Projects that are alternatives of or similar to wsl-systemd

one-script-wsl2-systemd
The one-script variant of the systemd hack for WSL2
Stars: ✭ 196 (+429.73%)
Mutual labels:  systemd, wsl2
subsystemctl
Utility to run systemd in WSL2 with a Linux namespace
Stars: ✭ 313 (+745.95%)
Mutual labels:  systemd, wsl2
convey
Communication through a serial port or named pipe
Stars: ✭ 46 (+24.32%)
Mutual labels:  wsl2
lua-systemd
Systemd bindings for Lua
Stars: ✭ 33 (-10.81%)
Mutual labels:  systemd
parca
Continuous profiling for analysis of CPU and memory usage, down to the line number and throughout time. Saving infrastructure cost, improving performance, and increasing reliability.
Stars: ✭ 2,834 (+7559.46%)
Mutual labels:  systemd
sicherboot
Unmaintained systemd-boot integration with secure boot support; consider https://github.com/Foxboron/sbctl instead.
Stars: ✭ 31 (-16.22%)
Mutual labels:  systemd
gnome-shell-extension-sermon
A GNOME Shell extension for monitoring and managing systemd services, cron jobs, docker and poman containers
Stars: ✭ 27 (-27.03%)
Mutual labels:  systemd
daemons.el
An Emacs UI for managing init system services
Stars: ✭ 87 (+135.14%)
Mutual labels:  systemd
system-76-keyboards
Rainbow / CPU monitor for system76 colored keyboards
Stars: ✭ 37 (+0%)
Mutual labels:  systemd
dotfiles
My main working machine setup. Here be cyber dragons, and optional bugs.
Stars: ✭ 35 (-5.41%)
Mutual labels:  systemd
idfx
Tool for flash/monitor ESP-IDF and ESP8266_SDK apps on the WSL2 ⚡
Stars: ✭ 71 (+91.89%)
Mutual labels:  wsl2
ruby-sdnotify
A pure-Ruby implementation of systemd's sd_notify(3)
Stars: ✭ 46 (+24.32%)
Mutual labels:  systemd
ansible-role-systemd-service
No description or website provided.
Stars: ✭ 37 (+0%)
Mutual labels:  systemd
InitWare
The InitWare Suite of Middleware allows you to manage services and system resources as logical entities called units. Its main component is a service management ("init") system.
Stars: ✭ 164 (+343.24%)
Mutual labels:  systemd
squashmount
Init and management script for mounting rewritable squashfs-compressed data
Stars: ✭ 40 (+8.11%)
Mutual labels:  systemd
dotfiles
Dotbot managed dotfiles for a polyglot dev using WSL. Includes PowerShell stuff for Windows Installation
Stars: ✭ 14 (-62.16%)
Mutual labels:  wsl2
fresh-coffee-listener
Using a raspberry pi, we listen to the coffee machine and count the number of coffee consumption
Stars: ✭ 52 (+40.54%)
Mutual labels:  systemd
nspawn
Containers with systemd-nspawn
Stars: ✭ 19 (-48.65%)
Mutual labels:  systemd
MirrorCache
Download Redirector
Stars: ✭ 24 (-35.14%)
Mutual labels:  systemd
dppm
An easy way to install and manage server applications
Stars: ✭ 107 (+189.19%)
Mutual labels:  systemd

systemd Helper Script for WSL2

ko-fi

This is a script designed to allow you to use systemd in WSL2 by faking PID1 using namespaces - aka "the poor man's container".

The main motivation behind this is you can run systemctl or your usual systemd stuff in WSL2 - all without waiting for Microsoft to wait for the official integration for custom inits (for now).

Why Another?

Most of the approaches done is more complicated to set up. This was created based on my frustration on the existing approaches:

  • Current Existing Approach does not preserve PWD when walking to the namespace. the Snaps guide is a example of this, while that guide was the basis of this project, I took the liberties to improve the script so it works seamlessly with WSL2.

  • Almost zero dependency - All you need is util-linux, nsenter and a sane POSIX-compatible shell. Approaches like genie requires you to install .NET Core just to do this which is rather - bloaty. You're just spawning a shared namespace, you don't need to write it in C#.

Installing

Simply download this script and add it on your /usr/bin or wherever you like.

However, to make sure this script truly works, make sure you have the following dependencies:

  • util-linux (comes standard in all linux distros)
  • nsenter (comes standard in all linux distros)

If you have them all, congrats! You're ready to use this.

Usage

The standard way

Usage: ./init-systemd -u (USER) -c (command)
This script spawns a namespace to be able to use systemd in a specified user.
This requires unshare (from util-linux).
If -c is provided, the command will be executed in the namespace's context non-interactively.

Execute during login

It's very much possible to execute this during login. However, I am not responsible if you can't log in normally in your system if something breaks.

Setting the sudoers

First of all is setting the sudoers so it can be executed by root without any hitches.

# Change this to where your init-systemd is.
%sudo ALL=(ALL) NOPASSWD: /usr/sbin/init-systemd

Then finally, let's edit /etc/bash.bashrc

/usr/sbin/init-systemd -u 1000

Now your system should enter the namespace whenever a interactive session is opened.

Limitations

  • Currently we can't kill the namespaces properly, so your ps tree might show multiple instances of unshare. That's going to be fixed soon once I figured out how to share only ONE systemd namespace instead of spawning another.

  • namespaces can't be killed for some reason. That's under investigation since even SIGKILL does not terminate a unshare namespace.

Contrbuting

There's more laywork to be done so it will be desirable for everyone, but in my own current usage, I say its ready for my own intended needs.

If you think you can make this script better please send patches via PR, or open some issues so I'm aware of the outstanding problems.

The entire script is written to be POSIX as possible. Bash-specific syntax should be prevented at all costs.

If you want to support me financially, my Ko-fi is available for you to donate to.

Copyright

This script is Copyright 2020 © Ayane "Capuccino" Satomi. Licensed under MIT.

This is inspired of this article from Snapcraft.io.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].