systemd로 부팅 할 때 nginx 시작 이제 systemctl로 알아 내려고 노력 중입니다. ~$ systemctl

방금 데비안 8 서버에 nginx 1.9를 설치했습니다. nginx가 제대로 작동한다고 말하면 부팅 할 때 자동으로 nginx를로드하지 않는 것 같습니다.

인터넷에서 권장되는 수많은 init 스크립트를 시도했지만 아직 아무것도 작동하지 않았습니다. 이제 systemctl로 알아 내려고 노력 중입니다.

~$ systemctl status nginx
● nginx.service
   Loaded: masked (/dev/null)
   Active: inactive (dead)
~$ sudo systemctl try-restart nginx
Failed to try-restart nginx.service: Unit nginx.service is masked.
~$ sudo systemctl reload nginx
Failed to reload nginx.service: Unit nginx.service is masked.
~$ sudo systemctl reload nginx
Failed to reload nginx.service: Unit nginx.service is masked.

불행히도 “서비스가 마스킹 됨”의 의미를 모르며 왜 마스킹되는지 모르겠습니다.

내가 달릴 때

sudo nginx

서버는 정상적으로 작동합니다. 그런 다음 nginx 서비스를 마스킹 해제하는 방법을 살펴 보았습니다.

~$ sudo systemctl unmask nginx.service
Removed symlink /etc/systemd/system/nginx.service.

좋아, 이제 systemctl을 사용하여 nginx를 시작할 수 있습니다. 그래서 재부팅하면 nginx가 자동으로로드되는지 확인했습니다. 그러나 그것은 그렇게하지 않으며, 나는 여기서 어디로 가야할지 전혀 모른다.

부팅시 nginx가 자동으로 실행되도록 도와 줄 수 있습니까?



답변

작동, 시작 및 마스크 작업을 혼동하는 것 같습니다.

  • systemctl start, systemctl stop: 해당 장치를 즉시 시작 (중지)합니다 .
  • systemctl enable, systemctl disable: 부팅시 자동 시작을 위해 장치를 표시 (표시 해제)합니다 ( [Install]섹션에 설명 된 장치 별 방식 ).
  • systemctl mask, systemctl unmask: 문제의 장치를 시작하려는 모든 시도 및 모든 시도를 수동으로 또는 기본 부팅 대상의 종속성을 포함하여 다른 장치의 종속성으로 허용하지 않습니다 (허용). systemd에서 자동 시작 표시는 기본 부팅 대상에서 해당 장치에 인공 종속성을 추가하여 구현되므로 “마스크”도 자동 시작을 허용하지 않습니다.

따라서이 모든 것이 별개의 작업입니다. 이 중 당신은 원합니다 systemctl enable.

참조 : systemctl (1) .

더 : Lennart Poettering (2011-03-02). “세 가지 수준의 꺼짐” . 관리자 용 시스템 . 0pointer.de.


답변

허용 된 답변의 링크가 오른쪽 페이지로 리디렉션되도록 수정했습니다. 그러나 여기 관련 비트가 있습니다.

sudo systemctl enable nginx.service
sudo systemctl start nginx.service
sudo systemctl status nginx.service

여기서 /lib/systemd/system/nginx.service다음과 같은 :

# Stop dance for nginx
# =======================
#
# ExecStop sends SIGSTOP (graceful stop) to the nginx process.
# If, after 5s (--retry QUIT/5) nginx is still running, systemd takes control
# and sends SIGTERM (fast shutdown) to the main process.
# After another 5s (TimeoutStopSec=5), and if nginx is alive, systemd sends
# SIGKILL to all the remaining processes in the process group (KillMode=mixed).
#
# nginx signals reference doc:
# http://nginx.org/en/docs/control.html
#
[Unit]
Description=A high performance web server and a reverse proxy server
After=network.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -q -g 'daemon on; master_process on;'
ExecStart=/usr/sbin/nginx -g 'daemon on; master_process on;'
ExecReload=/usr/sbin/nginx -g 'daemon on; master_process on;' -s reload
ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid
TimeoutStopSec=5
KillMode=mixed

[Install]
WantedBy=multi-user.target

`

답변

나를 위해 일한 것 :
https://web.archive.org/web/20150328063215/https://longhandpixels.net/blog/2014/02/install-nginx-debian-ubuntu

다른 버전의 nginx 컴파일과 관련된 대부분의 문서를 무시하고 “자동 시작”으로 넘어갔습니다.

나는 거기의 지시를 따르고, 이제 재부팅 할 때 nginx 1.9가 실행 중입니다.

나는 모든 사람의 도움과 통찰력을 분명히 감사합니다. 모두 감사합니다!


답변

nginx 리소스에서 https://www.nginx.com/resources/wiki/start/topics/examples/systemd/

echo "
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
" > /lib/systemd/system/nginx.service