i created a .jar executable file that when executed opens up two firefox selenium webdriver instances (two automated firefox instances) now when i execute the jar file through terminal likes this java -jar /opt/program.jar it works fine. but when i execute it through an upstart service:
program.conf
description "Desc"
author "Author"
start on filesystem
stop on shutdown
script
export HOME="/opt"
echo $$ > /var/run/program.pid
exec sudo /usr/bin/java -jar /opt/program.jar
end script
pre-start script
echo "[`date`] Starting" >> /var/log/program.log
end script
pre-stop script
rm /var/run/program.pid
echo "[`date`] Stopping" >> /var/log/program.log
end script
it doesn't launch any browser instances. just says
program start/running, process 14546
i would appreciate any help with how to go about doing what i am trying to do the correct way. thanks
Related
I wrote an application in java that needs five players and a server.
I need to write a script that executes the jar of the server and of every single player in different terminal windows. How can I do?
I tried a script and worked but the jar opened in the same terminal window than I tried with xterm or konsole with flag --noclose but does not work (warning command: konsole not found)
#! /bin/sh
xterm --hold -e java -jar /Users/Marco\ 1/Documents/ing-sw-2019-Lentini-Marazzi-Marini/out/artifacts/server_jar/adrenalina.jar
for X in $(seq 5)
do
konsole --noclose -e java -jar /Users/Marco\ 1/Documents/ing-sw-2019-Lentini-Marazzi-Marini/out/artifacts/client_jar/adrenalina.jar gui
done
exit;
To run a process in the background from bash, you'll need to add an & to the end of your command, e.g.
java -jar /path/to/jar/my.jar &
Otherwise bash will wait until the command execution terminates.
Not able to execute other instruction after if I am running a java jar file (which is present on another host) from my shell script.I tried using nohup but still not able to exit.
following is my script
#!/usr/bin/env bash
sshpass -p "${array[1]}" ssh -oStrictHostKeyChecking=no ${array[0]}#${array[2]} "cd ${array[3]} && echo -ne '\n' | nohup java -jar myapp.jar";
#some other instructions
echo "next statement"
already tried Scripts with nohup inside don't exit correctly but it doesn't worked.
sshpass -p pass ssh -o StrictHostKeyChecking=no xyz#hostname 'cd dir; nohup java -jar myapp.jar'
Try this with replacing the values appropriately
I have a cloud foundry application which has shell exec(builder) through which i can execute shell scripts.
My cf application first downloads the shell script and java jar to CF local (ex:/app/lib/) directory from s3 and it executes the shell script.In shell script i am triggering a java program and it fails with "Shell command returned a non-zero exit value: 127 error" .
cat my_shell_java.sh ->
#!/bin/bash
java -jar myjar.jar com.abc.def.myClass
i have tried with below command as well but same error.
cat my_shell_java.sh ->
#!/bin/bash
$JAVA_HOME/bin/java java -jar myjar.jar com.abc.def.myClass
But if i execute shell which creates a folder in CF , it works fine.
cat my_shell_mkdir.sh ->
#!/bin/bash
mkdir /app/lib
Can some one pls help me on how can i execute a java program from shell script in Cloud foundry.
You can just push the java app archive using cf push.
What is the need for the shell script?
I am just curious....
I want t start a jar which should provide a Rest-WebService.
When I run following command from terminal the jar and the webservice starts successfully:
java -jar SchnittprofilService-1.0-fat.jar BH121 8888
If I run the same command in a shell script start.sh, the jar starts but the not the webservice.
The permission for start.sh is set to 777.
Any suggestions?
Oops:
You have to put your arguments in quotation marks:
java -jar SchnittprofilService-1.0-fat.jar "BH121" "8888"
I would like to know if we can create files from a html page in browser to the linux server folder? I have a shell script which creates txt files.. But when i trigger this script from browser using ajax it doesn't create any files.. I gave all permissions to the parent directory but still i dont see file creations nor any error.
test.sh
echo "first sh"
java HelloWorld
echo "t1 test" > t1s
if [ ! -f t1s ]
then
echo "Shell File is not created .."
else
echo "Shell file is created.. "
fi
------
first.php
<?php
$output=shell_exec('sh test.sh');
echo "Hello Php \r\n";
echo $output;
echo "done \r\n";
?>
-----------
This is the output from command line:
Hello Php
hello first sh Shell file is created..
done
----------------
This is the output from broswer:
Hello Php hello first sh Shell File is not created .. done
When executing scripts via your web server, it helps to note that the environment used by your webserver is rarely identical to the environment that you see as a CLI user. For example, the command
sh test.sh
makes two assumptions: sh is in your $PATH, and test.sh is in the current working directory. It is very likely that neither of these are true when your webserver tries to run the command.
For better results, try including full paths to both the command and the file. For example:
shell_exec('/bin/sh /var/www/html/scripts/test.sh');
Finally, check the executable permissions on test.sh to be sure that the web user (httpd, or apache, or whatever) has permission to execute that script.