Bug 41337

Summary: koha-create --request-db and --populate-db creates log files owned by root (intranet-error.log, opac-error.log)
Product: Koha Reporter: Saiful Amin <saiful>
Component: Installation and upgrade (command-line installer)Assignee: Andreas Roussos <a.roussos>
Status: Pushed to main --- QA Contact: Jan Kissig <bibliothek>
Severity: major    
Priority: P1 - high CC: a.roussos, bibliothek, tomascohen
Version: Main   
Hardware: All   
OS: Linux   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25284
GIT URL: Initiative type: ---
Sponsorship status: --- Comma delimited list of Sponsors:
Crowdfunding goal: 0 Patch complexity: Small patch
Documentation contact: Documentation submission:
Text to go in the release notes:
This fixes the UNIX user/group ownership of the log files `intranet-error.log` and `opac-error.log` inside `/var/log/koha/<instance>/`. Previously, running `koha-create --request-db` followed by `koha-create --populate-db` would result in the two log files being owned by root/root. The correct ownership is now applied, meaning the log files will be owned by the <instance>-koha/<instance>-koha UNIX user/group.
Version(s) released in:
26.05.00
Circulation function:
Attachments: Bug 41337: Add missing Bash variable to `koha-create`
Bug 41337: Add missing Bash variable to `koha-create`
Bug 41337: Add missing Bash variable to `koha-create`
Bug 41337: Add missing Bash variable to `koha-create`

Description Saiful Amin 2025-12-01 14:12:41 UTC
When creating a new Koha instance using the two-step workflow (--request-db and --populate-db), some log files under /var/log/koha/<instance>/ end up with incorrect permissions. Specifically, intranet-error.log and opac-error.log are created as root:root instead of <inst>-koha:<inst>-koha.

This causes Apache/Plack to fail to start cleanly until the ownership is corrected manually.

Steps to Reproduce:

1. Run: koha-create --request-db test
2. Create the DB/user on the remote or local DB host as instructed.
3. Then run: koha-create --populate-db test
4. Check ownership of generated logs: ls -l /var/log/koha/test
Actual Result:
Two files are owned by root:root:
-rw-r--r-- 1 root      root    0 intranet-error.log
-rw-r--r-- 1 root      root    0 opac-error.log

All other logs have correct ownership (test-koha:test-koha).

Koha will not start smoothly until these two files are manually chowned.

Expected Result:
All log files under /var/log/koha/<instance>/ should be owned by <instance>-koha:<instance>-koha, identical to a normal koha-create run without the request/populate split.

