OpenResty CentOS 7 Systemd Script

I’ve been slowly getting adjusted to systemd on CentOS 7. OpenResty has been gaining in popularity and I was interested in getting a proper build for CentOS 7.

Below is my systemd service file for OpenResty/nginx, this is based on the default install path /usr/local/openresty Filename: /usr/lib/systemd/system/nginx.service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[Unit]
Description=The nginx HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/openresty/nginx/logs/nginx.pid
ExecStartPre=/usr/local/openresty/nginx/sbin/nginx -t
ExecStart=/usr/local/openresty/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

Then to enable and start the new service

1
2
systemctl enable nginx.service
systemctl start nginx.service

This post may evolve as I work on building an RPM for OpenResty based on the EPEL nginx SRPM package. I should note the majority of the service file above is from the EPEL nginx package.