debian – Nginx init.d脚本
作者:互联网
昨天在我的debian机器上进行了dist-upgrade后,我遇到了nginx init脚本的一些问题.每当我尝试使用init脚本启动nginx时,它会出现一条错误消息:
# service nginx start
Job for nginx.service failed. See 'systemctl status nginx.service' and 'journalctl -xn' for details.
systemctl status nginx.service的输出:
# systemctl status nginx.service
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled)
Active: failed (Result: exit-code) since Tue 2015-05-19 12:36:12 CEST; 7s ago
Process: 14087 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 14126 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=203/EXEC)
journalctl -xn的输出:
# journalctl -xn
systemd[1]: nginx.service never wrote its PID file. Failing.
systemd[1]: Failed to start A high performance web server and a reverse proxy server.
-- Subject: Unit nginx.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit nginx.service has failed.
--
-- The result is failed.
systemd[1]: Unit nginx.service entered failed state.
systemd[14126]: Failed at step EXEC spawning /usr/sbin/nginx: No such file or directory
-- Subject: Process /usr/sbin/nginx could not be executed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- The process /usr/sbin/nginx could not be executed and failed.
--
-- The error number returned while executing this process is 2.
systemd[1]: nginx.service: control process exited, code=exited status=203
systemd[1]: Failed to start A high performance web server and a reverse proxy server.
-- Subject: Unit nginx.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit nginx.service has failed.
--
-- The result is failed.
systemd[1]: Unit nginx.service entered failed state.
我在init.d中的nginx文件:
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/sbin/nginx
NAME=nginx
DESC=nginx
test -x $DAEMON || exit 0
# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
. /etc/default/nginx
fi
set -e
. /lib/lsb/init-functions
case "$1" in
start)
echo -n "Starting $DESC: "
start-stop-daemon --start --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
--exec $DAEMON -- $DAEMON_OPTS || true
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon --stop --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
--exec $DAEMON || true
echo "$NAME."
;;
restart|force-reload)
echo -n "Restarting $DESC: "
start-stop-daemon --stop --quiet --pidfile \
/usr/local/nginx/logs/$NAME.pid --exec $DAEMON || true
sleep 1
start-stop-daemon --start --quiet --pidfile \
/usr/local/nginx/logs/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true
echo "$NAME."
;;
reload)
echo -n "Reloading $DESC configuration: "
start-stop-daemon --stop --signal HUP --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
--exec $DAEMON || true
echo "$NAME."
;;
status)
status_of_proc -p /usr/local/nginx/logs/$NAME.pid "$DAEMON" nginx && exit 0 || exit $?
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2
exit 1
;;
esac
exit 0
nginx守护程序文件位于/usr/local/sbin / nginx(我在那里编译).
到目前为止我尝试过的事情:
我将守护进程文件/usr/local/sbin / nginx复制到/usr/sbin / nginx
当我使用服务nginx启动它挂起启动nginx.当我尝试连接到端口80时,它确实有效.所以我继续编辑我的init脚本并将PATH = /usr/local/sbin:/usr/local/bin:/ sbin:/ bin:/usr/sbin:/usr/bin更改为PATH = /usr/sbin:/ USR /斌:/ sbin目录:/ bin中:/usr/sbin目录:在/usr/bin中.然而,这给出了相同的结果.
到目前为止我还没有尝试过其他任何东西.
解决方法:
my nginx file in init.d:
……完全无关紧要.查看systemctl的输出.它告诉你究竟要查看的文件:
Loaded: loaded (/lib/systemd/system/nginx.service; enabled)
那是你的服务单位. systemctl告诉您该服务单元为准备启动服务而配置的内容:
Process: 14126 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=203/EXEC)
这就是您在服务单元的ExecStartPre设置中找到的内容.你会注意到PATH也完全不相关(在systemd中是设计的).期刊对发生的事情更加明确:
systemd[14126]: Failed at step EXEC spawning /usr/sbin/nginx: No such file or directory
无论您怎么想,计算机都认为在您尝试启动该服务时,/usr/sbin / nginx无法作为程序运行,因为该名称不存在任何文件.
我有根据的猜测是,您的服务单元中有一个RootDirectory设置,并且您将文件复制到不在更改的根环境中的/usr/sbin,或者从加载程序映像所需的某些辅助共享库中丢失了改变了根环境.
标签:init-d,nginx,debian 来源: https://codeday.me/bug/20190812/1642573.html