Minor issue in the stop loop of /opt/lucee/lucee_ctl

Stopping Lucee via /opt/lucee/lucee_ctl stop on my production VPS always takes more than the default 20 second timeout in the script (if [ $COUNT -gt 20 ]), so I changed it to 30 and we’ll see late tonight whether that’s enough. It would be ideal having graceful restarts.

While I was tinkering, I noticed what I think is a minor flaw in how the stop() function is coded (see below). In my opinion findpid should not be at the start of the while loop, but at the bottom after sleep 1.

The first iteration of the loop is wasted because the first call of findpid in the while loop will always set PID_FOUND=1 (unless the process has miraculously shut down in probably at most 1 millisecond). There hasn’t been even the beginning of a real opportunity yet for shutdown.sh to finish its job which started just prior to the while loop.

I’ve moved findpid in my own dev and prod environments and I’ve confirmed it works perfectly in dev, and again will see how it goes in prod tonight.

Next, I would love feedback whether this should be fixed for everyone? Again, I know it’s minor, but I get an adrenaline rush when I discover a hidden issue in something that’s been the de facto standard for many years, even when it’s in my own app!

stop() {
        echo -n " * Shutting down Lucee: "
        if [ $PID_FOUND -eq 1 ] ; then
                su -p -s /bin/sh $TOMCAT_OWNER $CATALINA_HOME/bin/shutdown.sh &> /dev/null &
                while [ $PID_FOUND -eq 1 ] ; do
                        if [ $COUNT -gt 20 ] ; then
                        echo -n ". "
                        # pause while we wait to try again
                        sleep 1
1 Like