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

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

  •  
  •   zunxiongchen · Nov 27, 2020 · 3026 views
    This topic created in 2017 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
    collery
        1
    collery  
       Nov 27, 2020
    可以
    Chemist
        2
    Chemist  
       Nov 27, 2020
    alias down=ssh userA:passA@hostA "service test stop" && shutdown
    f6x
        3
    f6x  
       Nov 27, 2020
    楼上方法好.
    直接写进 init.d 里网络情况和结果异常都没法处理.
    shily
        4
    shily  
       Nov 27, 2020
    Let me Google it for you

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

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