Need help running Lucee on Amazon Linux 2

I successfully ran the installer for Lucee v 5.3.10.120, and everything seems to have gone where it was meant to go. OpenJDK 11.0.18 is located at /opt/lucee/jre

When I go to /opt/lucee/tomcat/bin and try to execute shutdown.sh or startup.sh, I get an error about missing environment variables for JAVA_HOME or JRE_HOME. I still get this error if I first export JAVA_HOME=/opt/lucee/jre/
I tried creating a shell script to set that environment variable at /etc/profile.d/JAVA_HOME.sh and logged out of the shell and back in, but I still get the error about the environment variables missing. Now I’m out of ideas. Thoughts? TIA

In *nix those variables for Tomcat are usually set in path-to-lucee/tomcat/bin/setenv.sh as specified in Tomcat docs (search for setenv.sh):
https://tomcat.apache.org/tomcat-9.0-doc/RUNNING.txt

Just to add to how *NIX works, binaries run as users, be it real or service level accounts. Often times they are service accounts that do not know anything unless explicitly added.

.ENV in your profile usually holds the enviromental vars.
you can run in bash PRINT ENV
This will show your environment.
As Andreas explained, you need JRE_HOME or JAVA_HOME defined in your ENV

1 Like

I don’t see a setenv.sh file anywhere. The installer put tomcat at /opt/lucee/tomcat/. Do I need to create setenv.sh in the tomcat/bin directory and add my env variable there?

thanks for that. the printenv command shows JAVA_HOME=/opt/lucee/jre/, which is the correct path. How does the Lucee start script not find it?

You need to check the binary user “service user” that is running the program, that is the user and or group that needs to understand where lucee is, where java is and how to start it correctly.

what does systemctl list-units --type=service show
What user is lucee running as?
Did you su to that user and try starting ?

Generally as I am not sure if you did this, this is how I would setup lucee
install java (I will assume you did this)
add lucee user and group ( I will assume you did this)
run vi /etc/systemd/system/lucee.service

[Unit]
Description=Apache Lucee
After=network.target

[Service]
Type=forking

Environment=CATALINA_PID=/home/ec2-user/lucee/temp/tomcat9.pid
Environment=JAVA_HOME=/opt/java/jdk1.11.0_18/
Environment=CATALINA_HOME=/home/ec2-user/lucee
Environment=CATALINA_BASE=/home/ec2-user/lucee
Environment="JAVA_OPTS=-Dfile.encoding=UTF-8 -Djava.awt.headless=true"

ExecStart=/opt/lucee/tomcat/bin/startup.sh
ExecStop=/opt/lucee/tomcat/bin/shutdown.sh

User=lucee
Group=lucee

[Install]
WantedBy=multi-user.target

Test your configuration

systemctl daemon-reload
systemctl start lucee
systemctl enable lucee

If that fails you did something wrong, try again. Check your logs and how you set up java and lucee service permissions.

As I wanted to note, you will need to modify the above slightly for your use
generally, /home/ec2-user/“AppName” is where I place system account users and their binaries they run. So if its completely vanilla you would place catalina.home in /opt/lucee/. I have to run or I would edit this to help you a bit more.

Yes. Please see the tomcat docs that I Iinked in my previous post (and search for setenv.sh). it’s all written in there.