Use Java Program As Start UP Script Linux (RHEL5) Giving Error? - java

hi i have created my jar file PingConsolApps.jar and i have run this jar file at terminal running fine now o want to add it as a service that would start up on boot so i have put my jar file in "/home" place and i have created file PingConsolApps in etc/init.d as following this site,
http://www.shayanderson.com/linux/ad...-on-bootup.htm
but i have edited it here,
Code:
#! /bin/sh
case "$1" in
start)
cd /home/
/usr/bin/java -jar PingConsolApps.jar &
;;
stop)
killall -v java
;;
esac
exit 0
i gave permission to it ,
Code:
chmod +x /etc/init.d/PingConsolApps
and after it i execute,
Code:
chmod 777 /etc/init.d/PingConsolApps
i try to start its service
Code:
/etc/init.d/PingConsolApps start
it does not show any error but after it i check it using
Code:
service PingConsolApps status
it does not show any thing and do not give ant error i check it in running service,
Code:
service --status -all
i do not get it there also
when i try to stop it
Code:
/etc/init.d/PingConsolApps stop
it give error "java: no process killed"
if it run this service then my sql data base would be updates while it do not up date ???
what are the mistakes in this script help me out to get my goals i am new to linux and development to specially like creating this services
Thanks in Advance

See: http://fedoraproject.org/wiki/Packaging:SysVInitScript#Initscript_template
It is mandatory to have a line like:
#chkconfig 234 90 10

Related

Cannot use Java in a SLURM job on an HPC

I am trying to run a simple script on a Linux HPC, where I am looping over a number of RNA-seq files and want to call fastQC, a Java based program, on each of the files.
In the script I'm calling a wrapper script that runs the Java fastQC-program.
The script I wrote is as follows:
#!/bin/bash
#SBATCH -t 00:30:00
#SBATCH -n 1
#SBATCH --mail-type=end
#SBATCH --clusters=serial
#SBATCH --partition=serial_std
#SBATCH --mem=6gb
echo "Starting to run fastQC..."
FILENAMES_TXT=*filenames_path*/small_test_sample_filenames.txt
DIR_DATA=*data_directory*
IPPG=*roote_directory on the cluster dss*
FILENAMES_PATH=$IPPG/$FILENAMES_TXT
DATA_PATH=$IPPG/$DIR_DATA
LINES=$(cat $FILENAMES_PATH)
for LINE in $LINES
do
FILE=$DATA_PATH/$LINE
echo $FILE
*home_directory_path*/FastQC/fastqc $FILE
done
echo "fastQC is done!"
When I submit this job using sbatch, the SLURM error message is:
Can't exec "java": No such file or directory
Running the script on a single sample on the HPC-Login-Node worked fine, so I think the script published by fastQC is fine, and the problem only arises, when the script is submitted to the SLURM system with sbatch.
Apparently, the fastQC-script cannot find JAVA in the SLURM system, after it was called in my Bash-script.
Can anybody with HPC / SLURM experience tell me, how to import Java into the environment when submitting a job (I am not sure if that question is phrased correctly, but I hope somebody can understand)?
Solution was found through the system administrator:
module load openjdk

Desktop entry runs but terminal closes immediately and launcher never runs

Trying to setup a desktop entry on ubuntu 21.04 for a .jar file. When I execute it manually with:
$ java -jar /home/usr/Documents/launcher.jar
It outputs some logs from the jar and seems to throw that process into the background.
So as long as the terminal is open it stays running.
But when I setup the .desktop file:
[Desktop Entry]
Type=Application
Terminal=true
Icon=/home/usr/Pictures/logos/launcher.png
Exec=java -jar "/home/usr/Documents/launcher.jar"
Name=Launcher
Comment=Launcher information here
And when I run it a terminal opens showing the logs as expected but then it just closes immediately after and the launcher never actually starts. I was able to take a screenshot of the terminal before it closed/exited and there was no errors or unexpected logging.
UPDATE 1:
I tried to see if running it manually with following command gave the same output and running it as a desktop app and it did. Failed to actually launch launcher.jar
$ gnome-terminal -e "java -jar /home/usr/Documents/launcher.jar"
Have you try to use nohup command?
Add it before your java command and redirect outputs:
nohup java -jar [...] > launcher.log 2>&1 &

Error: Unable to access jarfile (Kubernetes)

kubectl get pods -n abc
NAME READY STATUS RESTARTS AGE
abc-v2-78b59ccc4f-85xgr 0/1 CrashLoopBackOff 27 129m
Facing below error:
> ➜ ~ kubectl logs -f abc-v2-78b59ccc4f-85xgr -n
Error: Unable to access jarfile abc.jar
I am assuming either jar is not present or required access is missing.
Pls guide me here, how to proceed.
Edit 1: As suggested by #howard-roark, Jar is available inside container, getting the same error message.
Edit 2: Check results now with .jar in java command
Edit 4: Ideally there should be only one instance with running status.
Kubernetes is a Container Orchestrator. It runs your images as Containers. The error you are showing looks like an application error and not a Kubernetes error. The way I would approach this is:
Check if the jar file your application calls is in your image. You can do this locally by running your image and exec'ing in to see if your jar file that your application runs is there.
docker run -it <image> /bin/bash
Or you can do a similar command via Kubernetes to exec into your pod:
kubectl run -i --tty testjavacontainer --image=<image> -- /bin/bash
If it is there, then I would confirm its path and make sure that my java command is correctly referencing that path. If it is not there, then I would adjust my Dockerfile to ensure it is at the path that my java command expects.
In short, I would approach this as a standard java error, with the nuance that it happens to run in a container.

