diff --git a/deb/openresty/debian/openresty@.service b/deb/openresty/debian/openresty@.service new file mode 100644 index 000000000..a8c7302c7 --- /dev/null +++ b/deb/openresty/debian/openresty@.service @@ -0,0 +1,30 @@ +# Stop dance for OpenResty +# ========================= +# +# ExecStop sends SIGSTOP (graceful stop) to OpenResty's nginx process. +# If, after 5s (--retry QUIT/5) nginx is still running, systemd takes control +# and sends SIGTERM (fast shutdown) to the main process. +# After another 5s (TimeoutStopSec=5), and if nginx is alive, systemd sends +# SIGKILL to all the remaining processes in the process group (KillMode=mixed). +# +# nginx signals reference doc: +# http://nginx.org/en/docs/control.html +# +[Unit] +Description=The OpenResty Application Platform (%f) +After=syslog.target network-online.target remote-fs.target nss-lookup.target +Wants=network-online.target + +[Service] +Type=forking +PIDFile=%f/logs/nginx.pid +ExecStartPre=/usr/local/openresty/nginx/sbin/nginx -t -q -p %f/ -g 'daemon on; master_process on;' +ExecStart=/usr/local/openresty/nginx/sbin/nginx -p %f/ -g 'daemon on; master_process on;' +ExecReload=/usr/local/openresty/nginx/sbin/nginx -p %f/ -g 'daemon on; master_process on;' -s reload +ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile %f/logs/nginx.pid +RuntimeDirectory=openresty-%i +TimeoutStopSec=5 +KillMode=mixed + +[Install] +WantedBy=multi-user.target diff --git a/rpm/SOURCES/openresty@.service b/rpm/SOURCES/openresty@.service new file mode 100644 index 000000000..0fca4f06f --- /dev/null +++ b/rpm/SOURCES/openresty@.service @@ -0,0 +1,18 @@ +[Unit] +Description=The OpenResty Application Platform (%f) +After=syslog.target network-online.target remote-fs.target nss-lookup.target +Wants=network-online.target + +[Service] +Type=forking +PIDFile=%f/logs/nginx.pid +ExecStartPre=/usr/local/openresty/nginx/sbin/nginx -t -p %f/ +ExecStart=/usr/local/openresty/nginx/sbin/nginx -p %f/ +ExecStartPost=/bin/sleep 1 +ExecReload=/bin/kill -s HUP $MAINPID +ExecStop=/bin/kill -s QUIT $MAINPID +RuntimeDirectory=openresty-%i +PrivateTmp=true + +[Install] +WantedBy=multi-user.target diff --git a/rpm/SPECS/openresty.spec b/rpm/SPECS/openresty.spec index dd3f66b47..b3a458b9f 100644 --- a/rpm/SPECS/openresty.spec +++ b/rpm/SPECS/openresty.spec @@ -17,7 +17,8 @@ Source0: https://openresty.org/download/openresty-%{version}.tar.gz %endif Source1: openresty.service -Source2: openresty.init +Source2: openresty@.service +Source3: openresty.init BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) @@ -246,11 +247,12 @@ ln -sf %{orprefix}/nginx/sbin/nginx %{buildroot}/usr/bin/%{name} mkdir -p %{buildroot}%{_unitdir} %{__install} -p -m 0644 %{SOURCE1} %{buildroot}%{_unitdir}/ +%{__install} -p -m 0644 %{SOURCE2} %{buildroot}%{_unitdir}/ %else mkdir -p %{buildroot}/etc/init.d -%{__install} -p -m 0755 %{SOURCE2} %{buildroot}/etc/init.d/%{name} +%{__install} -p -m 0755 %{SOURCE3} %{buildroot}/etc/init.d/%{name} %endif @@ -305,6 +307,7 @@ fi %dir %{orprefix}/nginx/sbin %if 0%{?use_systemd} %{_unitdir}/%{name}.service +%{_unitdir}/%{name}@.service %else /etc/init.d/%{name} %endif