Starting cron under wsl2

    There are a lot of "recipes" out there for how to start cron under wsl when a Windows PC starts up. I won't bore you with why I wanted to do that. Suffice to say, the recipes didn't work for me. But eventually, I found a way.

    The recipes have two parts to them. First set things up so any user under WSL can start the cron service. This means editing /etc/sudoers and adding a line like:

    %sudo ALL=(ALL) NOPASSWD: /usr/sbin/service cron start

    The second step revolves around setting up a task in Window's taskmgr to run on system boot up. This task wouldn't work for me … it would run and fail. The recipes set things up to lauch the following command.

      C:\Windows\System32\wsl.exe /usr/sbin/service cron start

    But that produced an error for me. E.g.,

      C:\Windows\System32\wsl.exe /usr/sbin/service cron start
      Starting periodic command scheduler: croncron: can't open or create /var/run/ Permission denied failed!

    What I found was that I needed to explicitly use the sudo command to start the service command. Changing the taskmgr job to the following resulted in success. Yay!

      C:\Windows\System32\wsl.exe /usr/bin/sudo /usr/sbin/service cron start

    If you webmention this page, please let me know the URL of your page.

    BTW: Your webmention won't show up until I next "build" my site.

    Word count: 200 (about 1 minutes)


    Updated: 9 Nov '23 08:49

    Author: Peter Smith


    Section: blog

    Kind: page

    Bundle type: leaf

    Source: blog/2023/11/09/starting-cron-under-wsl2/