fedora 13 init.d 脚本,无法停止

发布于 2024-09-15 16:31:24 字数 1067 浏览 2 评论 0原文

我编写了 init.d 脚本来运行 java CLI 进程。
问题是,当我停止它时,我[失败]并且进程仍在运行。
谢谢

#!/usr/bin/env bash
#
# chkconfig:    345 97 03
#
# processname:  quotes-srv
#
#
# source function library

. /etc/rc.d/init.d/functions

NAME=quotes-srv

start() {
    echo -n $"Starting $NAME: "
    daemon +19 java -Dlog4j.configuration="file:/opt/quotes/properties/log4j/log4j.properties"  -Dproperties_folder="/opt/quotes/properties/app/" -jar /opt/quotes/trade-0.0.1-SNAPSHOT-jar-with-dependencies.jar & 
touch /var/lock/subsys/$NAME
}

stop() {
    echo -n $"Stopping $NAME: "
    killproc $NAME
    echo
    rm -f /var/lock/subsys/$NAME
}

restart() {
    stop
    start
}

case "$1" in
  start)
    start
    ;;
  stop) 
    stop
    ;;
  restart|force-reload|reload)
    restart
    ;;
  condrestart|try-restart)
    [ -f /var/lock/subsys/$NAME ] && restart
    ;;
  status)
    status $NAME

    ;;
  *)
    echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
    exit 1
esac

exit 0

I wrote init.d script that suppose to run java CLI proccess.
The problem is that when i stop it, i get [failed] and the proccess is still running.
thanks

#!/usr/bin/env bash
#
# chkconfig:    345 97 03
#
# processname:  quotes-srv
#
#
# source function library

. /etc/rc.d/init.d/functions

NAME=quotes-srv

start() {
    echo -n $"Starting $NAME: "
    daemon +19 java -Dlog4j.configuration="file:/opt/quotes/properties/log4j/log4j.properties"  -Dproperties_folder="/opt/quotes/properties/app/" -jar /opt/quotes/trade-0.0.1-SNAPSHOT-jar-with-dependencies.jar & 
touch /var/lock/subsys/$NAME
}

stop() {
    echo -n $"Stopping $NAME: "
    killproc $NAME
    echo
    rm -f /var/lock/subsys/$NAME
}

restart() {
    stop
    start
}

case "$1" in
  start)
    start
    ;;
  stop) 
    stop
    ;;
  restart|force-reload|reload)
    restart
    ;;
  condrestart|try-restart)
    [ -f /var/lock/subsys/$NAME ] && restart
    ;;
  status)
    status $NAME

    ;;
  *)
    echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
    exit 1
esac

exit 0

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冰之心 2024-09-22 16:31:24

Killproc 将终止进程列表中与名称 $NAME 匹配的程序

严格来说,这就是您的情况 java

如果它是唯一的 java 进程,您可以将 java 放入 $NAME

如果您运行其他 java 服务,则必须找到另一种方法来停止 java 进程,例如将 PID 放入 /var/lock/subsys/$NAME 文件中然后使用pid杀死进程。

至少在 debian 上有一个很好的工具可以帮助解决这个问题,但我不确定它是否存在
红帽。

killproc will terminate programs in the process list which match the name $NAME

Strictly speaking this is in your case java .

If it is the only java process you can go and put java in $NAME

If you run other java services you have to find another way to stop your java process, e.g. putting the PID in the /var/lock/subsys/$NAME file and then killing the process using the pid.

On at least debian there is a nice tool which helps with this, but I am not sure it exists for
redhat.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文