Through the command nohup Java - jar channel. The jar & amp; Perform
Now I'd like to perform this action as the service form, the shell file called channeld
Shell program is as follows:
#!/bin/bash
# author: qinhan
NAME="channel. The jar
"PROCESS="/home/are/channel. The jar"
# start channeld
Start () {
Echo "starting channel... "
CD/home/are
Sudo rm/var/lock/LCK.. TtyS33333
Nohup Java - jar channel. The jar & amp;
Echo "channel successful... "
}
# stop channeld
Stop () {
Pid=` ps - ef | grep "$NAME" | grep -v "grep" | awk '{print $2}' `
If [" $pid "=" "]. Then
Echo "No channel pid alive... "
The else
Echo "now, kill pid $pid... "
Sudo kill 9 $pid
Echo "channel stopped successful... "
Fi
}
# show the status of channeld
The status () {
Pid=` ps - ef | grep "channel. The jar" | grep -v "grep" | awk '{print $2}' `
If [" $pid "=" "]. Then
Echo "channel is stopped... "
The else
Echo "channel is running... "
Fi
}
# restart channel
Restart () {
Stop
Start
}
# the execute by input command
Case "$1" in
Start)
Start
;;
Stop)
Stop
;;
Status)
The status
;;
Restart)
Restart
;;
*)
Echo $" Usage: $0 {start | stop | status | restart} "
The exit 1
Esac
By calling service channeld start/stop/status/restart to perform channel. The jar program
Question:
[color=# FF0000] [color=# FF0000] when I call the service channeld start/status when there is no problem, the call to service channeld stop, always cannot kill process
But the active prompt service from running into the dead, but the process has been, did not kill the diagram below
CodePudding user response:
Ps take PID, have more than oneCodePudding user response:
Only one, every instruction I tried, and use grep -v grep removed the grep itself,I dropped my stop inside other's comments, and then change to the
Stop () {
Kill ` ps - ef | grep channel. The jar | grep -v grep | awk '{print $2}' `
}
No problem, can kill,
This is the if judgment problems over there? Judge if there is written so? Then kill $pid??????
CodePudding user response:
NAME="channel. The jar"PROCESS="/home/are/channel. The jar"
About=no Spaces
CodePudding user response:
The two are not used, I forgot to put their comments,