1

I have an NGINX server (used for RTMP) installed on a Raspberry Pi3 running the latest version of Raspbian (as of this writing). I would like to have the NGINX server start automatically when the Pi powers on.

It would seem logical to me that this would have to be done after the user logs in, so I have enabled automatic login for the user foo. However, I have tried adding to /etc/init.d as well as using crontab (@reboot wait 5; /home/start_server.sh &) as well as adding pid /var/run/nginx.pid; to the NGINX config file and have had no success in starting the server at boot.

The contents of start_server.sh are as follows: sudo /usr/local/nginx/sbin/nginx

When I run the script from the terminal, the server starts up just fine.

I would like to know how to have the NGINX server start at boot. Acceptable answers are [explained] code snippets, [justified] links to tutorials, or any other comprehensible answer.

Thanks for the time in advance!

  • "I would like to have the NGINX server start automatically when the Pi powers on." -> This is not the same thing as "at login" but I think you are sort of aware of that. "It would seem logical to me that this would have to be done after the user logs in" -> Nope, in fact it is the other way around -- it does not make much sense to start a persistent inet server directly as a logged in user (although it is possible). Computer systems commonly do lots of things without anyone logged into them. Internet servers, for example, which are very commonly GNU/Linux based and deploy nginx. – goldilocks Sep 19 '16 at 22:56
  • The normative way to do this is via the init system, which is responsible for boot services (including the applications which allow a login). On current versions of Raspbian, init is systemd. Beware that previous versions used SysV init, and that is what init.d is a part of. You will find some discussion of that in the wikipedia article. So: Don't waste time on material that talks about /etc/init.d (or various rc.d directories, or tools related to them). You will be learning obsolescence that way. – goldilocks Sep 19 '16 at 22:56
  • 1
    If you installed nginx via the package manager, chances are there is already a systemd unit available for it. Try systemctl list-unit-files | grep nginx and see if it says anything. – goldilocks Sep 19 '16 at 22:56
  • If not, hey look: NGINX systemd service file <- From the official NGINX site. If you don't get how to apply this (the instructions there aren't complete and I think assume you understand how to use systemd already), leave a comment and I'll put all this into an answer with the blanks filled in (the reason I haven't is I'm presuming an actual knowledgeable nginx user will be along eventually, but who knows...). – goldilocks Sep 19 '16 at 23:02
  • @goldilocks An actual knowledgeable nginx user came along, but I use Fedora (and 64-bit!) rather than Raspbian. Still, this sounds perfectly reasonable. systemctl enable nginx ought to do it, but only if you install nginx from the repos. It doesn't sound like Question Asker has done that. In that case you'll have to hack the unit file a bit first, to ensure that all the paths are correct. – Michael Hampton Sep 21 '16 at 0:28

Your Answer

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

Browse other questions tagged or ask your own question.