V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
helloiac
V2EX  ›  问与答

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

  •  1
     
  •   helloiac · 2018-09-09 10:51:39 +08:00 · 866 次点击
    这是一个创建于 2067 天前的主题,其中的信息可能已经有所发展或是发生改变。

    写了个 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  
       2018-09-09 14:32:22 +08:00 via iPhone
    因为 cron 中$PATH=/usr/bin:/bin。service 是 /usr/sbin 下命令。你要么写全路径,要么 cron 中设置一下$PATH。
    helloiac
        2
    helloiac  
    OP
       2018-09-09 14:40:35 +08:00
    @bsder 学习了,谢谢!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1031 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 19:54 · PVG 03:54 · LAX 12:54 · JFK 15:54
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.