Notes: This only happens when using the two-step creation (--request-db + --populate-db). A normal one-step koha-create with --create-db assigns the correct ownership.
Comment 1 Andreas Roussos 2026-02-09 13:38:05 UTC
(In reply to Saiful Amin from comment #0)
> [...]
> Expected Result:
> All log files under /var/log/koha/<instance>/ should be owned by
> <instance>-koha:<instance>-koha, identical to a normal koha-create run
> without the request/populate split.
> [...]
Thank you, Saiful, for the detailed Bug Description and the steps to reproduce.

I can confirm this is still an issue, which relates to this line in the script:
https://git.koha-community.org/Koha-community/Koha/src/commit/c58989fc51bf41fc92fd568875f304c03aa075f6/debian/scripts/koha-create#L924

924     chown $username:$username /var/log/koha/$name/*.log

At this point in the script the $username variable is empty,
so the `chown` command becomes:

chown : /var/log/koha/test/*.log

The chown(1) man page states: "If only a colon is given, or if the
entire operand is empty, neither the owner nor the group is changed."
Comment 2 Andreas Roussos 2026-02-09 15:53:46 UTC Comment hidden (obsolete)
Comment 3 Andreas Roussos 2026-02-09 16:12:34 UTC
Created attachment 192822 [details] [review]
Bug 41337: Add missing Bash variable to `koha-create`

When creating a new Koha instance using the two-step workflow
(`koha-create --request-db <instance>`, followed by
`koha-create --populate-db <instance>`), some log files under
/var/log/koha/<instance>/ end up with incorrect ownership.

Specifically, intranet-error.log and opac-error.log are owned
by root:root instead of <instance>-koha:<instance>-koha.

This patch fixes that.

Test plan (tailored for KTD):

1) Before applying this patch, run the following commands
   inside your KTD Koha container:

   $ sudo koha-create --request-db test1
   $ SQLPASS=`sudo grep password: test1-db-request.txt | cut -c 16-`
   $ mysql -hdb -uroot -ppassword -e "CREATE DATABASE koha_test1;"
   $ mysql -hdb -uroot -ppassword -e "GRANT ALL PRIVILEGES ON koha_test1.* TO 'koha_test1'@'%' IDENTIFIED BY '${SQLPASS}';"
   $ mysql -hdb -uroot -ppassword -e "FLUSH PRIVILEGES;"
   $ sudo koha-create --populate-db test1

   $ ls -l /var/log/koha/test1/
     total 8
     -rw-r--r-- 1 test1-koha test1-koha    0 Feb  9 15:35 indexer-error.log
     -rw-r--r-- 1 test1-koha test1-koha 1278 Feb  9 15:35 indexer-output.log
     -rw-r--r-- 1 root       root          0 Feb  9 15:35 intranet-error.log
     -rw-r--r-- 1 root       root          0 Feb  9 15:35 opac-error.log
     -rw-r--r-- 1 test1-koha test1-koha    0 Feb  9 15:35 worker-error.log
     -rw-r--r-- 1 test1-koha test1-koha 1828 Feb  9 15:35 worker-output.log
     -rw-r--r-- 1 test1-koha test1-koha    0 Feb  9 15:35 zebra-error.log
     -rw-r--r-- 1 test1-koha test1-koha    0 Feb  9 15:35 zebra-output.log

   Notice the incorrect user/group ownership on two
   files: `intranet-error.log` and `opac-error.log`.

2) Apply this patch, remove the `test1` instance along
   with the database request text file, and copy the
   modified script to its system-wide location:

   $ sudo koha-remove test1
   $ sudo rm test1-db-request.txt
   $ sudo cp debian/scripts/koha-create /usr/sbin/koha-create

3) Repeat the commands in Step 1. This time, the output of
   the last command should resemble the following:

   total 8
   -rw-r--r-- 1 test1-koha test1-koha    0 Feb  9 15:42 indexer-error.log
   -rw-r--r-- 1 test1-koha test1-koha 1520 Feb  9 15:42 indexer-output.log
   -rw-r--r-- 1 test1-koha test1-koha    0 Feb  9 15:42 intranet-error.log
   -rw-r--r-- 1 test1-koha test1-koha    0 Feb  9 15:42 opac-error.log
   -rw-r--r-- 1 test1-koha test1-koha    0 Feb  9 15:42 worker-error.log
   -rw-r--r-- 1 test1-koha test1-koha 1828 Feb  9 15:42 worker-output.log
   -rw-r--r-- 1 test1-koha test1-koha    0 Feb  9 15:42 zebra-error.log
   -rw-r--r-- 1 test1-koha test1-koha    0 Feb  9 15:42 zebra-output.log

   All files should now have the correct user/group ownership.
Comment 4 Brendan Lawlor 2026-02-12 16:15:34 UTC
Created attachment 193015 [details] [review]
Bug 41337: Add missing Bash variable to `koha-create`

When creating a new Koha instance using the two-step workflow
(`koha-create --request-db <instance>`, followed by
`koha-create --populate-db <instance>`), some log files under
/var/log/koha/<instance>/ end up with incorrect ownership.

Specifically, intranet-error.log and opac-error.log are owned
by root:root instead of <instance>-koha:<instance>-koha.

This patch fixes that.

Test plan (tailored for KTD):

1) Before applying this patch, run the following commands
   inside your KTD Koha container:

   $ sudo koha-create --request-db test1
   $ SQLPASS=`sudo grep password: test1-db-request.txt | cut -c 16-`
   $ mysql -hdb -uroot -ppassword -e "CREATE DATABASE koha_test1;"
   $ mysql -hdb -uroot -ppassword -e "GRANT ALL PRIVILEGES ON koha_test1.* TO 'koha_test1'@'%' IDENTIFIED BY '${SQLPASS}';"
   $ mysql -hdb -uroot -ppassword -e "FLUSH PRIVILEGES;"
   $ sudo koha-create --populate-db test1

   $ ls -l /var/log/koha/test1/
     total 8
     -rw-r--r-- 1 test1-koha test1-koha    0 Feb  9 15:35 indexer-error.log
     -rw-r--r-- 1 test1-koha test1-koha 1278 Feb  9 15:35 indexer-output.log
     -rw-r--r-- 1 root       root          0 Feb  9 15:35 intranet-error.log
     -rw-r--r-- 1 root       root          0 Feb  9 15:35 opac-error.log
     -rw-r--r-- 1 test1-koha test1-koha    0 Feb  9 15:35 worker-error.log
     -rw-r--r-- 1 test1-koha test1-koha 1828 Feb  9 15:35 worker-output.log
     -rw-r--r-- 1 test1-koha test1-koha    0 Feb  9 15:35 zebra-error.log
     -rw-r--r-- 1 test1-koha test1-koha    0 Feb  9 15:35 zebra-output.log

   Notice the incorrect user/group ownership on two
   files: `intranet-error.log` and `opac-error.log`.

2) Apply this patch, remove the `test1` instance along
   with the database request text file, and copy the
   modified script to its system-wide location:

   $ sudo koha-remove test1
   $ sudo rm test1-db-request.txt
   $ sudo cp debian/scripts/koha-create /usr/sbin/koha-create

3) Repeat the commands in Step 1. This time, the output of
   the last command should resemble the following:

   total 8
   -rw-r--r-- 1 test1-koha test1-koha    0 Feb  9 15:42 indexer-error.log
   -rw-r--r-- 1 test1-koha test1-koha 1520 Feb  9 15:42 indexer-output.log
   -rw-r--r-- 1 test1-koha test1-koha    0 Feb  9 15:42 intranet-error.log
   -rw-r--r-- 1 test1-koha test1-koha    0 Feb  9 15:42 opac-error.log
   -rw-r--r-- 1 test1-koha test1-koha    0 Feb  9 15:42 worker-error.log
   -rw-r--r-- 1 test1-koha test1-koha 1828 Feb  9 15:42 worker-output.log
   -rw-r--r-- 1 test1-koha test1-koha    0 Feb  9 15:42 zebra-error.log
   -rw-r--r-- 1 test1-koha test1-koha    0 Feb  9 15:42 zebra-output.log

   All files should now have the correct user/group ownership.

Signed-off-by: Brendan Lawlor <blawlor@clamsnet.org>
Comment 5 Jan Kissig 2026-02-16 13:49:10 UTC
Created attachment 193247 [details] [review]
Bug 41337: Add missing Bash variable to `koha-create`

When creating a new Koha instance using the two-step workflow
(`koha-create --request-db <instance>`, followed by
`koha-create --populate-db <instance>`), some log files under
/var/log/koha/<instance>/ end up with incorrect ownership.

Specifically, intranet-error.log and opac-error.log are owned
by root:root instead of <instance>-koha:<instance>-koha.

This patch fixes that.

Test plan (tailored for KTD):

1) Before applying this patch, run the following commands
   inside your KTD Koha container:

   $ sudo koha-create --request-db test1
   $ SQLPASS=`sudo grep password: test1-db-request.txt | cut -c 16-`
   $ mysql -hdb -uroot -ppassword -e "CREATE DATABASE koha_test1;"
   $ mysql -hdb -uroot -ppassword -e "GRANT ALL PRIVILEGES ON koha_test1.* TO 'koha_test1'@'%' IDENTIFIED BY '${SQLPASS}';"
   $ mysql -hdb -uroot -ppassword -e "FLUSH PRIVILEGES;"
   $ sudo koha-create --populate-db test1

   $ ls -l /var/log/koha/test1/
     total 8
     -rw-r--r-- 1 test1-koha test1-koha    0 Feb  9 15:35 indexer-error.log
     -rw-r--r-- 1 test1-koha test1-koha 1278 Feb  9 15:35 indexer-output.log
     -rw-r--r-- 1 root       root          0 Feb  9 15:35 intranet-error.log
     -rw-r--r-- 1 root       root          0 Feb  9 15:35 opac-error.log
     -rw-r--r-- 1 test1-koha test1-koha    0 Feb  9 15:35 worker-error.log
     -rw-r--r-- 1 test1-koha test1-koha 1828 Feb  9 15:35 worker-output.log
     -rw-r--r-- 1 test1-koha test1-koha    0 Feb  9 15:35 zebra-error.log
     -rw-r--r-- 1 test1-koha test1-koha    0 Feb  9 15:35 zebra-output.log

   Notice the incorrect user/group ownership on two
   files: `intranet-error.log` and `opac-error.log`.

2) Apply this patch, remove the `test1` instance along
   with the database request text file, and copy the
   modified script to its system-wide location:

   $ sudo koha-remove test1
   $ sudo rm test1-db-request.txt
   $ sudo cp debian/scripts/koha-create /usr/sbin/koha-create

3) Repeat the commands in Step 1. This time, the output of
   the last command should resemble the following:

   total 8
   -rw-r--r-- 1 test1-koha test1-koha    0 Feb  9 15:42 indexer-error.log
   -rw-r--r-- 1 test1-koha test1-koha 1520 Feb  9 15:42 indexer-output.log
   -rw-r--r-- 1 test1-koha test1-koha    0 Feb  9 15:42 intranet-error.log
   -rw-r--r-- 1 test1-koha test1-koha    0 Feb  9 15:42 opac-error.log
   -rw-r--r-- 1 test1-koha test1-koha    0 Feb  9 15:42 worker-error.log
   -rw-r--r-- 1 test1-koha test1-koha 1828 Feb  9 15:42 worker-output.log
   -rw-r--r-- 1 test1-koha test1-koha    0 Feb  9 15:42 zebra-error.log
   -rw-r--r-- 1 test1-koha test1-koha    0 Feb  9 15:42 zebra-output.log

   All files should now have the correct user/group ownership.

Signed-off-by: Brendan Lawlor <blawlor@clamsnet.org>
Signed-off-by: Jan Kissig <bibliothek@th-wildau.de>
Comment 6 Lucas Gass (lukeg) 2026-02-26 16:06:39 UTC
Nice work everyone!

Pushed to main for 26.05