Issue
I'm trying to do it like this:
file_name=$1
#Clear log file
echo > nohup.out
for PID in $(ps aux | grep service_name | awk {'print $2'}); do
kill -9 $PID;
done
echo "Killed old process"
nohup java -Xms256m -Xmx256m -XX:MaxMetaspaceSize=256m -jar $file_name &
echo "Started new process"
But it's just printing "Killed" and doesn't start it again. If I do all this stuff separately - it's working, but for all together - not...
Допоможіть хто зможе...
Solution
The script from which you execute it, does it contain "service_name" in its name? Then it obviously fulfills the criteria for begin killed by your for loop and commits suicide.
If it does not, then still the grep service_name
remains which fulfills the kill criteria (has service_name in its cmd line) - for fixed strings in grep I usually write them grep "s[e]rvice_name"
, other prefer to put another |grep -v grep
into the pipe before the awk
Answered By - Stefan Hegny Answer Checked By - Marilyn (WPSolving Volunteer)