简体   繁体   中英

Using command substituion in tomcat.conf when running as a service?

I had tomcat8 installed in an AWS instance that was built using an Amazon Linux 1 AMI. Inside the tomcat.conf, I had added variables that were being set using command substitution $() to read parameters from the AWS parameter store with information on database url, name, etc. That worked great. Anytime tomcat started, it would run and parse the commands and set the environment variables based on the current parameter store values. This could then be used in a spring bean to connect to a database.

Recently I had to update to using an Amazon Linux 2 AMI. I figured out how to get tomcat installed (8.5), but it is now running as a systemctl service. When that starts up, it reads the command substitution text as is so the environment variables end up being set as "$(.....)" which obviously doesn't work.

If I manually run /usr/libexec/tomcat/servers start it does do the replacement, but when I run systemctl start tomcat.service, it does not.

I tried using jsvc, but that doesn't make a difference. I can print out one of the variables in the /usr/libexec/tomcat/preamble right after it reads in the tomcat.conf and it doesn't do the command substitution.

Does anyone know why this no longer works? Is there any way to have environment variables set at run time for tomcat the way it used to work?

So I figured out a way to do this. If I put a file in the /etc/tomcat/conf.d folder it will be parsed. I moved all the variables I wanted set into that and added an "export" at the front and that seemed to do it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM