无法通过 systemd 重新启动 nginx,因为它已在运行

无法通过 systemd 重新启动 nginx,因为它已在运行

我正在尝试重新启动 nginx,但 systemd 不愿意。

据我所知,nginx 运行良好,并且按预期响应请求,但 systemd 似乎并不认为它可以控制该服务,因此我猜它会尝试启动一个新的副本,但会失败,因为现在它尝试绑定到已被占用的 :80。

经过一些故障排除后,我放弃了,并重新启动了机器,以为这样可以解决问题,但令我惊讶的是,我又回到了同样的状态。

我能找到让 systemd 满意的唯一方法是

# killall nginx
# systemctl restart nginx.service

但我显然不想依赖它。有关我目前状态的信息:

# systemctl restart nginx.service
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

# journalctl -xe
-- Unit nginx.service has begun starting up.
Oct 22 12:12:43 shared1 nginx[4772]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx[4772]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx[4772]: nginx: [emerg] still could not bind()
systemd[1]: nginx.service: Control process exited, code=exited status=1
systemd[1]: Failed to start A high performance web server and a reverse proxy server.
-- Subject: Unit nginx.service has failed

# netstat -lpn | grep :80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      3607/nginx

# ps fax | grep nginx
4827 pts/0    S+     0:00                          \_ grep --color=auto nginx
3607 ?        Ss     0:00 nginx: master process /usr/sbin/nginx
3608 ?        S      0:00  \_ nginx: worker process
3609 ?        S      0:00  \_ nginx: cache manager process

# cat /etc/issue
Ubuntu 16.04.3 LTS \n \l

$ nginx -v
nginx version: nginx/1.10.3 (Ubuntu)

$ find /etc/systemd/ /lib/systemd/system -name nginx.service
/etc/systemd/system/multi-user.target.wants/nginx.service
/lib/systemd/system/nginx.service
$ stat /etc/systemd/system/multi-user.target.wants/nginx.service 2>&1 | head -n1
  File: '/etc/systemd/system/multi-user.target.wants/nginx.service' -> '/lib/systemd/system/nginx.service'
$ stat /lib/systemd/system/nginx.service 2>&1 | head -n2
  File: '/lib/systemd/system/nginx.service'
  Size: 986             Blocks: 8          IO Block: 4096   regular file

答案1

sudo killall apache2

解决作业nginx.service因控制进程退出并显示错误代码而失败的问题。详情请参阅systemctl status nginx.service和。journalctl -xe

相关内容