Skip to content
Advertisement

Run a bash script to shutdown tomcat from another directory

I have two scripts, one to run the application shutdown for Tomcat server, and another that calls it when deploying. So basically after Jenkins builds my application, and moves the deploy-able artifact to the server (linux). Once that completes Jenkins kicks off a script to do the deployment of the application on Tomcat. That deployment script calls another script to shutdown the currently running application on tomcat. The problem I’m having is that it doesn’t recognize anything is running on Tomcat. So I end up with two instances of the application running at the same time on the server…and I get out of memory exceptions. So this is the strange part. If I try to run the script as sudo /path/to/my/script stop it doesn’t recognize any application running on tomcat, but if I cd to the directory like cd /path/to/my and then run sudo ./script stop it works. Does anyone know what the issue is? I don’t think this has to do with permissions, I am using the same user to do everything, build and deploy. All files are owned by the same user, and I’m using sudo before the command. Thanks in advance for your help.

Advertisement

Answer

Without knowing what script does, this is the best you can do

(cd path/to/my && sudo ./script stop)

you can create an alias or a function if you like.

Advertisement