Running Java from an OSX ".app" bundle causes "Error -10810"

This was tested on OSX Mavericks through virtual box, and on Yosemite on a macbook.
I have a simple executable jar named "HelloWorld.jar".
I am trying to create a .app bundle for this java application. (Obviously, my actual program is more complex, but I have whittled it down to the barest problems).
CASE 1 - SIMPLE BUNDLE WITHOUT JAVA - WORKS COMPLETELY
Step 1 - Test at Console - Works
At the console I type
echo "Hello World (no java)" > /Users/josh/Desktop/test-output.txt
I view test-output.txt and see the expected output.
Step 2 - Test with Script - Works
I make a simple bash script named test:
#!/bin/bash
echo "Hello World (no java)" > /Users/josh/Desktop/test-output.txt
I chmod +x test and then type ./test, I view test-output.txt and see the expected output.
Step 3 - Create Rudimentary App Bundle - Works
mkdir -p test.app/Contents/MacOS
cp test test.app/Contents/MacOS
open test.app
I view test-output.txt and see the expected output.
CASE 2 - SIMPLE BUNDLE WITH JAVA - DOES NOT WORK
Setup
File HelloWorld.java:
public class HelloWorld {
public static void main ( String[] args ) {
System.out.println ( "Hello World" );
}
}
File myManifest
Main-Class: HelloWorld
Did the following at console:
javac HelloWorld.java
jar -cfm HelloWorld.jar myManifest HelloWorld.class
Step 1 - Test at Console - Works
At the console I type:
java -jar HelloWorld.jar > /Users/josh/Desktop/java-output.txt
I get the expected output: Hello World
Step 2 - Test with Script - Works
I make a simple bash script named "helloworld"
#!/bin/bash
java -jar HelloWorld.jar > /Users/josh/Desktop/java-output.txt
I chmod +x helloworld and then type ./helloworld, I get the expected output: Hello World
Step 3 (With Java) - Does not Work
mkdir -p helloworld.app/Contents/MacOS
cp helloworld helloworld.app/Contents/MacOS
cp HelloWorld.jar helloworld.app/Contents/MacOS
open helloworld.app
I get the following error:
LSOpenURLsWithRole() failed with error -10810 for the file /Users/josh/Desktop/helloworld/helloworld.app
/user/Josh/desktop/java-output.txt appears, but has no text inside.
As you can see, it appears that something is happening where running java inside an .app bundle is giving me that -10810 error.
Note: I also tried a variation of the first example, where I had the bash script launch /Applications/TextEdit.app, and that worked successfully. It makes me suspect the problem is with java specifically.
Does anyone have any idea what's causing this problem and how I can fix it?
I do not currently have an OS X machine handy to test this, but hints on the web from another question seem to imply that you need to set JAVA_HOME and possibly PATH in order to make java work inside the app bundle.
Specifically, at the top of your shell script, before attempting to run your program, put the following lines, with appropriate changes for your system.
export JAVA_HOME=/path/to/my/java/install
export PATH=$PATH:/path/to/directory/containing/java
More generally, to diagnose the root cause of the problem, change the existing line in your script to capture stderr and see if that gives you any useful output that might have otherwise been swallowed by the app's environment.
java -jar HelloWorld.jar > /Users/josh/Desktop/java-output.txt 2> /Users/josh/Desktop/java-error.txt
If you are able to capture the printed error, it may suffice to show you root cause.

How would I run my Java program as a daemon in RHEL 5

hi i want to run my java program as daemon service as i have a jar file for that program does any one has general daemon script that runs at boot and can be start stop and restart so please share it with me
in which i will simply change the path of jar with my jar file and i would use it
i have search for it a lot i have found 2 to 3 script but they have some error so i cant use them i will mention there link also,
http://www.source-code.biz/snippets/java/7.htm
http://www.apexninjas.com/blog/f?p=100:1:0::::P1_ARTICLE:1460
http://zerocool.is-a-geek.net/?p=139
the last link is not giving any error but it is not running service too as i check it using command "service vsftpdg status" so there is no service found error in that last link i use code and just change the path for my jar file and it would be like this,
nohup java -jar /usr/local/vsftpdg/helloworld.jar /usr/local/vsftpdg 2>> /dev/null >> /dev/null &
echo $! > /usr/local/vsftpdg/pid
and the path changes the same as it need in the further code i mentioned the way i change the file path as above
after a serarching for more then a week i am asking for general script that would run my jar file
Hopes for your help thanks in advance

Categories