写了个 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'
1
bsder 2018-09-09 14:32:22 +08:00 via iPhone
因为 cron 中$PATH=/usr/bin:/bin。service 是 /usr/sbin 下命令。你要么写全路径,要么 cron 中设置一下$PATH。
|