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.jsIt works for forever, but nginx never starts.
I also tried:
@reboot /etc/init.d/nginx reload
@reboot sudo service nginx reloadAny ideas?
My nginx conf looks like this:
server { listen 443 ssl; server_name ssl_certificate /var/wwwssl/example.pem; ssl_certificate_key /var/wwwssl/example.key.pem; location / { proxy_pass 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=alwayswhich 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
enabledI 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 "" 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:
- I reboot the server
- After reboot the node app is running (crontab starts the forever process)
- Nginx has errors
- 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:
122 Answers
Roman:
sudo systemctl enable nginxCan you try with this command to set link to init as SysV?
update-rc.d nginx defaultsWhy 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. 1 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