Bryan, I would set Tomcat up as a service and let systemd handle startup and shutdown.
Create a unit file for tomcat: /etc/systemd/system/tomcat.service ----- Begin Unit File Contents ---- [Unit] Description=Tomcat 9.0 After=network.target [Service] Type=forking User=joe Group=joe Environment="JRE_HOME=<path to your java>" Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom" Environment="CATALINA_BASE=/opt/apache-tomcat-9.0.14" Environment="CATALINA_HOME=/opt/apache-tomcat-9.0.14" Environment="CATALINA_PID=/opt/apache-tomcat-9.0.14/temp/tomcat.pid" Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC" ExecStart=/opt/apache-tomcat-9.0.14/bin/startup.sh ExecStop=/opt/apache-tomcat-9.0.14/shutdown.sh [Install] WantedBy=multi-user.target ---- End Unit File Contents ---- You might need to adjust or omit the JAVA_OPTS and CATALINA_OPTS for your use case. Then set this up to automatically start when the system boots if you like. systemctl enable tomcat.service Then I would create a new group like "TomcatAdmins" and configure in /etc/sudoers using visudo to allow %TomcatAdmins to run the following commands as root: systemctl stop tomcat systemctl start tomcat systemctl restart tomcat Then add the TomcatAdmins group to the appropriate users and instruct them to use: sudo systemctl stop tomcat sudo systemctl start tomcat I hope this is helpful. Mike On Thu, Jul 4, 2024 at 7:48 AM Bryan Buchanan <bry...@webbtide.com.invalid> wrote: > I'm running Tomcat 9.0.14 on Centos 8 with JDK 15. > > Tomcat is loaded in /opt/tomcat, the directory owned by "joe". If I login > as "joe" and start Tomcat, everything is fine. > > We have people login to the Centos system to run the business application > as "mary", "jane", "fred" etc. Sometimes they want to shutdown Tomcat, for > example if they wish to load a price update to the DBMS or whatever. To > enable them to do this from within the business application, I wrote a > setuid() C program which sets the effective user as "joe" and executes > /opt/tomcat/bin/shutdown.sh or /opt/tomcat/bin/startup.sh. This does > startup Tomcat, but 10 minutes later it dies. Nothing is logged that is > unusual. These are the last few lines when it dies: > > 04-Jul-2024 21:45:01.154 INFO [main] > org.apache.catalina.startup.Catalina.start Server startup in [54,789] > milliseconds > 04-Jul-2024 21:54:10.149 INFO [Thread-3] > org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler > ["http-nio-8080"] > 04-Jul-2024 21:54:10.157 INFO [Thread-3] > org.apache.catalina.core.StandardService.stopInternal Stopping service > [Catalina] > 04-Jul-2024 21:54:10.194 WARNING [Thread-3] > org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesJdbc The > web application [TPDRESTServer] registered the JDBC driver > [org.postgresql.Driver] but failed to unregister it when the web > application was stopped. To prevent a memory leak, the JDBC Driver has been > forcibly unregistered. > 04-Jul-2024 21:54:10.196 WARNING [Thread-3] > org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The > web application [TPDRESTServer] appears to have started a thread named > [Tomcat JDBC Pool Cleaner[862048902:1720093501299]] but has failed to stop > it. This is very likely to create a memory leak. Stack trace of thread: > java.base@15/java.lang.Object.wait(Native Method) > java.base@15/java.util.TimerThread.mainLoop(Timer.java:553) > java.base@15/java.util.TimerThread.run(Timer.java:506) > 04-Jul-2024 21:54:10.231 INFO [Thread-3] > org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler > ["http-nio-8080"] > 04-Jul-2024 21:54:10.243 INFO [Thread-3] > org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler > ["http-nio-8080"] > > My C program is: > > int main (int argc, char *argv[]) { > if (argc != 2) { > printf("%s", "Syntax: ManageTomcat START|STOP"); > return(0); > } > printf("%s\n", argv[0]); > printf("%s\n", argv[1]); > > setuid(1000); > > if(strcmp(argv[1], "STOP")) { > system("/opt/apache-tomcat-9.0.14/bin/startup.sh"); > } else { > system("/opt/apache-tomcat-9.0.14/bin/shutdown.sh"); > } return(1); > } > Any ideas would be appreciated. > > Bryan