The WSL Onion

Calling powershell.exe from PowerShell inside WSL

The other day I was playing around in WSL with a colleague of mine and we did this: # We start out in WSL Debian and enter PowerShell Core marco@box:~$ pwsh PowerShell 7.2.2 Copyright (c) Microsoft Corporation. https://aka.ms/powershell Type 'help' to get help. # Then we get the major version of the active PowerShell session PS /home/marco> ($PSVersionTable.PSVersion).Major 7 # Then we call powershell.exe and get a completely different version! [Read More]

Windows Subsystem For Linux 2: Debian+Podman

The problem: Docker itself can’t be run in WSL2 as it requires the docker daemon, usually run though sysemd. The solution: Podman works just fine and can easilly be installed, allthough we will need to configure some things to make it work properly. Install Podman The official installation instructions are a great place to find out how to install on your distro. On my Debian 11 (bullseye) system I used apt: sudo apt install podman [Read More]

Going Part Time

(Re)starting my indie journey

Starting on the first of March 2022 I no longer work full-time in my day job. That sentence has been about a year in the making and makes me both happy and a bit scared about the future. I have been doing some side-hustle and projects since I’ve been 16 building websites with my dad, so you could say it has been a long time coming. Right now I have set myself three mid-term goals to build up something that brings me joy and financial independence. [Read More]

Simple HTTP Status Monitor Using Curl

Using some output redirection and the --write-out parameter we can produce a script that simply outputs the status code of a curl request. This script can then be used as the basis for a simple monitoring of a URL. #! /bin/bash # Description: Returns the HTTP response code obtained by curl on the URL using the specified HTTP method # Usage: script.sh GET https://example.org # Usage: scripts.sh POST https://example.org # Author: marco@kamner. [Read More]

Local S3 with MinIO in Django

In production I would consider it best practice to use a S3 solution for serving assets. Namely static files and user-generated media. This describes my setup on how to do this locally too. The main benefit for me is that there is less of a difference between environments and I can test S3 specific features in my app. Setup I will assume a already working Django project and MacOS with [[brew]] installed, but brew specific parts are easilly replicated on different systems using their native package managers. [Read More]
python  django  s3  minio 

Hidden WSL Fileshare

WSL file systems get exposed as a hidden share network share: \\wsl$\<WSL Name>\<path\to\file>

For example, my Debian home folder is at: \\wsl$\Debian\home\kamner

wsl  windows 

Windows Terminal: Open New WSL Tab In Linux Home Folder

The path you are in when opening a new WSL tab is determined by startingDirectory. This parameter needs to be a valid Windows path, which isn’t great if we want to end up in /home/kamner inside WSL. The nice thing about WSL is that it will resolve windows paths into their equivalent WSL/linux path if possible. For example, C:\Scripts would resolve to /mnt/c/Scripts. Using this and the neat trick that the WSL filesystem is exposed as a a hidden fileshare ([[technology/windows/wsl-hidden-fileshare]]) we can get to where we want. [Read More]

Resolve .local Through Nameserver With Netplan

When using netplan it is easy to force .local DNS requests to go to you nameservers instead of being only resolved locally (the default and standard).

This also works with all other strange .WHATEVER domains you may have lying around in your organization.

Snippet from netplan configuration:

 nameservers:
        addresses:
          - X
          - Y
        search:
          - local
          - myotherstupiddomain

MongoDB Logrotate

MongoDB does not rotate it’s log on it’s own. To get it to ratet we will use logrotate. First, we need to configure some things in mongod.conf to get the desired behaviour when we utilize logrotate. systemLog: destination: file path: /var/log/mongodb/mongod.log logAppend: true logRotate: reopen Afterwards, we can create a logroatet configuration going in /etc/logrotate.d/mongodb. /var/log/mongodb/mongod.log { rotate 5 # Keep the last 5 rotated logs, so 6 files including the currently active size 10M # Rotate once the log reaches 10MB in size, depending on your envrionment you could instead use daily, weekly, monthly, etc missingok # It's ok if the log file does not exist create 0600 mongodb mongodb # Permissions and ownership for the roatetd logs delaycompress # Don't compress on first rotation, so we have the current log and log. [Read More]