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:
- 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:
sudo systemctl enable service.name
work? – pa4080 Jun 15 '20 at 12:12