7

I am using crontab to start some services after a reboot.

Here is my current crontab:

@reboot root /etc/init.d/nginx reload
@reboot /usr/local/bin/forever start /var/www/rtc/index.js

It works for forever, but nginx never starts.

I also tried:

@reboot /etc/init.d/nginx reload
@reboot sudo service nginx reload

Any ideas?

My nginx conf looks like this:

server {
        listen 443 ssl;
        server_name www.example.com;
    ssl_certificate /var/wwwssl/example.pem;
    ssl_certificate_key /var/wwwssl/example.key.pem;

    location / {
            proxy_pass https://www.example.com:8443;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
    }

}

EDIT:

This solution also did not work

Do that with a systemd drop-in:

[Service]
Restart=always

which you place as the file /etc/systemd/system/nginx.service.d/override.conf (creating the directory if it doesn't exist). You can also use systemctl edit nginx to create the file.

EDIT:

The service is enabled.

# systemctl is-enabled nginx
enabled

I still have no clue why nginx does not start.

After every shutdown -r (I use this to test reboot) I check with sudo service --status-all and nginx is not running.

EDIT

The syslogs show some errors for nginx after reboot:

nginx: [emerg] host not found in upstream "www.example.com" in /etc/nginx/sites-enabled/default:100
nginx: configuration file /etc/nginx/nginx.conf test failed
nginx.service: Control process exited, code=exited, status=1/FAILURE
nginx.service: Failed with result 'exit-code'.
Failed to start A high performance web server and a reverse proxy server.

EDIT:

Tried to add a resolver:

resolver IP valid=30s;

Still the same issue

EDIT

It may be that nginx cant start after reboot, because of the start order? Nginx must be started by root. The node app is started by nodeuser with crontab.

Manually it works:

  1. I reboot the server
  2. After reboot the node app is running (crontab starts the forever process)
  3. Nginx has errors
  4. I start nginx with service nginx restart

I assume what leads to the problem is:

After reboot the root process is handled first. Nginx tries to start, but the node app is not started yet, so it bugs out. But how would I fix that?

I seems order makes no difference. I removed the forever start and after reboot the same errors show up.

nginx -t:

enter image description here

Roman
  • 143

2 Answers2

2

Roman:

sudo systemctl enable nginx

Can you try with this command to set link to init as SysV?

update-rc.d nginx defaults

Why set nginx defaults?

When  run  with  the  defaults  option,  update-rc.d  makes links named
       /etc/rcrunlevel.d/[SK]NNname that point to the script /etc/init.d/name,
       using  runlevel  and  dependency information from the init.d script LSB
       comment header.
Adrian
  • 174
2

The solution is also explained in this stack topic

I had to replace the domain in proxy_pass in the nginx config with the IP:

proxy_pass https://<IP-OF-YOUR-SERVER>:8443;
Roman
  • 143