Chapter 4. Usage and Operations
Understanding how to start and stop the NGINX Unit server, and the applications it runs, is essential. In this chapter, you will learn how to start and stop the Unit service on init.d and systemd service managers, as well as how to start the Unit server in the foreground. This chapter also details how to submit the configuration objects to the Unit control API in order to start serving the application.
4.1 Startup and Shutdown
Problem
You need to start or stop the NGINX Unit server.
Solution
When Unit is installed through a repository, a startup file for a service manager such as init.d or systemd is also installed and configured. These service managers will start Unit as a daemon.
Start Unit on an init.d system:
sudo /etc/init.d/unit start
Stop Unit on an init.d system:
sudo /etc/init.d/unit stop
Start Unit on a systemd system:
sudo systemctl start unit
Stop Unit on a systemd system:
sudo systemctl stop unit
Start Unit in the foreground. The following assumes that the Unit binary is installed into a directory defined in your PATH:
sudo unitd --no-daemon
Discussion
The service manager used to start the Unit daemon depends on the type of system it’s running on. Each service manager has its own syntax for starting and stopping services. The service managers will start Unit as a daemon. An example of starting Unit in the foreground is also shown. This can be useful for testing or when running Unit in a Docker container.