Skip to content

Commit de446c6

Browse files
authored
Merge pull request #37 from lucee/LDEV-5944
LDEV-5944 use service name for linux installer
2 parents 1c6226d + bf50a2c commit de446c6

7 files changed

Lines changed: 213 additions & 105 deletions

File tree

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,15 +389,15 @@ jobs:
389389
--installiis false \
390390
--startatboot false \
391391
--luceepass ibtest \
392-
--systemuser lucee \
392+
--systemuser ${{ matrix.user }} \
393393
--installjre ${{ env.INSTALL_JRE }}
394394
395395
sleep 10;
396396
397397
sudo ls -l /var/www/html
398398
sudo chown -R apache:apache /var/www/html
399399
sudo chmod o+w /var/www/html
400-
sudo usermod -a -G apache ${{matrix.user}}
400+
sudo usermod -a -G apache ${{ matrix.user }}
401401
402402
echo "Write out simple test script to confirm Lucee / Java / Tomcat versions" | tee -a $GITHUB_STEP_SUMMARY
403403

LDEV-5944-status.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# LDEV-5944 Status - Linux Service Name Support
2+
3+
## Issue
4+
Linux installer hardcodes `lucee_ctl` service name, preventing multiple Lucee installations side-by-side.
5+
6+
## PR
7+
https://github.com/lucee/lucee-installer/pull/37
8+
9+
## CI Run
10+
https://github.com/lucee/lucee-installer/actions/runs/19765897410
11+
12+
## Changes Made
13+
14+
### 1. Configurable Service Name (LDEV-5944)
15+
- Added `servicename` parameter to installer UI
16+
- Platform defaults: Windows = `Lucee`, Linux = `lucee`
17+
- Linux control script becomes `${servicename}_ctl` (e.g., `lucee_ctl`, `myapp_ctl`)
18+
- Updated `service_config.sh` with `--name` parameter
19+
- Updated `change_user.sh` to accept service name as 4th argument
20+
- Updated `lucee.xml` to use `${servicename}_ctl` everywhere
21+
- Updated uninstaller to use configurable service name
22+
23+
### 2. PR #35 Bug Fixes (merged first)
24+
- Fixed `checkGroupExists()` - was using `id -g` instead of `getent group`
25+
- Fixed `rebuildControlScript()` - `mv` failed on fresh install when file doesn't exist
26+
- Fixed template name mismatch - `lucee.xml` referenced `engine_ctl_template` but PR #35 renamed it to `lucee_ctl_template`
27+
28+
### 3. Fail-Fast Error Handling
29+
- Added `set -e` to `lucee_ctl_template`
30+
- Added `abortOnError` and `onErrorActionList` to lucee.xml for the start command
31+
- Installer now fails immediately with clear error instead of waiting for Tomcat timeout
32+
33+
### 4. `su` Command Fixes
34+
- Problem: Docker containers don't have `su` in PATH or installed
35+
- First attempt: Changed `su` to `/usr/bin/su` - failed on AlmaLinux where `su` is at `/bin/su`
36+
- Second attempt: Changed to `/bin/su` - failed because AlmaLinux `almalinux:latest` doesn't have `util-linux` installed
37+
- Current fix: Added `run_as_owner()` helper function that skips `su` when current user matches target user
38+
39+
## Current `run_as_owner` Implementation
40+
```bash
41+
run_as_owner() {
42+
if [ "$(id -un)" = "$TOMCAT_OWNER" ]; then
43+
"$@"
44+
else
45+
/bin/su -p -s /bin/sh "$TOMCAT_OWNER" "$@"
46+
fi
47+
}
48+
```
49+
50+
## CI Test Matrix
51+
| Platform | Container | Users Tested |
52+
|----------|-----------|--------------|
53+
| Ubuntu x64 | Native runner | $USER, root, lucee |
54+
| Ubuntu aarch64 | Native runner | $USER, root, lucee |
55+
| Debian 12 | debian:12 | root, lucee |
56+
| AlmaLinux | almalinux:latest | root, lucee |
57+
| Windows | Native runner | N/A |
58+
59+
## Known Issues
60+
61+
### AlmaLinux CI Workflow Bug
62+
Line 392 in main.yml always uses `--systemuser lucee` regardless of matrix user variable.
63+
64+
### `su` Still Required for Non-Matching Users
65+
When running as root with `--systemuser lucee`, the script still needs `su` which may not be installed in minimal containers.
66+
67+
## Files Modified
68+
- `lucee/lucee.xml` - service name support, fail-fast, template name fix
69+
- `lucee/linux/sys/lucee_ctl_template` - `set -e`, `run_as_owner()` function
70+
- `lucee/linux/sys/change_user.sh` - service name support, getent group fix, mv fix
71+
- `lucee/linux/sys/service_config.sh` - `--name` parameter
72+
- `lucee/translations/messages.en.txt` - renamed message keys
73+
74+
## Next Steps
75+
1. Wait for CI to complete
76+
2. Check failed logs for actual error
77+
3. May need to install `util-linux` in CI workflow for AlmaLinux if `su` is still needed

