CentOS 5.5:关闭时服务未停止

Bor*_*ris 5 centos service

我已经编写了脚本 /etc/init.d/xxx 来启动/停止我在 CentOS 5.5 上的服务。

当我调用“service start xxx”或“service stop xxx”时,一切正常。但是当我重新启动机器时,我在日志中看到关闭时服务没有停止。

但是,它在启动时启动。

> chkconfig --list xxx 
 xxx 0:关 1:关 2:开 3:开 4:开 5:开 6:关

我做错了什么。谢谢你。

UPD:脚本的标题:

#!/bin/bash
#
# Startup script for the xxx
#
# chkconfig: 345 99 01
# description: This script ...
#

### BEGIN INIT INFO
# Provides: xxx
# Required-Start: $local_fs $network
# Required-Stop: $local_fs $network
# Should-Start:
### END INIT INFO
Run Code Online (Sandbox Code Playgroud)

Bog*_*anu 10

我不是 linux 专家,实际上更像是一个菜鸟,但为了执行关闭脚本,您必须在启动脚本的 /var/lock/subsys/ 文件夹中创建一个锁定文件。我在这里找到了答案: CentOS 论坛

脚本示例:

#!/bin/sh
# chkconfig: 345 98 11
# description: my auto start-stop script.

echo "my service is doing something :)" >> /root/tempfile
case "$1" in
 start)
  echo "my service started" >> /root/tempfile
  touch /var/lock/subsys/myservice
  echo "OK"
  ;;
 stop)
  echo "my service stoped" >> /root/tempfile
  rm -f /var/lock/subsys/myservice
  echo "OK"
  ;;
esac
Run Code Online (Sandbox Code Playgroud)


小智 2

您可能必须在 /etc/rc6.d/ 目录中创建一个链接,以便在关闭服务器时调用该脚本。

ls -l /etc/rc5.d/K60nfs

lrwxrwxrwx 1 root root 2010 年 5 月 13 日 13 /etc/rc5.d/K60nfs -> ../init.d/nfs