PostgreSQL unable to run after process kill - java

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?

Related

I am trying to use elastic search with logstash and kibana but im unable to run a logstash file?

I have installed elastic search,logstash and kibana successfully. I have also installed jdk. Elastic search is running on port 9200 properly I am trying to run the logstash.conf file it is giving me following error
[it is giving me following error
This is the code i am trying to run
and i am trying to run code with following Two commands
1)logstash -f logstash.py
2)logstash -e 'input{stdin{}}output{stdout{}}'
According to this message, one instance of Logstash is already running and you are trying to start another one. It is not a big problem if they are completely separated from each other. But you are starting the 2nd instance that uses the same database as the 1st one.
If this was not your intention, then first stop the 1st instance before starting the 2nd one.
If you really need multiple instances simultaneously, configure them correspondingly: database, ports.
You are already running 1 instance of logstash.
either restart your OS (that will stop all running processes) and then execute it again.
Another option is to use the CLI command:
type in your CLI: top or ps aux | grep logstash
find the PID of the logstash
type: kill -9 <logstash-pid>
If you are running logstash as a service try running:
service logstash status - to see if it is running.
service logstash stop - to stop it and then.
service logstash start - to start it again.

With Heroku, how can I automatically start a Java app that doesn't bind to a port when the app is deployed?

I have a Java application (packaged as a JAR) that interacts with a chat program (Slack) via websockets. As far as I understand it, my app doesn't need to bind to a specific port in order to work - it's just connecting to Slack's Real Time Messaging API. It's not acting as a web application or a web server. It's not listening on any ports for incoming requests because it doesn't need to. I want someone to be able to click on the "Deploy to Heroku" button for my application and I want the Java application to run as soon as the app is deployed, without a user having to manually turn on the process that starts the Java app.
I've tried using "web" as the process type that starts my Java app (java -jar ...), but, as you can probably guess, since my app uses websockets, the app stops running after 60 seconds because Heroku detects that it failed to bind to a port.
I've tried using a different process name like "bot" as the process type, but, after a period of time, I get a "No web process running" error because no web process is running. Also, in that situation, a user has to manually start the "bot" process using the Heroku website or a command line tool.
Is there a way I can set it up so it doesn't complain that I haven't bound to a a port and that there isn't a web process, but that it also starts automatically when someone deploys it?
EDIT: I've discovered that I can get rid of the "No web process running" error by telling it to not expect any web dynos. I can even use an undocumented app.json property to achieve this:
"formation": [
{ "process": "web", "quantity": 0},
{ "process": "bot", "quantity": 1}
]
However, they still have to manually start the bot process. Also I'd prefer not using an undocumented property. If I don't use it, they have to use the command line to modify the app after it is deployed. Still haven't found a way to get it to start automatically.
This is a bit of a hack, but you could use the "web" proc type and start a simple web server alongside your Java process. For example:
web: sh start.sh
And then add a start.sh script to your project like this:
ruby -rwebrick -e'WEBrick::HTTPServer.new(:Port => ENV["PORT"], :DocumentRoot => Dir.pwd).start' &
java -jar myapp.jar
Note the "&" after the ruby command
In your Procfile, just name the process type something other than "web". For example:
worker: java -jar myapp.jar
Then scale it up accordingly:
heroku ps:scale worker=1
Only "web" dynos are required to bind to a port.
You can also scale it up from the dashboard.

Autostart GUI Java jar Lubuntu

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!

How to start and stop the Windows Oracle service using a Jenkins job?

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.

NativeProcess API Java Debugging?

What is your way to debug Java side when nativeProcess.standardInput.write method is invoked by Flex side? I know that it is possible but don't know how?
To be able to attach your Eclipse debugger to a running Java process you need to start that process with the following Java options…
-Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=n
Once you have done this and have restarted the server, you can use your Eclipse to attach to the running process. From Eclipse go to the Debug manager and create a new Remote Java Application configuration for the process you want to connect to. Set the port number to 8001, the same as that of the options. You will also need to enter the hostname for the machine running the Java process. That is pretty much it…

Categories

Resources