From 0103bbbf349d0434252a8d40f39f113eaf6499cc Mon Sep 17 00:00:00 2001 From: alexmerlin Date: Tue, 17 Jun 2025 15:25:06 +0300 Subject: [PATCH 1/4] Issue #69: Unable to start Apache/MariaDB on startup Signed-off-by: alexmerlin --- docs/book/v2/setup/setup-packages.md | 2 +- wsl/README.md | 2 +- wsl/install.yml | 1 + wsl/roles/apache/tasks/main.yml | 10 ++++++++++ wsl/roles/mariadb/tasks/main.yml | 10 ++++++++++ wsl/roles/system/tasks/main.yml | 4 ++++ wsl/roles/system/vars/main.yml | 1 + 7 files changed, 28 insertions(+), 2 deletions(-) diff --git a/docs/book/v2/setup/setup-packages.md b/docs/book/v2/setup/setup-packages.md index 5c38895..e250afa 100644 --- a/docs/book/v2/setup/setup-packages.md +++ b/docs/book/v2/setup/setup-packages.md @@ -29,7 +29,7 @@ Update/Upgrade system packages: sudo dnf upgrade -y ``` -Now, install the latest version of **Ansible Core** and run **ansible-galaxy** in order to install collections: +Now, install the latest version of **Ansible Core** and run **ansible-galaxy** to install collections: ```shell sudo dnf install ansible-core -y diff --git a/wsl/README.md b/wsl/README.md index 3219ffb..c4ff2fc 100644 --- a/wsl/README.md +++ b/wsl/README.md @@ -112,7 +112,7 @@ Update/Upgrade system packages: sudo dnf upgrade -y ``` -Now, install the latest version of **Ansible Core** and run **ansible-galaxy** in order to install collections: +Now, install the latest version of **Ansible Core** and run **ansible-galaxy** to install collections: ```shell sudo dnf install ansible-core -y diff --git a/wsl/install.yml b/wsl/install.yml index 0509ddf..7babbe1 100644 --- a/wsl/install.yml +++ b/wsl/install.yml @@ -7,6 +7,7 @@ vars_files: - ./config.yml - ./roles/apache/vars/main.yml + - ./roles/system/vars/main.yml tasks: - name: Install and configure packages include_role: diff --git a/wsl/roles/apache/tasks/main.yml b/wsl/roles/apache/tasks/main.yml index 9b20a81..57d6fa1 100644 --- a/wsl/roles/apache/tasks/main.yml +++ b/wsl/roles/apache/tasks/main.yml @@ -5,6 +5,16 @@ - httpd - httpd-tools state: latest +- name: Ensure /run/httpd directory exists on Apache startup + ansible.builtin.lineinfile: + path: "{{ etc_rc_d_rc_local_path }}" + line: "{{ item }}" + create: yes + insertafter: EOF + loop: + - "# Ensure /run/httpd directory exists on Apache startup" + - "/usr/bin/mkdir -p /run/httpd" + - "/usr/bin/install -d -o apache -g apache -m 0755 /run/httpd" - name: Enable and start Apache service command: systemctl enable --now httpd - name: Fix Apache home directory ownership diff --git a/wsl/roles/mariadb/tasks/main.yml b/wsl/roles/mariadb/tasks/main.yml index 286a3d0..92f5a6e 100644 --- a/wsl/roles/mariadb/tasks/main.yml +++ b/wsl/roles/mariadb/tasks/main.yml @@ -1,6 +1,16 @@ --- - name: Install MariaDB 11.4 command: "dnf install python3-mysqlclient mariadb-server -y" +- name: Ensure /run/mariadb directory exists on MariaDB startup + ansible.builtin.lineinfile: + path: "{{ etc_rc_d_rc_local_path }}" + line: "{{ item }}" + create: yes + insertafter: EOF + loop: + - "# Ensure /run/mariadb directory exists on MariaDB startup" + - "/usr/bin/mkdir -p /run/mariadb" + - "/usr/bin/chown mysql:mysql /run/mariadb" - name: Enable and start MariaDB service command: systemctl enable --now mariadb - name: Set MariaDB root password diff --git a/wsl/roles/system/tasks/main.yml b/wsl/roles/system/tasks/main.yml index fe0e7f1..fd5df26 100644 --- a/wsl/roles/system/tasks/main.yml +++ b/wsl/roles/system/tasks/main.yml @@ -22,3 +22,7 @@ template: src: bash_profile.j2 dest: "{{ bash_profile_dest }}" +- name: Ensure /etc/rc.d/rc.local is executable + file: + path: "{{ etc_rc_d_rc_local_path }}" + mode: '0755' diff --git a/wsl/roles/system/vars/main.yml b/wsl/roles/system/vars/main.yml index e9a659d..74870ae 100644 --- a/wsl/roles/system/vars/main.yml +++ b/wsl/roles/system/vars/main.yml @@ -1,3 +1,4 @@ --- wsl_config_dest: /etc/wsl.conf bash_profile_dest: "/home/{{ config.system.username }}/.bash_profile" +etc_rc_d_rc_local_path: "/etc/rc.d/rc.local" From 89502d9bc35dbe57f7d04b9fa3581d6f8070ff40 Mon Sep 17 00:00:00 2001 From: alexmerlin Date: Tue, 17 Jun 2025 16:40:12 +0300 Subject: [PATCH 2/4] Added service responsible with re/creating runtime directories Signed-off-by: alexmerlin --- wsl/install.yml | 2 +- wsl/roles/apache/tasks/main.yml | 10 -------- wsl/roles/mariadb/tasks/main.yml | 10 -------- wsl/roles/system/tasks/main.yml | 25 ++++++++++++++++--- .../templates/runtime-directories.service.j2 | 13 ++++++++++ .../templates/runtime-directories.sh.j2 | 8 ++++++ wsl/roles/system/vars/main.yml | 3 ++- 7 files changed, 45 insertions(+), 26 deletions(-) create mode 100644 wsl/roles/system/templates/runtime-directories.service.j2 create mode 100644 wsl/roles/system/templates/runtime-directories.sh.j2 diff --git a/wsl/install.yml b/wsl/install.yml index 7babbe1..7a7a44f 100644 --- a/wsl/install.yml +++ b/wsl/install.yml @@ -14,11 +14,11 @@ name: "{{ role }}" tasks_from: main loop: - - system - apache - php - mariadb - phpmyadmin + - system - composer - nodejs - git diff --git a/wsl/roles/apache/tasks/main.yml b/wsl/roles/apache/tasks/main.yml index 57d6fa1..9b20a81 100644 --- a/wsl/roles/apache/tasks/main.yml +++ b/wsl/roles/apache/tasks/main.yml @@ -5,16 +5,6 @@ - httpd - httpd-tools state: latest -- name: Ensure /run/httpd directory exists on Apache startup - ansible.builtin.lineinfile: - path: "{{ etc_rc_d_rc_local_path }}" - line: "{{ item }}" - create: yes - insertafter: EOF - loop: - - "# Ensure /run/httpd directory exists on Apache startup" - - "/usr/bin/mkdir -p /run/httpd" - - "/usr/bin/install -d -o apache -g apache -m 0755 /run/httpd" - name: Enable and start Apache service command: systemctl enable --now httpd - name: Fix Apache home directory ownership diff --git a/wsl/roles/mariadb/tasks/main.yml b/wsl/roles/mariadb/tasks/main.yml index 92f5a6e..286a3d0 100644 --- a/wsl/roles/mariadb/tasks/main.yml +++ b/wsl/roles/mariadb/tasks/main.yml @@ -1,16 +1,6 @@ --- - name: Install MariaDB 11.4 command: "dnf install python3-mysqlclient mariadb-server -y" -- name: Ensure /run/mariadb directory exists on MariaDB startup - ansible.builtin.lineinfile: - path: "{{ etc_rc_d_rc_local_path }}" - line: "{{ item }}" - create: yes - insertafter: EOF - loop: - - "# Ensure /run/mariadb directory exists on MariaDB startup" - - "/usr/bin/mkdir -p /run/mariadb" - - "/usr/bin/chown mysql:mysql /run/mariadb" - name: Enable and start MariaDB service command: systemctl enable --now mariadb - name: Set MariaDB root password diff --git a/wsl/roles/system/tasks/main.yml b/wsl/roles/system/tasks/main.yml index fd5df26..b96f5c4 100644 --- a/wsl/roles/system/tasks/main.yml +++ b/wsl/roles/system/tasks/main.yml @@ -22,7 +22,24 @@ template: src: bash_profile.j2 dest: "{{ bash_profile_dest }}" -- name: Ensure /etc/rc.d/rc.local is executable - file: - path: "{{ etc_rc_d_rc_local_path }}" - mode: '0755' +- name: Add create runtime directories script + template: + src: runtime-directories.sh.j2 + dest: "{{ runtime_directories_script_path }}" + mode: "0755" +- name: Add create runtime directories service + template: + src: runtime-directories.service.j2 + dest: "{{ runtime_directories_service_path }}" + mode: "0755" +- name: Reload systemd + ansible.builtin.systemd: + daemon_reload: yes +- name: Enable runtime-directories.service + ansible.builtin.systemd: + name: runtime-directories.service + enabled: yes +- name: Start runtime-directories.service + ansible.builtin.systemd: + name: runtime-directories.service + state: started diff --git a/wsl/roles/system/templates/runtime-directories.service.j2 b/wsl/roles/system/templates/runtime-directories.service.j2 new file mode 100644 index 0000000..ae28193 --- /dev/null +++ b/wsl/roles/system/templates/runtime-directories.service.j2 @@ -0,0 +1,13 @@ +[Unit] +Description=Create runtime directories for Apache and MariaDB +DefaultDependencies=no +After=local-fs.target +Before=httpd.service mariadb.service + +[Service] +Type=oneshot +ExecStart={{ runtime_directories_script_path }} +RemainAfterExit=true + +[Install] +WantedBy=multi-user.target diff --git a/wsl/roles/system/templates/runtime-directories.sh.j2 b/wsl/roles/system/templates/runtime-directories.sh.j2 new file mode 100644 index 0000000..a3fcf7d --- /dev/null +++ b/wsl/roles/system/templates/runtime-directories.sh.j2 @@ -0,0 +1,8 @@ +#!/bin/bash +set -e + +# Create /run/httpd with correct ownership and permissions +install -d -o apache -g apache -m 0755 /run/httpd + +# Create /run/mariadb with correct ownership and permissions +install -d -o mysql -g mysql -m 0755 /run/mariadb diff --git a/wsl/roles/system/vars/main.yml b/wsl/roles/system/vars/main.yml index 74870ae..b915f62 100644 --- a/wsl/roles/system/vars/main.yml +++ b/wsl/roles/system/vars/main.yml @@ -1,4 +1,5 @@ --- wsl_config_dest: /etc/wsl.conf bash_profile_dest: "/home/{{ config.system.username }}/.bash_profile" -etc_rc_d_rc_local_path: "/etc/rc.d/rc.local" +runtime_directories_script_path: "/usr/local/bin/runtime-directories.sh" +runtime_directories_service_path: "/etc/systemd/system/runtime-directories.service" From b0b08741e151850284ca7eaac28fe0be3099b249 Mon Sep 17 00:00:00 2001 From: alexmerlin Date: Wed, 18 Jun 2025 08:11:10 +0300 Subject: [PATCH 3/4] Fixed Git configs Signed-off-by: alexmerlin --- wsl/roles/git/tasks/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/wsl/roles/git/tasks/main.yml b/wsl/roles/git/tasks/main.yml index 844037d..f0752ec 100644 --- a/wsl/roles/git/tasks/main.yml +++ b/wsl/roles/git/tasks/main.yml @@ -9,9 +9,11 @@ value: "{{ item.value }}" scope: global with_dict: "{{ git_config }}" + become: false - name: Apply global user configurations git_config: name: "{{ item.key }}" value: "{{ item.value }}" scope: global with_dict: "{{ config.git.config }}" + become: false From bf1507c51856a841561d4f186962655c99ce5aa8 Mon Sep 17 00:00:00 2001 From: alexmerlin Date: Wed, 18 Jun 2025 15:06:38 +0300 Subject: [PATCH 4/4] Added WSL2 clean start instructions to docs and README Signed-off-by: alexmerlin --- docs/book/v1/setup/installation.md | 35 +++++++++++++++++++++++- docs/book/v2/setup/installation.md | 35 +++++++++++++++++++++++- wsl/README.md | 43 +++++++++++++++++++++++++++++- 3 files changed, 110 insertions(+), 3 deletions(-) diff --git a/docs/book/v1/setup/installation.md b/docs/book/v1/setup/installation.md index ca543a3..1242cc8 100644 --- a/docs/book/v1/setup/installation.md +++ b/docs/book/v1/setup/installation.md @@ -1,8 +1,41 @@ # Install AlmaLinux9 +Before proceeding with the installation, we need to make sure that no other WSL2 distribution (aka: _distro_) is running. +This is important because this installation will fail if required ports are already in use by another distro. + Open `Windows Terminal`. -List the available Linux distributions (aka: _distros_) by executing: +## Stop other WSL2 distros + +List all installed distros: + +```shell +wsl -l -v +``` + +If there is no other distro installed, you will see the below output (an empty list): + +```text + NAME STATE VERSION +``` + +In this case, you can jump to the [installation](#install-almalinux9-1) section. + +If you have other distros installed, the output could look similar to the below: + +```text + NAME STATE VERSION +* AlmaLinux-9 Stopped 2 +* AlmaLinux-10 Running 2 +``` + +Make sure that the **STATE** column reads **Stopped** for all distros. +If any of them reads **Running**, you must stop if first by executing `wsl -t `, for example: `wsl -t AlmaLinux-10`. +Once you have stopped all distros, you can continue to the [installation](#install-almalinux9-1) section. + +## Install AlmaLinux9 + +List the available Linux distros by executing: ```shell wsl --list --online diff --git a/docs/book/v2/setup/installation.md b/docs/book/v2/setup/installation.md index f47b321..c36a0c8 100644 --- a/docs/book/v2/setup/installation.md +++ b/docs/book/v2/setup/installation.md @@ -1,8 +1,41 @@ # Install AlmaLinux10 +Before proceeding with the installation, we need to make sure that no other WSL2 distribution (aka: _distro_) is running. +This is important because this installation will fail if required ports are already in use by another distro. + Open `Windows Terminal`. -List the available Linux distributions (aka: _distros_) by executing: +## Stop other WSL2 distros + +List all installed distros: + +```shell +wsl -l -v +``` + +If there is no other distro installed, you will see the below output (an empty list): + +```text + NAME STATE VERSION +``` + +In this case, you can jump to the [installation](#install-almalinux10-1) section. + +If you have other distros installed, the output could look similar to the below: + +```text + NAME STATE VERSION +* AlmaLinux-8 Stopped 2 +* AlmaLinux-9 Running 2 +``` + +Make sure that the **STATE** column reads **Stopped** for all distros. +If any of them reads **Running**, you must stop if first by executing `wsl -t `, for example: `wsl -t AlmaLinux-9`. +Once you have stopped all distros, you can continue to the [installation](#install-almalinux10-1) section. + +## Install AlmaLinux10 + +List the available Linux distros by executing: ```shell wsl --list --online diff --git a/wsl/README.md b/wsl/README.md index c4ff2fc..ea82e86 100644 --- a/wsl/README.md +++ b/wsl/README.md @@ -1,8 +1,41 @@ # Install AlmaLinux10 +Before proceeding with the installation, we need to make sure that no other WSL2 distribution (aka: _distro_) is running. +This is important because this installation will fail if required ports are already in use by another distro. + Open `Windows Terminal`. -List the available Linux distributions (aka: _distros_) by executing: +## Stop other WSL2 distros + +List all installed distros: + +```shell +wsl -l -v +``` + +If there is no other distro installed, you will see the below output (an empty list): + +```text + NAME STATE VERSION +``` + +In this case, you can jump to the [installation](#install-almalinux10-1) section. + +If you have other distros installed, the output could look similar to the below: + +```text + NAME STATE VERSION +* AlmaLinux-8 Stopped 2 +* AlmaLinux-9 Running 2 +``` + +Make sure that the **STATE** column reads **Stopped** for all distros. +If any of them reads **Running**, you must stop if first by executing `wsl -t `, for example: `wsl -t AlmaLinux-9`. +Once you have stopped all distros, you can continue to the [installation](#install-almalinux10-1) section. + +## Install AlmaLinux10 + +List the available Linux distros by executing: ```shell wsl --list --online @@ -39,6 +72,14 @@ OracleLinux_9_1 Oracle Linux 9.1 Note the two columns: **NAME** and **FRIENDLY NAME**. To install a specific distro, use the value from the **NAME** column, in this case: `AlmaLinux-10`. + +> If you try to install a distro that is already installed, the installation process will fail: +> +> Downloading: AlmaLinux OS 10 +> Installing: AlmaLinux OS 10 +> A distribution with the supplied name already exists. Use --name to choose a different name. +> Error code: Wsl/InstallDistro/Service/RegisterDistro/ERROR_ALREADY_EXISTS + Install the AlmaLinux10 distro by executing the below command: ```shell