3

Received the following error when trying to start nginx on boot in Raspbian GNU/Linux 8 (jessie)

● 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 Sun 2016-08-07 10:38:50 EDT; 1min 10s ago
  Process: 478 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)

My config works fine, and I'm able to start nginx after logging in; but I can't get systemd to start it.

Here is my Unit file:

# 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=syslog.target network.target remote-fs.target nss-lookup.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

/lib/systemd/system/nginx.service

What target do I need to start this after? I've already tried network-online.target (which would make the most sense, and received the same result.

Update

I changed a few things thanks to this post and I got nginx to start up...but it still fails with an error.

  1. Modified /etc/systemd/system/mult-user.target.wants/nginx.service to include:
    1. After=network-online.target
    2. Wants=network-online.target
      1. Before it was After=network.target
  2. Ran sudo systemctl enable systemd-networkd-wait-online.service, to start that up (since network-online.target can't be enabled up using sudo systemctl enable network-online.target)
  3. Ran sudo systemctl enable nginx
  4. Restarted...
  5. After the restart, I ran systemd-analyze plot > something.svg and search for nginx.service within the file, and it was present, however it did not successfully start up instead giving me an error about my reverse proxy server..which I'm not sure how to solve, but that's a topic for another question.

Below is the image I got from systemd-analyze plot:

systemd-analyze output...

However...after I boot the machine, and run sudo systemctl start nginx it starts without issue.

Here is the error message from the error log:

2017/05/16 13:12:53 [emerg] 555#0: host not found in upstream "somehost.somedomain.lan" in /etc/nginx/sites-enabled/siteconf:41

Here is config line in question:

server {
     listen     80; ## listen for ipv4; this line is default and implied
    #listen   [::]:80 default_server ipv6only=on; ## listen for ipv6

    # Make site accessible from http://localhost/
    server_name somehost somehost.somedomain.lan;

    # Note: There should never be more than one root in a 
    #       virtual host
    #   Also there should never be a root in the location.
    #root /var/www/nginx/;

         location ^~ / {
            resolver 127.0.0.1 valid=300s; # NOTE: Added this to resolve it.
            access_log ./logs/RootWiki_access.log;
            error_log ./logs/RootWiki_error.log;
            proxy_buffers 16 4k;
            proxy_buffer_size 2k;
            proxy_set_header Host $host;
            proxy_set_header X-Real_IP $remote_addr;
            rewrite /(.*) /$1 break;
            proxy_pass http://wiki.leerdomain.lan:8080; # NOTE: This one causes the error according to the error log.
        }

migrated from raspberrypi.stackexchange.com Aug 7 '16 at 15:06

This question came from our site for users and developers of hardware and software for Raspberry Pi.

  • Could this have something to do with it? Using the Timer Seciton to slow the startup down? digitalocean.com/community/tutorials/… – leeand00 Nov 23 '16 at 16:55
  • Are you binding to an IPv6 address? – ppparadox May 17 '17 at 9:49
  • Also you haven't shown any log messages. – ppparadox May 17 '17 at 9:55
  • @ppparadox No, ipv4. I'll get those log messages for you... – leeand00 May 17 '17 at 14:39
  • @ppparadox Okay, I added the log message and the configuration line in question. – leeand00 May 17 '17 at 14:52
1

Got this working:

# 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=muli-user.target
Requires=network-online.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

under the Unit section I added the following:

[Unit]
# ...
After=muli-user.target
Requires=network-online.target

/lib/systemd/system/nginx.service

I also ran the following in the bash:

$ sudo systemctl enable nginx

and then to make sure the symbolic link shows up:

$ ls -la /etc/systemd/system/multi-user.target/wants
...
lrwxrwxrwx  1 root root   33 May 14  2016 nginx.service -> /lib/systemd/system/nginx.service
...

and then reload the daemons:

$ sudo systemctl daemon-reload

and finally reboot and see if it's there:

$ sudo systemctl status --state active | grep nginx

Graph showing that nginx.service has been moved after the multi-user target

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.