lucee/linux/sys/change_user.sh

Lines changed: 32 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
# Author: Jordan Michaels (jordan@viviotech.net)
77
# Copyright: Jordan Michaels, 2010-2018, All rights reserved.
88
#
9-
# Usage: change_user.sh [username] [install dir] [engine] [nobackup]
9+
# Usage: change_user.sh username /path/to/installdir [nobackup] [servicename]
1010
#
11-
# [username] must start with a lower-case letter and must be alpha-
12-
# numeric
13-
# [engine] must be either "lucee" or "openbd". Engine name is used
14-
# in the control script name, such as "lucee_ctl" or "openbd_ctl"
11+
# username must start with a lower-case letter and must be alphanumeric
12+
# servicename is optional, defaults to lucee_ctl
1513
# ----------------------------------------------------------------------------------
1614
#
1715
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
@@ -74,31 +72,24 @@ else
7472
myInstallDir=$2;
7573
fi
7674

77-
# the default when [nobackup] is not specified is always to backup control scripts
78-
if [[ -z "$3" ]]; then
79-
echo "lucee_ctl will be backed up to lucee_ctl.old";
80-
myControlNeedsBackup=1;
81-
else
82-
if [[ "$3" = "openbd" ]]; then
83-
echo "Error: OpenBD is no longer supported by this script.";
84-
exit 1;
85-
else
86-
if [[ -z "$4" ]]; then
87-
echo "lucee_ctl will be backed up to lucee_ctl.old";
88-
myControlNeedsBackup=1;
89-
else
90-
# At this point $3 and $4 both exist.
91-
# The legacy $3 argument (lucee) is ignored,
92-
# but the old usage is supported to avoid breaking change!
93-
if [[ "$3" = "nobackup" || "$4" = "nobackup" ]]; then
94-
echo "lucee_ctl will NOT be backed up!";
95-
myControlNeedsBackup=0;
96-
else
97-
echo "lucee_ctl will be backed up to lucee_ctl.old";
98-
myControlNeedsBackup=1;
99-
fi
100-
fi
75+
# default service name
76+
myServiceName="lucee_ctl"
77+
78+
# parse optional arguments
79+
myControlNeedsBackup=1
80+
for arg in "$3" "$4"; do
81+
if [[ "$arg" = "nobackup" ]]; then
82+
myControlNeedsBackup=0
83+
elif [[ -n "$arg" && "$arg" != "lucee" ]]; then
84+
# treat non-empty, non-legacy values as service name
85+
myServiceName="$arg"
10186
fi
87+
done
88+
89+
if [[ ${myControlNeedsBackup} -eq 1 ]]; then
90+
echo "${myServiceName} will be backed up to ${myServiceName}.old";
91+
else
92+
echo "${myServiceName} will NOT be backed up!";
10293
fi
10394

