Subscribe
Home Craft How to Install and Use systemd to Manage Services in WSL

How to Install and Use systemd to Manage Services in WSL

by Staff
0 comment

WSL uses the System V init system by default. Here’s how you can replace that with systemd to manage services on WSL like a pro.


Windows Subsystem for Linux, or WSL, is a great way for developers who need to run Linux and Windows to do so without having to set up a virtual machine or dual boot.


One major new feature is the ability to run systemd on WSL, which is useful for web developers setting up test environments locally. Here’s how to enable and use it.


Why Install systemd on WSL?

WSL services by default run the older System V init service and services are started with the service command. In September 2022, Microsoft added the option to use systemd to manage services. Most major Linux distributions have already changed to systemd.

Despite the controversy, in real use, it’s much simpler to start and stop services with systemd. It’s also easier to follow along with other Linux tutorials as you don’t have to change around commands as much.

A local LAMP testing environment will be closer to a standard Linux server, so your app will be easier to debug.

How to Enable systemd on WSL

To enable systemd, you have to run the right version of WSL. systemd requires WSL version 0.67.6 or higher. You can check the version number by opening up PowerShell and typing:

wsl 

If you have an older version installed and wish to use systemd, you can update WSL using:

wsl 

Now you’ll have to set up systemd in any distro you have installed with WSL. The process is the same on any WSL distro, whether that’s Ubuntu, Debian, Fedora, or something else.

Simply edit the /etc/wsl.conf file in your system as root and add these lines:

[boot]
systemd=true

If the wsl.conf file doesn’t exist, don’t worry and proceed by creating it yourself. These lines will work regardless.

Save the file, and now you’ll have to restart any running WSL distros. To do this, open up a PowerShell window and type this command:

wsl 

Open up another terminal, and you’ll be able to manage services with systemd on WSL.

Starting and Stopping WSL Services With systemd

You can now use systemctl to start and stop services in WSL.

Suppose you were using Apache to run a local web server to test a web app you were developing.

You’d start Apache like this:

sudo systemctl start apache2.service

If you wanted it to start automatically, you’d enable it using:

sudo systemctl enable apache2.service

And disable it with:

sudo systemctl stop apache2.service

Now You Can Run systemd on WSL

With the latest updates to WSL, you can now enable systemd and start and stop services as you need them. This makes WSL a good environment for developing web applications, as you can test them as if you were using any other standard Linux machine.

It’s also extremely easy to install a LAMP (Linux, Apache, MySQL, PHP) server on Windows Subsystem for Linux.



Read the full article here

SaleBestseller No. 1
Apple AirPods Max Wireless Over-Ear Headphones. Active Noise Cancelling, Transparency Mode, Spatial Audio, Digital Crown for Volume Control. Bluetooth Headphones for iPhone - Green
Apple AirPods Max Wireless Over-Ear Headphones. Active Noise Cancelling, Transparency Mode, Spatial Audio, Digital Crown for Volume Control. Bluetooth Headphones for iPhone - Green
 Apple-designed dynamic driver provides high-fidelity audio; Active Noise Cancellation blocks outside noise, so you can immerse yourself in music
$449.99
Bestseller No. 3
Apple iPad Air 2, 64 GB, Space Gray (Renewed)
Apple iPad Air 2, 64 GB, Space Gray (Renewed)
Apple iOS 8; 9.7-Inch Retina Display; 2048x1536 Resolution; A8X Chip with 64-bit Architecture; M8 Motion Coprocessor
$185.00
SaleBestseller No. 4
2021 Apple 10.2-inch iPad (Wi-Fi, 64GB) - Silver
2021 Apple 10.2-inch iPad (Wi-Fi, 64GB) - Silver
Gorgeous 10.2-inch Retina display with True Tone; A13 Bionic chip with Neural Engine; 8MP Wide back camera, 12MP Ultra Wide front camera with Center Stage
$269.99
Bestseller No. 5
2022 Apple TV 4K Wi‑Fi with 64GB Storage (3rd Generation)
2022 Apple TV 4K Wi‑Fi with 64GB Storage (3rd Generation)
4K Dolby Vision and HDR10+ for vivid picture quality; Dolby Atmos for three-dimensional, theater-like sound
$123.49
Bestseller No. 7
Apple AirTag 4 Pack
Apple AirTag 4 Pack
Keep track of and find your items alongside friends and devices in the Find My app; Simple one-tap setup instantly connects AirTag with your iPhone or iPad
$94.98
Bestseller No. 8
Apple MacBook Air with Intel Core i5, 1.6GHz, (13-inch, 4GB,128GB SSD) - Silver (Renewed)
Apple MacBook Air with Intel Core i5, 1.6GHz, (13-inch, 4GB,128GB SSD) - Silver (Renewed)
1.6 GHz dual-core Intel Core i5 (Turbo Boost up to 2.7 GHz) with 3 MB shared L3 cache; 13.3-Inch (diagonal) LED-backlit Glossy Widescreen Display, 1440 x 900 resolution
$299.99
Bestseller No. 9
Apple Of My Eye
Apple Of My Eye
Amazon Prime Video (Video on Demand); Amy Smart, Burt Reynolds, Liam McIntyre (Actors); Castille Landon (Director) - Castille Landon (Writer) - Dori A. Rath (Producer)
$3.99
SaleBestseller No. 10
Apple 35W Dual USB-C Port Compact Power Adapter ​​​​​​​
Apple 35W Dual USB-C Port Compact Power Adapter ​​​​​​​
The compact size and folding prongs make it easy to pack and store.; Charging cable sold separately.
$52.00

You may also like

Leave a Comment

Iman Hearts is one of the biggest lifestyle news and articles portals, we provide the latest news and articles about family, lifestyle, entertainment, and many more, follow us to get the latest news about what matters to you.

 

© 2022 Iman Hearts. All rights reserved. Sitemap