How to check solr server restarted sucessfully or not? - java

I am writing an automate script, where I am restarting solr servers one by one. But some time they are not restarting.
I am using the below command to restart it:
stopsolr; //stoping the solar server
cd $SolrFolder; //going to index folder
unzip -o $solrindex; //extracting the index
sleep 240; //waiting some time
startsolr" >> $SolrLog;//starting server
Now I want to check if the server started or not. If not started, then I want to stop my script from execution and will return an error code. I am vary new to Linux environment/shell scripting. Which command I can use to check the status of solr server?

you can do something along the lines of:
curl 'http://127.0.0.1:8983/solr/core0/select/?q=*%3A*
parse the response, and verify numfound= your expected number, or numfound> X if you don't know the size for sure.

Solr has a ping handler which is handy to use when you want to check status of a Solr instance programmatically. SolrCloud uses this to keep handle on its cluster.
http://localhost:8983/solr/admin/ping
look for status "ok". This is exactly the purpose this handler.
More about it here : http://lucene.apache.org/solr/4_1_0/solr-core/org/apache/solr/handler/PingRequestHandler.html

Related

Automating Scheduled Task- Running main.java file

Daily i run a job in eclipse its batch job every day 11 pm. It's a main.java file need to run java application once executed i have copy the console output log into a notepad and i save with name as log file(exmaple.log), this file has to be posted to the particular share point portal, and an automated mail should be shared to the group about the file.
I want to automate this process. Please help me out, i am new to this process, but trying to automate the process which manually executing daily basis.
Since you added shell and cron, i am assuming it's kind of unix.
Verify server got connectivity to SharePoint server and mailx is enabled. If it's present you can do everything from server itself. This will be my approach.
Modify code
To log the required data to a file. You can either use a simple file
writer or use logging libraries.
Upload file to share point using share point rest api. Java httpclient can be used to execute http requests.
Use javax mail to send email. Or use native mailx unix command.
Convert java class to jar file. Schedule as cron job.
If you don't have connectivity. We have to do everything from local machine.
In that case, code should be modified to connect to server and execute remotely over ssh. Use cron or windows schedules for job management.

How to execute MSDOS Command from browser (PHP or Java)

