9
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

systemd を有効にした WSL をバックグラウンドに常駐させたい。

Last updated at Posted at 2023-01-12

概要

systemd を動かすことができなかった今までは、WSL で cron や dockerd などのバックグラウンドプロセスを常駐させるために以下のような方法を使っていました。

上記の記事で紹介している方法を簡単に説明すると Startup フォルダに cron や dockerd 起動用のコマンドを入れるという方法です。

systemd を有効にできるようになり、上記の仕組みも不要になる!と思ったのですが以下の理由で実際にはそうなりませんでした。

  • systemd を有効にしたとしても WSL 自体は Windows 起動時に自動起動してくれない。
  • WSL ターミナルを起動しておかないとタイムアウトで WSL インスタンスが自動停止してしまう。

上記を解決する方法の1つを紹介します。

解決方法

以下のファイルを Startup フォルダに配置します。

wsl_startup.vbs
Set ws = CreateObject("Wscript.Shell")
ws.run "cmd /c wsl", vbhide

Startup フォルダを開くには「Windows キー + R同時押し」で「ファイル名を指定して実行」ウィンドウを開き、「名前」に「shell:startup」を入力し、OK を押下してください。

コマンドプロンプトウィンドウを非表示にする目的で VBScript を使っています。

wsl コマンドを単に実行し、WSL ターミナルウィンドウをバックグラウンドで起動しています。
タスクマネージャーで「Linux 用 Microsoft Windows サブシステム ランチャー」を発見できると思います。

9
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?