* [PATCH] update init and add systemd examples
@ 2016-07-07 1:22 7% Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2016-07-07 1:22 UTC (permalink / raw)
To: yahns-public
Reduce raciness in the init script and add LSB tags.
However, the systemd examples should be race-free and
safer (if one feels safe using systemd :P)
---
examples/init.sh | 43 +++++++++++++++++++++++++++++++++---------
examples/logrotate.conf | 5 +++++
examples/yahns.socket | 17 +++++++++++++++++
examples/yahns@.service | 50 +++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 106 insertions(+), 9 deletions(-)
create mode 100644 examples/yahns.socket
create mode 100644 examples/yahns@.service
diff --git a/examples/init.sh b/examples/init.sh
index 9464220..6fe1ae6 100644
--- a/examples/init.sh
+++ b/examples/init.sh
@@ -2,8 +2,14 @@
# To the extent possible under law, Eric Wong has waived all copyright and
# related or neighboring rights to this examples
set -e
-# Example init script, this can be used with nginx, too,
-# since nginx and yahns accept the same signals
+### BEGIN INIT INFO
+# Provides: yahns
+# Required-Start: $local_fs $network
+# Required-Stop: $local_fs $network
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: Start/stop yahns Ruby app server
+### END INIT INFO
# Feel free to change any of the following variables for your app:
TIMEOUT=${TIMEOUT-60}
@@ -11,21 +17,22 @@ APP_ROOT=/home/x/my_app/current
PID=$APP_ROOT/tmp/pids/yahns.pid
CMD="/usr/bin/yahns -D -c $APP_ROOT/config/yahns.rb"
INIT_CONF=$APP_ROOT/config/init.conf
+UPGRADE_DELAY=${UPGRADE_DELAY-2}
action="$1"
set -u
test -f "$INIT_CONF" && . $INIT_CONF
-old_pid="$PID.oldbin"
+OLD="$PID.oldbin"
cd $APP_ROOT || exit 1
sig () {
- test -s "$PID" && kill -$1 `cat $PID`
+ test -s "$PID" && kill -$1 $(cat $PID)
}
oldsig () {
- test -s $old_pid && kill -$1 `cat $old_pid`
+ test -s "$OLD" && kill -$1 $(cat $OLD)
}
case $action in
@@ -47,18 +54,36 @@ restart|reload)
$CMD
;;
upgrade)
- if sig USR2 && sleep 2 && sig 0 && oldsig QUIT
+ if oldsig 0
+ then
+ echo >&2 "Old upgraded process still running with $OLD"
+ exit 1
+ fi
+
+ cur_pid=
+ if test -s "$PID"
+ then
+ cur_pid=$(cat $PID)
+ fi
+
+ if test -n "$cur_pid" &&
+ kill -USR2 "$cur_pid" &&
+ sleep $UPGRADE_DELAY &&
+ new_pid=$(cat $PID) &&
+ test x"$new_pid" != x"$cur_pid" &&
+ kill -0 "$new_pid" &&
+ kill -QUIT "$cur_pid"
then
n=$TIMEOUT
- while test -s $old_pid && test $n -ge 0
+ while kill -0 "$cur_pid" 2>/dev/null && test $n -ge 0
do
printf '.' && sleep 1 && n=$(( $n - 1 ))
done
echo
- if test $n -lt 0 && test -s $old_pid
+ if test $n -lt 0 && kill -0 "$cur_pid" 2>/dev/null
then
- echo >&2 "$old_pid still exists after $TIMEOUT seconds"
+ echo >&2 "$cur_pid still running after $TIMEOUT seconds"
exit 1
fi
exit 0
diff --git a/examples/logrotate.conf b/examples/logrotate.conf
index ebc92a5..b0d1351 100644
--- a/examples/logrotate.conf
+++ b/examples/logrotate.conf
@@ -25,6 +25,11 @@
# config. yahns supports the USR1 signal and we send it
# as our "lastaction" action:
lastaction
+ # systemd users do not have PID files,
+ # only signal the @1 process since the @2 is short-lived
+ # and only runs while @1 is restarting.
+ systemctl kill -s SIGUSR1 yahns@1.service
+
# assuming your pid file is in /var/run/yahns_app/pid
pid=/var/run/yahns_app/pid
test -s $pid && kill -USR1 "$(cat $pid)"
diff --git a/examples/yahns.socket b/examples/yahns.socket
new file mode 100644
index 0000000..6455b41
--- /dev/null
+++ b/examples/yahns.socket
@@ -0,0 +1,17 @@
+# ==> /etc/systemd/system/yahns.socket <==
+[Unit]
+Description = yahns sockets
+
+[Socket]
+
+# yahns can handle an arbitrary number of listen sockets,
+# so I prefer to keep listeners for IPv4 and IPv6 separate
+# to avoid ugly IPv4-mapped-IPv6 addresses for IPv4 clients:
+# (e.g ":ffff:10.0.0.1" instead of just "10.0.0.1").
+ListenStream = 0.0.0.0:443
+BindIPv6Only = ipv6-only
+ListenStream = [::]:443
+Service = yahns@1.service
+
+[Install]
+WantedBy = sockets.target
diff --git a/examples/yahns@.service b/examples/yahns@.service
new file mode 100644
index 0000000..1ee010f
--- /dev/null
+++ b/examples/yahns@.service
@@ -0,0 +1,50 @@
+# ==> /etc/systemd/system/yahns@.service <==
+# Since SIGUSR2 upgrades do not work under systemd, this service
+# file allows starting two (or more) simultaneous services
+# during upgrade (e.g. yahns@1 and yahns@2) with the intention
+# that they are both running during the upgrade process.
+#
+# This allows upgrading without downtime, using yahns@2 as a
+# temporary hot spare:
+#
+# systemctl start yahns@2
+# sleep 2 # wait for yahns@2 to boot, increase as necessary for big apps
+# systemctl restart yahns@1
+# sleep 2 # wait for yahns@1 to warmup
+# systemctl stop yahns@2
+
+[Unit]
+Description = yahns Ruby server %i
+Wants = yahns.socket
+After = yahns.socket
+
+[Service]
+# yahns can handle lots of open files:
+LimitNOFILE = 32768
+LimitCORE = infinity
+
+# The listen socket we give yahns should be blocking for optimal
+# load distribution between processes under the Linux kernel.
+# NonBlocking is false by default in systemd, but we specify it
+# here anyways to discourage users from blindly changing it.
+Sockets = yahns.socket
+NonBlocking = false
+
+# bundler users must use the "--keep-file-descriptors" switch, here:
+# ExecStart = /path/to/bin/bundle exec --keep-file-descriptors yahns -c ...
+ExecStart = /path/to/bin/yahns -c /path/to/yahns.conf.rb
+KillSignal = SIGQUIT
+User = www-data
+Group = www-data
+ExecReload = /bin/kill -HUP $MAINPID
+
+# this should match the shutdown_timeout value in yahns_config(5)
+TimeoutStopSec = 600
+
+# Only kill the master process, it may be harmful to signal
+# workers via default "control-group" setting since some
+# Ruby extensions and applications misbehave on interrupts
+KillMode = process
+
+[Install]
+WantedBy = multi-user.target
--
EW
^ permalink raw reply related [relevance 7%]
* [ANN] yahns 1.13.0 -_- sleepy app server for Ruby
@ 2016-08-05 7:44 6% Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2016-08-05 7:44 UTC (permalink / raw)
To: ruby-talk; +Cc: yahns-public
A Free Software, multi-threaded, non-blocking network
application server designed for low _idle_ power consumption.
It is primarily optimized for applications with occasional users
which see little or no traffic. yahns currently hosts Rack/HTTP
applications, but may eventually support other application
types. Unlike some existing servers, yahns is extremely
sensitive to fatal bugs in the applications it hosts.
* git clone git://yhbt.net/yahns
* https://yahns.yhbt.net/README
* https://yahns.yhbt.net/NEWS.atom.xml
* we only accept plain-text email yahns-public@yhbt.net
* and archive all the mail we receive: https://yhbt.net/yahns-public/
* nntp://news.public-inbox.org/inbox.comp.lang.ruby.yahns
lrg nabgure ubeevoyl-anzrq freire :>
Changes:
yahns 1.13.0 - some user-visible improvements...
And probably a billion new regressions!
yahns now allows users to skip the Rack::Head, Rack::Chunked and
Rack::ContentLength middlewares to ease migrating from/to other
real-world Rack HTTP servers. Most notably, our chunked
encoding implementation is a bit faster than Rack::Chunked by
taking advantage of the writev(2) syscall:
https://yhbt.net/yahns-public/20160803031906.14553-4-e@80x24.org/
There's also rack 2.x fixes in the test case and extras/ section
(these incompatibilities did not affect existing users unless
they use the wonky extras/ section).
There's also some graceful shutdown fixes, the process title is
now changed to display the number of live FDs.
Of course, there's the usual round of documentation improvements
which are systemd and OpenSSL setup-related this time around.
However, the majority of changes (proxy_*, wbuf_lite), affect
currently-unadvertised functionality which is subject to removal
or incompatible config changes. However, they are used to serve
our mailing list archives at:
https://yhbt.net/yahns-public/
49 changes since yahns 1.12.5:
proxy_pass: simplify writing request bodies upstream
proxy_pass: hoist out proxy_res_headers method
proxy_pass: simplify proxy_http_response
proxy_pass: split out body and trailer reading in response
proxy_pass: trim down proxy_response_finish, too
proxy_pass: split out req_res into a separate file
proxy_pass: fix resumes after complete buffering is unblocked
proxy_pass: X-Forwarded-For appends to existing list
proxy_pass: pass entire object to proxy_http_response
proxy_pass: support "proxy_buffering: false"
proxy_pass: remove unnecessary rescue
req_res: store proxy_pass object here, instead
proxy_pass: redo "proxy_buffering: false"
wbuf: remove needless "busy" parameter
Merge branch 'maint'
extras/try_gzip_static: do not show backtrace on syscall errors
wbuf: remove tmpdir parameter
wbuf_lite: fix write retries for OpenSSL sockets
test_proxy_pass_no_buffering: fix racy test
queue_*: check for closed IO objects
cleanup graceful shutdown handling
proxy_pass: more descriptive error messages
proxy_pass: fix HTTP/1.0 backends on EOF w/o buffering
wbuf_common: reset offset counter when done
extras/try_gzip_static: resolve symlinks
test_ssl: remove unnecessary priv_key DH parameter
openssl_client: wrap shutdown for graceful termination
proxy_pass: keep trailer buffer on blocked client writes
proxy_pass: avoid TOCTTOU race when unbuffering, too
proxy_pass: avoid accessing logger in env after hijacking
proxy_pass: avoid stuck responses in "proxy_buffering: false"
extras: include status messages in responses
update init and add systemd examples
test_proxy_pass_no_buffering: exclude rb/ru files, too
wbuf_lite: use StringIO instead of TmpIO
wbuf_lite: truncate StringIO when done
wbuf_lite: prevent clobbering responses
wbuf_lite: unify EOF error handling
wbuf_lite: reset sf_offset/sf_count consistently
wbuf_lite: clear @busy flag when re-arming
http_response: drop bodies for non-compliant responses
fix rack 2.x compatibility bugs
doc: add session cache usage to OpenSSL example
test: skip some buffering tests on non-default values
response: drop clients after HTTP responses of unknown length
response: reduce stack overhead for parameter passing
response: support auto-chunking for HTTP/1.1
Revert "document Rack::Chunked/ContentLength semi-requirements"
extras/exec_cgi: fix for HTTPoxy vulnerability
Please note the disclaimer:
yahns is extremely sensitive to fatal bugs in the apps it hosts. There
is no (and never will be) any built-in "watchdog"-type feature to kill
stuck processes/threads. Each yahns process may be handling thousands
of clients; unexpectedly killing the process will abort _all_ of those
connections. Lives may be lost!
yahns hackers are not responsible for your application/library bugs.
Use an application server which is tolerant of buggy applications
if you cannot be bothered to fix all your fatal bugs.
--
EW
^ permalink raw reply [relevance 6%]
Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2016-07-07 1:22 7% [PATCH] update init and add systemd examples Eric Wong
2016-08-05 7:44 6% [ANN] yahns 1.13.0 -_- sleepy app server for Ruby Eric Wong
Code repositories for project(s) associated with this public inbox
https://yhbt.net/yahns.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).