nginx autostart after reboot

Topics about the Software of Revolution Pi
Post Reply
Peter_Platzer
Posts: 12
Joined: 18 Feb 2024, 12:37

nginx autostart after reboot

Post by Peter_Platzer »

Hi!

I installed nginx on RevPi with:

Code: Select all

sudo apt install nginx
I was able to start it after installation with

Code: Select all

sudo /etc/init.d/nginx start
and it worked fine.

After a reboot the nginx was not running any more.
I thought it would be possible to enable autostart with

Code: Select all

sudo systemctl enable nginx
but this does not work.
I see the following erorrs in the daemon.log:

Code: Select all

nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (2: No such file or directory)
nginx[2601]: 2024/08/03 18:16:18 [emerg] 2601#2601: open() "/var/log/nginx/access.log" failed (2: No such file or directory)
nginx[2601]: nginx: configuration file /etc/nginx/nginx.conf test failed
systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
nginx.service: Failed with result 'exit-code'.
I tried to start it with

Code: Select all

sudo /etc/init.d/nginx start
But this does not work:

Code: Select all

Starting nginx (via systemctl): nginx.serviceJob for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.
 failed!
If I create the directories and files.

Code: Select all

sudo mkdir /var/log/nginx
cd nginx
sudo nano access.log
sudo nano error.log
it is possible to start it again with:

Code: Select all

sudo /etc/init.d/nginx start
As /var/log/ is a tmpfs file system directories and files are gone after reboot.

How is it possible to create directories and files at boot time befor starting nginx?
Or how do I get the nginx autostart working?
Peter_Platzer
Posts: 12
Joined: 18 Feb 2024, 12:37

Re: nginx autostart after reboot

Post by Peter_Platzer »

I solved it with a pyhton programm after boot using revpipyload.

Code: Select all

    if os.path.exists('/var/log/nginx')== False:
        os.system('sudo mkdir /var/log/nginx')
        os.system('sudo touch /var/log/nginx/access.log')
        os.system('sudo touch /var/log/nginx/error.log')
        os.system('sudo /etc/init.d/nginx start')
and it works fine.
u.biakoup
KUNBUS
Posts: 201
Joined: 14 Apr 2022, 13:04

Re: nginx autostart after reboot

Post by u.biakoup »

Hello Peter,

I am happy to hear that you solved the problem.
Enjoy it!
Best Regards

Ulrich Kouatang Biakoup | field application engineer
Post Reply