10495
###################
@@ -120,7 +111,7 @@ function checkUserExists {
120111
function checkGroupExists {
121112
echo -n "Checking to see if group exists...";
122113
myGroupNeedsCreating=0;
123-
if id -g "${myUserName}" >/dev/null 2>&1; then
114+
if getent group "${myUserName}" >/dev/null 2>&1; then
124115
echo "[FOUND]";
125116
else
126117
echo "[NOT FOUND]";
@@ -174,28 +165,28 @@ function processControlScriptTemplate {
174165
function rebuildControlScript {
175166
echo "Rebuilding Control Scripts for new User...";
176167
# backup current control script
177-
if [[ ${myControlNeedsBackup} -eq 1 ]]; then
178-
# If we're backing up, do it
179-
mv ${myInstallDir}/lucee_ctl ${myInstallDir}/lucee_ctl.old;
168+
if [[ ${myControlNeedsBackup} -eq 1 && -f "${myInstallDir}/${myServiceName}" ]]; then
169+
# If we're backing up and file exists, do it
170+
mv ${myInstallDir}/${myServiceName} ${myInstallDir}/${myServiceName}.old;
180171
else
181172
# otherwise, just remove the old file
182-
rm -f ${myInstallDir}/lucee_ctl
173+
rm -f ${myInstallDir}/${myServiceName}
183174
fi
184-
175+
185176
# create the control script from easier to maintain separate template
186-
TomcatControlScript="${myInstallDir}/lucee_ctl";
177+
TomcatControlScript="${myInstallDir}/${myServiceName}";
187178
local scriptDir="$(dirname "${BASH_SOURCE[0]}")"
188-
179+
189180
# Process the template to generate the control script
190181
processControlScriptTemplate "${scriptDir}/lucee_ctl_template" "$TomcatControlScript"
191-
182+
192183
# make it executable
193-
chmod 744 $TomcatControlScript;
184+
chmod 744 $TomcatControlScript;
194185

195186
# see if there's a control script in the init directory
196-
if [[ -f /etc/init.d/lucee_ctl ]]; then
187+
if [[ -f /etc/init.d/${myServiceName} ]]; then
197188
# if there is, copy the new control script over it
198-
cp -f $TomcatControlScript /etc/init.d/lucee_ctl;
189+
cp -f $TomcatControlScript /etc/init.d/${myServiceName};
199190
fi
200191
}
201192

lucee/linux/sys/lucee_ctl_template

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
set -e
23
# chkconfig: 345 22 78
34
# description: Tomcat/Lucee Control Script
45

@@ -25,17 +26,34 @@ CATALINA_TMPDIR=${myInstallDir}/tomcat/temp; export CATALINA_TMPDIR
2526
@@luceeJAVAhome@@
2627
TOMCAT_OWNER=${myUserName}; export TOMCAT_OWNER
2728

29+
# Run a command as TOMCAT_OWNER
30+
# Tries multiple methods: direct execution, runuser, sudo, su
31+
run_as_owner() {
32+
if [ "$(id -un)" = "$TOMCAT_OWNER" ]; then
33+
"$@"
34+
elif command -v runuser >/dev/null 2>&1; then
35+
runuser -u "$TOMCAT_OWNER" -- "$@"
36+
elif command -v sudo >/dev/null 2>&1; then
37+
sudo -u "$TOMCAT_OWNER" "$@"
38+
elif command -v su >/dev/null 2>&1; then
39+
su -p -s /bin/sh "$TOMCAT_OWNER" -- "$@"
40+
else
41+
echo "ERROR: Cannot switch to user $TOMCAT_OWNER - no runuser, sudo, or su available" >&2
42+
return 1
43+
fi
44+
}
45+
46+
# Check if Lucee/Tomcat is running by examining the PID file
2847
checkisrunning() {
2948
LUCEE_IS_RUNNING=0
3049
# delete stale PID caused by server reboot
3150
if [[ -f "$CATALINA_PID" && /proc -nt "$CATALINA_PID" ]]; then
3251
rm "$CATALINA_PID"
3352
fi
34-
if [ -f "$CATALINA_PID" ] ; then
35-
PIDNUMBER=`cat "$CATALINA_PID"`
36-
TEST_RUNNING=`ps -p ${PIDNUMBER} | grep ${PIDNUMBER} | grep java`
37-
if [ ! -z "${TEST_RUNNING}" ]; then
38-
# PID is found and running
53+
if [ -f "$CATALINA_PID" ]; then
54+
PIDNUMBER=$(cat "$CATALINA_PID")
55+
# check if process is running - use kill -0 which is cleaner than grepping ps output
56+
if kill -0 "$PIDNUMBER" 2>/dev/null; then
3957
LUCEE_IS_RUNNING=1
4058
fi
4159
fi
@@ -45,7 +63,7 @@ start() {
4563
echo " * Starting Lucee: "
4664
checkisrunning
4765
if [ $LUCEE_IS_RUNNING -eq 0 ] ; then
48-
su -p -s /bin/sh $TOMCAT_OWNER $CATALINA_HOME/bin/startup.sh
66+
run_as_owner $CATALINA_HOME/bin/startup.sh
4967
echo -n " * Waiting for confirmation that Lucee is running: "
5068
COUNT=0
5169
while [ $LUCEE_IS_RUNNING -eq 0 ] ; do
@@ -79,7 +97,7 @@ stop() {
7997
echo -n " * Shutting down Lucee: "
8098
checkisrunning
8199
if [ $LUCEE_IS_RUNNING -eq 1 ] ; then
82-
su -p -s /bin/sh $TOMCAT_OWNER $CATALINA_HOME/bin/shutdown.sh &> /dev/null &
100+
run_as_owner $CATALINA_HOME/bin/shutdown.sh &> /dev/null &
83101
COUNT=0
84102
while [ $LUCEE_IS_RUNNING -eq 1 ] ; do
85103
COUNT=$((${COUNT}+1))

0 commit comments

Comments
 (0)