I have a USB line display, similar to the ones that are used in store point of sale systems.
To print ABC to this line display, I run the following command:
echo ABC > \\.\LCLD9\
This prints ABC to the line display.
I'm trying to figure out how to control this output from a website, if possible, although I am not sure if it would be possible, as I can see security issues with being able to run arbitrary commands form web pages.
I'm trying to figure out how to control this output from a website, if possible, although I am not sure if it would be possible, as I can see security issues with being able to run arbitrary commands form web pages.
This is indeed not possible on an unmodified system. There is no way for a web page to run an arbitrary command on the user's machine -- that is the definition of a security vulnerability.
If you can get the user to install software ahead of time, you could use a Chrome extension with the serial, usb
or nativeMessaging APIs to expose this functionality to web pages.
Check out function shell_exec. http://php.net/manual/en/function.shell-exec.php
There are several ways to do this. One way is to simply have your website store the current text somewhere and then build a script on the local PC that asks your website for the current text and updates the display. You can schedule that script to run periodically using the Task Scheduler.
This script can be as simple as this (assuming PHP is installed on your local PC):
<?php
$text = file_get_contents('https://example.com/current_text.php');
shell_exec('echo "' . $text . '" > \\.\LCLD9\');
If you don't have PHP installed and don't want to install it, you can probably do something similar in a Powershell script or in a plain old batch file.
Note that you probably want to add some extra checks to this, you don't want to accidentally clutter your display with a 404 error page, a 500 internal server error or a network error.

How can I perform git push within a process?

My goal is to perform git push programatically rather then from a console window.
To this aim I create a process like:
val processbuilder=new ProcessBuilder(List("git.exe","push","origin","master").asJava)
process=processbuilder.start()
Now, the problem is that git.exe seems to start an other process, to the output/error and input of which I have no access. I know this because if I run it without internet connection, it just prints a message on the error output and quits, as it should. However if I do the same with having an internet connection, it prints nothing on its standard output/error. Also I cannot destroy the process in that case ( see : http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4770092 ), which is an indication that authentication takes place in a separate process that is created by git.exe and to which I have no access.
I tried to get around this by starting cmd.exe as a process and issue git push as a command, but also in this case writing the password to cmd.exe's standard input has no effect.
The platform I'm using is Windows 10 + Scala sbt.
What is the way out of this?
Edit:
I'm trying to do this from a JavaFX based Scala application rather than from a console Scala program.
Edit2:
Using the sys api here does not solve the problem. If you try to perform the gith push through sys api call, then two things can happen:
If there is no internet connection, it will print an error message on the gui application's console window ( it has one, if you run it with sbt run ).
It there is an internet connection then it will print nothing and you cannot perform the authentication. The process simply detaches and becomes unreachable for you.
The point is that git.exe seems to start a subprocess and you have no access to this subprocess. This is problem is special to Windows to which I gave a link in the question. When you run git in the Windows console window then it takes care of the sub processes input and output for you. You are however not in the same position as the operation system to do this.
I came up with a poor man's solution. It will run in a system console window but at least it can be started from the gui app.
The mixture that finally works is this:
1) Create a Windows batch file ( call it "temp.bat" ) which contains the command:
git push origin master
2) Start cmd.exe as a process and to its standard input write the following line:
start temp.bat
This will open a console window and initiate the git push. The authentication will be handled properly, you are prompted for the password and can type it in the console window.
Other versions don't work. For example 'start git.exe' won't open a new console window.
You can use Scala sys.process API.
import sys.process._
val statusCode = "git push origin master" ! // one ! for the statusCode
Or:
val commandOutput "git push origin master" !! // two ! for getting the output

Weblogic server status script using unix batch file

I am checking my weblogic server status(running or stop) through weblogic console. But i paln to automate by using unix script. Can u plz give me the unix scripts(.bat) to check the web logic server stsus. After running unix(.bat) i want to track server status in text file.
This example does what you need. With a few minor tweaks, you can get it to work for you.

Backend generates pdf files (labels, packing slips, etc) - Need to automatic print to pre-selected printers from browser - Workaround?

I'm in the process of developing a web application; where in the admin backend I need to have the functionality to do automatic print jobs for different processes that run and generate a pdf (labels, packing slips) in admin that will be sent to pre-selected LAN network printers in my warehouse.
I've been doing some research on this and I know due to security issues automatic printing like this is hard to configure. However, I have some posts where people write that they were able to pull this off with active x, java, print server, client software, etc...but there isn't a clear outline on how exactly to do this.
Can someone help me figure out a workaround that I can use to be able to automatically print to different LAN network printers in my warehouse when a certain process runs and generates a pdf file?
Thank you!
I also manage a warehouse system that does these tasks. I will not claim that the following solutions are the best way to go, but they have been working for us. Our system is built using PHP 5.3 on a Windows server using Apache. With this setup, the user does not need to print anything from the browser, it's all handle server-side.
Requirements: Apache needs to be running with Administrator privileges. Probably not recommended for web-facing servers.
To print a PDF on Windows via PHP:
$file = "c:\\path\\to\\file.pdf";
$exec = '"C:\\Program Files\\bioPDF\\Acrobat Wrapper\\acrowrap.exe" /t ';
session_write_close(); // prevents hanging
pclose(popen($exec. $file . " \\networked\\printer",'r'));
This just launches reader, prints the file, and closes reader.
On a Linux/Mac you should be able to use (without Admin privliages):
$file = "/path/to/file.pdf";
$command = "lpr -P /printer/path " . $file;
exec($command);

Categories