I am using run_command shell program to run some commands on servers from client machine, this shell program runs particular command on server by socket communication. In Server side i use java program to run command on server, Normally for commands like ls , pwd it is working good , but for commands like "tail -f" though i am pressing ctrl^c to stop a command, it is not stopping in server side.
is there any way to to capture ctrl^c so that i will send some msg that kills running command on server
to kill some command on server , how can i kill only that particular command which was run from client not any other
Use kill command. For more information please refer URL Kill Command for UNIX
first of all, I assume that for some reason you cannot run kill on that run_command thing. If you can, ignore below answer.
On the server, start Process. Wrap the Process object along with an ID (auto generated). Add wrapper to a List or Map. Display the ID to user on client.
when user wants to kill process, send something like "mykill ". On server, if command.equals("mykill"), then get the Process indicated by id and call its destroy method, and remove from list. Also remove stale processes from your list (whether running or exited, just to keep your list or map from getting too big).
I am using run_command shell program to run some commands on servers from client machine, this shell program runs particular command on server by socket communication.
I assume there is a good reason you are not using putty. I also assume you can modify the code of that server.
Please note I have not tried this myself. I am just giving ideas.
May be you are looking for this
killall `pidof ProcessName`
Related
i want to stop a Minecraft server (java) from an empty cmd window (in the server window, we just can type "stop" to stop the server),
because I want to automatize the start and the stop of the server with os library with :
os.system("the command i search")
I don't want to kill the task , because with this method, the server is not stopped properly, and we lost a lot of data.
As for automation of the start of the server, that's simple. Either put a shortcut to your server file in your Startup folder in Windows or put a shortcut to your run.bat file in the same folder. For shutting it down, that might be a pain. I can tell from using the os.system() method that you're using Python. Stopping the server from a clear command window is something I don't know how to do, but I did find a "life-hack" you can do. This plugin is made to automatically restart your server at a specific time of day. But you should be able to configure it to just shut down, instead of a restart. Even if you made it restart, you could make the PC it's hosted on shut down just after the server restarts. This would cause a crash, granted, but it would also save all progress.
Hi guys I need your help. I have a PC which runs Lubuntu 14.10 without a monitor. The user is autologged in. I have created a Sysvinit script and installed it on /etc/init.d. My script amongst other things, starts a jar file that opens a GUI application that listens on serial port.
The problem is that I can't make the jar application start automatically on boot. Java complains that it cannot connect to the X11 display server. However this is the strange thing. If I ssh into the machine and run the script myself with sudo service it starts normally. Also if I have a monitor connected during boot, it also starts correctly by itself.
I need to have the script started without a monitor connected. It seems as if when a monitor is not connected, Xorg server isn't initiated. Does anyone have any suggestions?
Thanks
You probably need an Xorg emulator like xvfb.
I haven't tested the following on Lubuntu, but it should work:
sudo apt-get install xvfb
sudo Xvfb :10 -ac
export DISPLAY=:10
That should allow your application to run through xvfb, without having a monitor or display of any kind.
After a lot of troubleshooting, I finally managed to achieve what I wanted. The problem after all was that X server did not have enough time to load. The Xserver was started from lightdm that was an upstart service, and my script started from init.d.
It seems that if a monitor is connected X server starts earlier and my script in init.d didn't crash.
A simple sleep 10 command to stall the execution of the script until X server started did the trick. However this is a guess of time when X server will start. So a more elegant solution would be to check when the desktop starts and then launch my app. In order to achieve this I inserted the following lines before launching my script.
while [ -z $(pidof lxsession) ]; do
echo "LXSession not started yet, waiting for 2 secs"
sleep 2
done
with -z $(pidof lxsession) I check if the returned string of pidof is null. (So No PID found for process lxsession). As soon as lxsession starts, the loop is canceled and the script moves on to the execution of my java app that now finds the X server and runs normally.
Thank you all for your help. I hope other people are helped by this thread and not tortured like me!
I want to run a command in another server from my java code.
Ex. My project runs in under the server ip like ---- xx.xxx.xxx.xx
But I have to run command in another server which is like ---- .yyy.yy.yyy.yy (I am having all the credentials and access for this ip)
Is it possible? Any help would be appreciated.
Yes you can, one of the way:
On your target server(yyy.yyy.yyy.yyy), run a process that listens for commands from your client machine(xxx.xxx.xxx.xxx) . There are different ways to communicate between two remote jvms, you may chose any of them for example socket communication.
On target machine JVM, you can use ProcessBuilder to run the command received from client machine.
Or just some search for frameworks already available to such a task.
You could do it multiple ways, one way to create your own server client running on both instance and communicate it over some secure protocol to instruct remotely running agent to execute command
and if you don't want to re-invent wheel you can use SSH as underlying communication protocol and using sshj you can connect and execute command on remote machine
an example code that invokes ping command from remote machine and targetting google.com
In my java web application i am using certain ports like 1025,10..,10.. .after restarting tomcat in server .the port used by tomcat project are not closing ,it is still open
how to close the port manually using putty or WinSCP file editing
any solution for closing the port
You can use Nirsoft's CurrPorts utility to manually close TCP connections. That said, it is not necessarily the right thing to do...
Get to the tomcat directory and run shutdown.sh script and now you can re-use those ports. Hope this helps, if not comment the response.
If this doesn't solve.
Find the process id or pid using netstat command.
Verify that pid using lsof if linux or pfiles for solaris
Kill using kill
hope this helps. In a server there will be multiple processes running some of which you might not know, those processes might use your ports(sharing). While using netstat watch for CLOSE_WAIT status (these are killer handing processes) you must get rid of them in a safe way
Objective: I want to make a java program containing a boolean that checks every 5 minutes to see if my games server (cloudnine1999.no-ip.org:port 43594)
Purpose: To restart my game server if it crashes
Problem: Not sure how to check if a server is online using java.
Programs Function: If the boolean returns false(meaning the server is offline) I want the java program to open a specific batch file so the server starts up(in case the server crashes)
I tried finding something on google but I didn't find anything helpful and I'm not quite advanced enough of a coder to figure this out on my own, all I need is someone to instruct me/point me in the right direction of coding a server status checker with java and I can do the rest from there.
I may not be able to respond to your answers until around 4PM Central Us&Canada time zone.
Use Socket to check if the server is up (if it can connect to the IP and Port without throwing an exception). Be careful, some servers don't like these 'empty' connections.
try{
new Socket("cloudnine1999.no-ip.org", 43594).close();
}catch(IOException ex){
// Server probably down, restart it...
}catch(Exception ex){
// Some other problem, likely DNS or security related.
}
Use ProcessBuilder to start it up again.
Shell Script Solution :
I am assuming that server is a Java EE server. Servers are kicked by "bat" on Windows or "shell" script on Linux/Unix. For UNIX/LINUX : The most easiest solution is code a logic, in the SHELL Script that kicks of the server, to LOG the PID of the JVM in a file when the server is started. Then you write a simple shell script to monitor the PID logged by using the command "ps -aef | grep " . If the PID is not there , start the server. You should run this script as the same user who starts the server in its original place. A second solution is to "ps auxww | grep java" . Note the server varaiables which identifies your server. If you run the command , you will know.
Java Solution :
Every server has an admin port which can be monitored using a HTTP URL. Oh,well you can also hit the application url. With a Java Program you can test the connection. If the HTTP Response code is 200 - you are good and if its other than 200 like - 500 / 400 , server may be assumed dead. Then you need to kickoff the server start script.