Reputation: 11
I have used the following scripting for start and stop a jar file.
**start.sh**
#!/bin/bash
nohup nice java -jar Server.jar > ./Server.out 2>&1 &
**stop.sh**
#!/bin/bash
kill `ps -ef | grep Server.jar | grep -v grep | awk '{ print $2 }'`
Now I want to merge both scripts and create a new restart script. I also want this script output in a terminal instead of a text file(Server.out).
Would appreciate any kind of input/help.
Upvotes: 1
Views: 2272
Reputation: 28762
You can either put the commands of the two sripts after each other (kill
first, java
second) or just call the two scipts in the appropriate order.
The idea is that restart is basically equivalent to killing the current running version and starting a new one.
To avoid the output to a file, remove the > ./Server.out
part.
Edit: removed note about removing the redirection part as I misread the grep
part of the kill
script
Update: Missed the nohup
part of the script: with nohup
you need to redirect output to a file, because the process is detached from the terminal (see documentation). If you do want to see the output in the terminal, remove nohup
as well as the redirection to the file
Upvotes: 1