Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

systemd units: add template unit for different prefix #143

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions deb/openresty/debian/[email protected]
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions rpm/SOURCES/[email protected]
Original file line number Diff line number Diff line change
@@ -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
7 changes: 5 additions & 2 deletions rpm/SPECS/openresty.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Source0: https://openresty.org/download/openresty-%{version}.tar.gz
%endif

Source1: openresty.service
Source2: openresty.init
Source2: [email protected]
Source3: openresty.init

BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down