Skip to content

Instantly share code, notes, and snippets.

@HauptJ
Created June 21, 2018 18:02
Show Gist options
  • Save HauptJ/7adf77da20c65b394ebcbff98ef7d2e8 to your computer and use it in GitHub Desktop.
Save HauptJ/7adf77da20c65b394ebcbff98ef7d2e8 to your computer and use it in GitHub Desktop.

Revisions

  1. HauptJ created this gist Jun 21, 2018.
    31 changes: 31 additions & 0 deletions openresty.service
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    # Stop dance for OpenResty
    # A modification of the Nginx systemd script
    # Source: https://www.digitalocean.com/community/tutorials/how-to-use-the-openresty-web-framework-for-nginx-on-ubuntu-16-04
    # =======================
    #
    # ExecStop sends SIGSTOP (graceful stop) to the Nginx process.
    # If, after 5s (--retry QUIT/5) OpenResty is still running, systemd takes control
    # and sends SIGTERM (fast shutdown) to the main process.
    # After another 5s (TimeoutStopSec=5), and if OpenResty 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=A dynamic web platform based on Nginx and LuaJIT.
    After=network.target

    [Service]
    Type=forking
    PIDFile=/run/openresty.pid
    ExecStartPre=/usr/local/openresty/bin/openresty -t -q -g 'daemon on; master_process on;'
    ExecStart=/usr/local/openresty/bin/openresty -g 'daemon on; master_process on;'
    ExecReload=/usr/local/openresty/bin/openresty -g 'daemon on; master_process on;' -s reload
    ExecReload=/bin/kill -s HUP $MAINPID
    ExecStop=/bin/kill -s QUIT $MAINPID
    TimeoutStopSec=5
    KillMode=mixed

    [Install]
    WantedBy=multi-user.target