V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
helloiac
V2EX  ›  问与答

cron 中启动 apache 服务的两个命令,一个行,一个不行

  •  1
     
  •   helloiac · Sep 9, 2018 · 1247 views
    This topic created in 2800 days ago, the information mentioned may be changed or developed.

    写了个 shell 脚本,cron 每分钟执行,发现 apache2 进程停止了就去重启 apache2,尝试用了下面两个命令格式:

    √ /etc/init.d/apache2 start

    × service apache2 start

    结果第一个可以,第二个不行。都是 root 权限,apache 的日志也都一样。

    请教为什么。

    # 进程测试 service apache2 start,结果进程未启动
    [Sun Sep 09 10:29:27.037734 2018] [mpm_event:notice] [pid 17399:tid 3074283264] AH00491: caught SIGTERM, shutting down
    [Sun Sep 09 10:30:30.292831 2018] [mpm_event:notice] [pid 17768:tid 3074914048] AH00489: Apache/2.4.34 (Ubuntu) OpenSSL/1.1.0h configured -- resuming normal operations
    [Sun Sep 09 10:30:30.292967 2018] [core:notice] [pid 17768:tid 3074914048] AH00094: Command line: '/usr/sbin/apache2'
    
    # 进程测试 /etc/init.d/apache2 start,进程启动了
    [Sun Sep 09 10:40:49.433989 2018] [mpm_event:notice] [pid 17768:tid 3074914048] AH00491: caught SIGTERM, shutting down
    [Sun Sep 09 10:41:03.682583 2018] [mpm_event:notice] [pid 18234:tid 3074279168] AH00489: Apache/2.4.34 (Ubuntu) OpenSSL/1.1.0h configured -- resuming normal operations
    [Sun Sep 09 10:41:03.682709 2018] [core:notice] [pid 18234:tid 3074279168] AH00094: Command line: '/usr/sbin/apache2'
    
    bsder
        1
    bsder  
       Sep 9, 2018 via iPhone
    因为 cron 中$PATH=/usr/bin:/bin。service 是 /usr/sbin 下命令。你要么写全路径,要么 cron 中设置一下$PATH。
    helloiac
        2
    helloiac  
    OP
       Sep 9, 2018
    @bsder 学习了,谢谢!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3052 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 04:08 · PVG 12:08 · LAX 21:08 · JFK 00:08
    ♥ Do have faith in what you're doing.