Distributions
› Ubuntu
› Fedora
› CentOS
中文资源站
› 网易开源镜像站
zunxiongchen
V2EX  ›  Linux

运行关机 shutdown 命令时。能不能自动关闭某些服务

  •  
  •   zunxiongchen · Nov 27, 2020 · 3452 views
    This topic created in 2180 days ago, the information mentioned may be changed or developed.
    A 自定义了一个脚本在 /etc/init.d/test,在 A 运行 service test stop,就会 ssh 到 B 机器,shutdown 关机 B 机器。
    有没有可能在 A 运行 shutdown 时自关也去跑 service test stop, 从而关闭 A 就是关闭 A+B
    10 replies  •  2020-12-01 13:10:11 +08:00
    code2fun
    code2fun
    Nov 27, 2020
    1
    可以
    Chemist
    Chemist
    Nov 27, 2020
    2
    alias down=ssh userA:passA@hostA "service test stop" && shutdown
    f6x
    f6x
    Nov 27, 2020
    3
    楼上方法好.
    直接写进 init.d 里网络情况和结果异常都没法处理.
    shily
    shily
    Nov 27, 2020
    4
    Let me Google it for you

    谷歌第一个链接是 https://opensource.com/life/16/11/running-commands-shutdown-linux 就提到了。

    runlevel 3 就是关机
    no1xsyzy
    no1xsyzy
    Nov 27, 2020
    5
    init.d 估计不行, #2 反转了控制,未必可行(比如 A 在内网?)
    systemd 倒是可以保证在网络退出前先完成 stop
    julyclyde
    julyclyde
    Nov 27, 2020
    6
    跨机器啊……这样做的话,B 那里感觉就是莫名其妙被关了
    是不是不太好?
    zunxiongchen
    zunxiongchen
    OP
    Dec 1, 2020
    7
    @kyuuseiryuu @f6x 你顾虑的对。我参考下
    zunxiongchen
    zunxiongchen
    OP
    Dec 1, 2020
    8
    @julyclyde B 机器就是 DB server 而已。服务于 A 的 web 应用,A,B 想要同步关
    zunxiongchen
    zunxiongchen
    OP
    Dec 1, 2020
    9
    @no1xsyzy 是。我用的 systemd
    no1xsyzy
    no1xsyzy
    Dec 1, 2020
    10
    关闭时运行脚本 https://unix.stackexchange.com/a/41756
    确保运行脚本前不把网络卸载 https://unix.stackexchange.com/a/294054
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4468 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 07:08 · PVG 15:08 · LAX 23:08 · JFK 02:08
    ♥ Do have faith in what you're doing.