How can my bash script detect that tomcat is fully stopped? [duplicate] - bash

This question already has answers here:
shell script to kill tomcat service if it is not stopped by stop command after certain amount of time?
(2 answers)
Closed 6 years ago.
I have tomcat downloaded on my computer (not installed as a service).
I am writing a script that upgrades a webapp running on the tomcat server. The script roughly works like this:
Stop tomcat
Perform several upgrade operations
Start tomcat
When performing the upgrade operations, I need to know that tomcat is fully stopped. However if I run $TOMCAT_HOME/bin/catalina.sh stop then that script exits before tomcat is actually stopped and if I execute the upgrade operations while tomcat is still running that might cause things to crash. In addition, the upgrade operations may finish quickly and this can cause the tomcat startup to execute before the shutdown is complete which causes tomcat to crash.
Right now my solution is to wait for 5 seconds after the shutdown is initiated but I am wondering if there is a more elegant solution to the problem.

One way to verify whether the process is still running is by using its process id. Depending on your installation, you should be able to find the process id of your tomcat server in:
/opt/tomcat/catalina.pid
In theory, if this file is empty, then the process should have ended although depending on the implementation and certain circumstances (tomcat crashing?) this might not be true. To be safe, you can take the pid found in this file and just check whether this process is still running.
ps -p <pid>
The above command will return the pid, the time and the command of the process if it is still active.

Another option would be to check if a certain port (the one that Tomcat uses) can be bound. If you can't bind on this port, it means that Tomcat is still running.
Anyway, Felix's solution is more appropriate and it's probably better to use it. I only wrote my suggestion in order to provide more alternatives, also not all Tomcat installations have catalina.pid (at least the default one doesn't).

Related

Start/stop process in embedded linux

I have my own embedded Linux system on PocketBeagle board. I have developed a simple gpio application in C that issues an on/off command to one of the pins of the connectors of the board. The application is called gpio_aa6 and located at /root.
The first challenge was to find a way to launch my application automatically after booting the board. I found two ways to do that; the first was to add an entry to etc/rcS directory. This entry is a simple script file that launches my application. The second way was to edit /etc/inittab file and add an entry to that file (::respawn:/root/gpio_aa6). In both these ways my application was launched successfully: but I am still not sure if this is the right way to launch my application automatically.
Then I came to the second challenge, how can I stop my running application, as the respawn re-launches the application if it's terminated?
I am communicating with the board in two ways; via a serial communication (using screen terminal) and via web sever (root#192.168.42.2). I have tried to use Ctrl+C, Ctrl+Z, Ctrl+\, but couldn't stop the program from being continue running. Then I used command "killall" with killsignals -9 or -15, it seems that the program is interrupted but it's launched again directly after that.
My application is to run infinitely, but I need to stop it sometimes to update it and re-launch it again.
Is there any suggestion how to overcome this problem?
Thanks.
Both solutions you have used are correct. I personally prefer the option of adding an init script to /etc/init.d though.
I believe the behavior that you observe that you apparently can't kill the program is because you are starting your program from inittab, with the respawn keyword, which precisely tells the init program to restart your application when it exits. If you actually check the PID of your application, you will see that it changes everytime you kill it.
Therefore, I would recommend you to use an init script instead, with which you can implement start and stop actions. See ./package/lldpd/S60lldpd for a basic example in Buildroot.

Windows 2000 Shutdown on Program Close

Is there a way to signal windows 2000 to shutdown when a specific program closes? I tried doing it by scheduling a task but couldn't find the shutdown executable, apparently it's only include starting in windows 2003. My next thoughts were with a batch file but I couldn't find any documentation on the command to use.
To summarize the comments & further information therein, this question is closer to the following:
How can I monitor a process on a Windows 2000 VM, running in VirtualBox, so that I can kill off the VM when the process I care about falls over?
Working from there, something like http://www.virtualbox.org/manual/ch08.html#vboxmanage-guestcontrol would be the way to go. Create a process which tells VirtualBox to start your process & then perform the shutdown when that process terminates. You'd essentially be constructing a supervisory process outside of the Win2K environment, however you want to accomplish that, rather than trying to work within the environment itself.

SonarQube server won't start

I've been using SonarQube for a year now and once I had been through all the installation process, I never got any problem... Until now.
I'm just trying to analyze a Maven Project (like I did several times before). To do so, I need to run the server first (port 9000). But when I launch "StartSonar.bat" (I'm on Windows), I get a huge log and finally the wrapper stops.
I think there is something wrong with the port 9000 although I'm not sure because I'm not that advanced with analysing logs and everything.
Here's a link to download the log I get
Thanks for your help!
The log states "Address already in use: bind" which means that some other tool already runs on that port. Choose another one should already do the trick.
Or there is a zombie-process still running (no clean shutdown). But you should see a process in the task manager - just kill that one. Usually a reboot should solve that too.
Run netstat -abo on the Windows command line to see which ports are used, by which programs they are used and their process IDs (PID). With the PID you can find the process in Task Manager and kill it there if necessary.

Remotely Executing an Independent .exe on an Apache Server [CGI]

I have an executable program I've created which is a server. I would like to be able to start and stop instances of this program on a Windows Server 2008 machine via the website the same machine hosts.
The functionality I'm hoping to achieve is: from anywhere I can access my website to start and stop instances of the server code instead of constantly Remote Desktop-ing into it just to start/stop it.
I've tried using Perl, but when I run the code it looks like it prints out some of the information the program does (so it's working) but then seems to stop. Whereas I would like it to start an instance of the program as its own process.
Perl:
#!C:/Perl64/bin/perl.exe
print "Content-type: text/plain\n\n";
exec('C:\file.exe');
I'm not sure what language I should be using or if there are completely other, better ways of achieving my goal. Thanks!
exec is the wrong choice, and so are threads. Simply start the process in the background. You did not say how you would normally stop the server. If it has its own command for stopping, the same as for starting applies; else kill the process.

Run Apache 2.2 as a single httpd.exe for debugging

I'm running Apache 2.2 in console mode on Windows to test an apache module I'm writing.
By default, a parent httpd.exe is started (with one thread), which starts a child httpd.exe with a number of worker threads.
Now I have to attach the debugger to the child process each time to be able to debug my module.
Is there a way to configure Apache to run from a single httpd.exe? (Like good old days if I remember correctly) I've been searching the docs, but don't find anything else than limitations of the number of requests handles per thread or process...
You might want to use httpd.exe -X which will run apache as a single process without giving back terminal/cmd prompt control.

Resources