linux - RHEL7 中的服务

标签 linux shell rhel7 systemctl

我已经有一个为 RHEL6 编写的服务,并且我有一些可以执行的自定义服务命令。请参阅下面的脚本摘录。

case "$1" in
    'start')
        start
        ;;
    'stop')
        stopit
        ;;
    'restart')
        stopit
        start
        ;;
    'status')
        status
        ;;
    'AppHealthCheck')
        AppHealthCheck
        ;;
    *)
        echo "Usage: $0 {  start | stop | restart | status | AppHealthCheck }"
        exit 1
        ;;
esac 

所有被调用的方法都有定义...所以以前在 RHEL6 中如果我必须执行服务并查看它是否健康我曾经执行服务 $servicename AppHealthCheck .. 它曾经工作但现在在 RHEL7 我如果我想检查 AppHealth,我无法在服务单元文件中定义...就我所做的研究而言,我了解到可以定义服务启动/停止/重启时调用的内容,但无法找到如果我们可以在脚本中调用任何自定义方法..请查看下面我的服务单元文件:-

[Unit]
Description=SPIRIT Agent Application

[Service]
Type=forking
ExecStart=scripts/Agent start
ExecStop=scripts/Agent stop
ExecReload=scripts/Agent restart

[Install]

你能帮我解决这个问题吗?如果需要更多信息,请告诉我。

最佳答案

systemd 方法是将输出发送到日志,以便 systemctl status 显示最新的日志消息,并告诉您服务是否正在运行。如果您想要更详细的状态,您可以创建一个单独的命令行命令来执行 AppHealthCheck。它不会通过 systemctl 执行,它是一个单独的东西。

这就是Pacemaker工作,例如。 systemctl status pacemaker 显示服务是否正在运行。

# systemctl status pacemaker
● pacemaker.service - Pacemaker High Availability Cluster Manager
   Loaded: loaded (/usr/lib/systemd/system/pacemaker.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2016-11-10 15:28:11 GMT; 1 weeks 3 days ago

Nov 11 15:54:59 node1 crmd[4422]:   notice: Operation svc1_stop_0: ok (node=node1, call=93, rc=0, cib-update=134, confirmed=true)
Nov 11 15:54:59 node1 crmd[4422]:   notice: Operation svc2_stop_0: ok (node=node1, call=95, rc=0, cib-update=135, confirmed=true)
Nov 11 15:54:59 node1 crmd[4422]:   notice: Operation svc3_stop_0: ok (node=node1, call=97, rc=0, cib-update=136, confirmed=true)

pcs status 提供了有关其运行情况的更多详细信息。

# pcs status
Cluster name: node
Stack: corosync
Current DC: node2 (version 1.2.3) - partition with quorum
2 nodes and 3 resources configured

Online: [ node1 node2 ]

Full list of resources:

 <snip>

PCSD Status:
  node1: Online
  node2: Online

Daemon Status:
  corosync: active/enabled
  pacemaker: active/enabled
  pcsd: active/enabled

关于linux - RHEL7 中的服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40722137/

相关文章:

c++ - 链接器错误: “relocation R_X86_64_PC32 against symbol ` xmlFree'…使用-fPIC重新编译”,但已经使用-fPIC编译了违规的库

sql - 您将如何使用Gradle处理增量SQL补丁

regex - 在Linux命令行上通过Regex获取一部分主机名

python-3.x - 安装 nltk 包时出现 ModuleNotFoundError : No module named '_sqlite3'

linux - 为 tpm 模拟器安装裤子

linux - 制作一个 bash 脚本来刷新值,而无需像 TOP 命令那样向下滚动终端

c - #error 您现在需要定义 FIXED_POINT 或 FLOATING_POINT

shell 脚本 "syntax error: ` 意外完成。”

mysql - Ansible Playbook 使用 mysql 1044, "Access denied for user ' root' @'localhost' 到数据库 'scm' "

python - Ansible mysql_user 与 Percona 57 和 RHEL7