haozi1986
V2EX  ›  问与答

添加到 init.d 的服务不显示 echo 信息,请问问题出在哪里?谢谢

  •  
  •   haozi1986 · Oct 29, 2016 · 2311 views
    This topic created in 3592 days ago, the information mentioned may be changed or developed.
    最近重新部署了 VPS ,系统是 Ubuntu 16.04.1 x32 ,但是发现了一个问题

    我自己添加了很多服务到 init.d 里面,比如控制 nginx 以及 aria2c 之类的,在之前的系统里面,启动、关闭、重启服务都会显示相应的 echo 消息,比如服务脚本里的 echo "已开启 nginx"等均可以正常显示,但是这一次不管怎样都没有了相关信息的显示,不过如果在其它目录里面按照 ./***.sh 的方式运行, echo 则可以正常显示……

    虽说消息不显示并不妨碍正常使用,但总是强迫症发作想改过来,并且也很想知道问题究竟出在哪里,在网上搜索了很久都没找到相关的解决办法,特意请教一下各位

    另说明一下,我所有操作均是在 root 权限下进行的

    谢谢

    附一个说明测试:( root 账户下进行)

    nano /etc/init.d/test

    #!/bin/bash
    case "$1" in
    start)
    echo "start"
    ;;
    stop)
    echo "stop"
    ;;
    restart)
    echo "restart"
    ;;
    esac
    exit 0

    chmod 755 /etc/init.d/test
    systemctl daemon-reload

    按理说执行 service test start 就会显示 start ,但是并没有……
    2 replies    2016-10-29 23:26:15 +08:00
    BOYPT
        1
    BOYPT  
       Oct 29, 2016   ❤️ 1
    在 systemd 里面,/etc/init.d 里面的文件已经不是在主要的服务启动方式,而是 systemd 的 service unit ,旧版的 init.d 文件通过 unit 配置文件里面类似下面这样的方式启动

    [Service]
    ExecStart=/etc/init.d/xxx start
    ExecStop=/etc/init.d/xxx stop

    脚本启动过程不是根据当前 shell 子进程启动的, stdin/out/err 都会被 systemd 接管,所以你看不到 echo 了。
    haozi1986
        2
    haozi1986  
    OP
       Oct 29, 2016 via Android
    @BOYPT 啊,原来如此,完全没想到是这个原因,之前 VPS 系统是 Ubuntu 14 ,我就还在疑惑为什么那时候是正常的
    感谢解答!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1111 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 17:34 · PVG 01:34 · LAX 10:34 · JFK 13:34
    ♥ Do have faith in what you're doing.