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!
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.
I'm developing an installer in Java, which suppose to install PostgreSQL 9.4.5 automatically in Centos 6 Linux OS.
Also, the installation (the Java code) is responsible for creating new system user for the postgres and then registering and starting the PostgreSQL service as a postgres service:
`service "pgsql_service_name" start`
I have notices that if this process was killed using: kill -9 "pgsql_pid" it won't be able to recover using service "pgsql_service_name" start until deleting postmaster.pid file or reboot the system.
Now, the interesting part is what happening afterwards: after deleting the postmaster.pid file, I started Postgres service again using service "pgsql_service_name" start this time from the Linux shell, only this time when I killed the process again using kill -9 "pgsql_pid", the same service "pgsql_service_name" start command has managed to run successfully from shell and overwrite the postmaster.pid file automatically.
Why do you think this inconsistently between starting the process from Java code (the installer), and between killing it (or running it back) from Linux shell is happening?
Is there any better solution than deleting the `postmaster.pid` file at first time when this issue occur?
I am using Oracle 11g. On a remote server (Windows server-12) I have three separate Oracle instances (SID).
I want to stop and start their Oracle services from Jenkins.
How can I do this with Jenkins?
Windows service can be started and stopped using the command line:
net startservice
net stopservice
(See the details for "Start, stop, pause, resume, or restart a service").
Calling a shell command from Jenkins is quite easy with the build step "Execute command". Just be careful that Windows is bad/non predictive about when the service is effectively stopped. You may want to play around with some "waiting" clause, especially if you want to stop the start again.
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`
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.