Skip to content

Commit

Permalink
add systemd unit configuration file for the prefork command
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Aug 1, 2016
1 parent 0dc526e commit eed9a2b
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,5 +1,5 @@

7.01 2016-07-31
7.01 2016-08-01
- Improved support for systemd.
- Fixed a bug in Mojo::Server::Prefork where PID files would not contain a
newline character.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -24,7 +24,7 @@
SNI, IDNA, HTTP/SOCKS5 proxy, Comet (long polling), keep-alive, connection
pooling, timeout, cookie, multipart, and gzip compression support.
* Built-in non-blocking I/O web server, supporting multiple event loops as
well as optional preforking and hot deployment, perfect for building
well as optional pre-forking and hot deployment, perfect for building
highly scalable web services.
* JSON and HTML/XML parser with CSS selector support.
* Very clean, portable and object-oriented pure-Perl API with no hidden
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/Server/Hypnotoad.pm
Expand Up @@ -22,7 +22,7 @@ sub configure {
my $c = $prefork->app->config($name) || {};
$self->upgrade_timeout($c->{upgrade_timeout}) if $c->{upgrade_timeout};

# Prefork settings
# Pre-fork settings
$prefork->reverse_proxy($c->{proxy}) if defined $c->{proxy};
$prefork->max_clients($c->{clients}) if $c->{clients};
$prefork->max_requests($c->{requests}) if $c->{requests};
Expand Down Expand Up @@ -161,7 +161,7 @@ Mojo::Server::Hypnotoad - A production web serv...ALL GLORY TO THE HYPNOTOAD!
=head1 DESCRIPTION
L<Mojo::Server::Hypnotoad> is a full featured, UNIX optimized, preforking
L<Mojo::Server::Hypnotoad> is a full featured, UNIX optimized, pre-forking
non-blocking I/O HTTP and WebSocket server, built around the very well tested
and reliable L<Mojo::Server::Prefork>, with IPv6, TLS, SNI, Comet (long
polling), keep-alive, multiple event loop and hot deployment support that just
Expand Down
6 changes: 3 additions & 3 deletions lib/Mojo/Server/Prefork.pm
Expand Up @@ -53,7 +53,7 @@ sub run {
my $self = shift;

# No fork emulation support
say 'Preforking does not support fork emulation.' and exit 0
say 'Pre-forking does not support fork emulation.' and exit 0
if $Config{d_pseudofork};

# Pipe for worker communication
Expand Down Expand Up @@ -195,7 +195,7 @@ sub _wait {
=head1 NAME
Mojo::Server::Prefork - Preforking non-blocking I/O HTTP and WebSocket server
Mojo::Server::Prefork - Pre-forking non-blocking I/O HTTP and WebSocket server
=head1 SYNOPSIS
Expand All @@ -221,7 +221,7 @@ Mojo::Server::Prefork - Preforking non-blocking I/O HTTP and WebSocket server
=head1 DESCRIPTION
L<Mojo::Server::Prefork> is a full featured, UNIX optimized, preforking
L<Mojo::Server::Prefork> is a full featured, UNIX optimized, pre-forking
non-blocking I/O HTTP and WebSocket server, built around the very well tested
and reliable L<Mojo::Server::Daemon>, with IPv6, TLS, SNI, Comet (long polling),
keep-alive and multiple event loop support. Note that the server uses signals
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojolicious/Command/prefork.pm
Expand Up @@ -5,7 +5,7 @@ use Getopt::Long qw(GetOptionsFromArray :config no_auto_abbrev no_ignore_case);
use Mojo::Server::Prefork;

has description =>
'Start application with preforking HTTP and WebSocket server';
'Start application with pre-forking HTTP and WebSocket server';
has usage => sub { shift->extract_usage };

sub run {
Expand Down Expand Up @@ -36,7 +36,7 @@ sub run {
=head1 NAME
Mojolicious::Command::prefork - Prefork command
Mojolicious::Command::prefork - Pre-fork command
=head1 SYNOPSIS
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Commands.pm
Expand Up @@ -233,7 +233,7 @@ embedded in the C<DATA> sections of your application into real files.
$ ./myapp.pl prefork
Use L<Mojolicious::Command::prefork> to start application with standalone
preforking HTTP and WebSocket server.
pre-forking HTTP and WebSocket server.
=head2 psgi
Expand Down
27 changes: 22 additions & 5 deletions lib/Mojolicious/Guides/Cookbook.pod
Expand Up @@ -56,9 +56,11 @@ like this.
[Install]
WantedBy=multi-user.target

On UNIX platforms you can also add preforking and switch to a multi-process
architecture with L<Mojolicious::Command::prefork>, to take advantage of
multiple CPU cores and copy-on-write memory management.
=head2 Pre-forking

On UNIX platforms you can also add pre-forking to the built-in web server and
switch to a multi-process architecture with L<Mojolicious::Command::prefork>, to
take advantage of multiple CPU cores and copy-on-write memory management.

$ ./script/my_app prefork
Server available at http://127.0.0.1:3000
Expand Down Expand Up @@ -86,6 +88,21 @@ whenever a new worker process has been forked and its event loop gets started.

app->start;

And to manage the pre-forking web server with systemd, you can use a unit
configuration file like this.

[Unit]
Description=My Mojolicious application
After=network.target

[Service]
Type=simple
ExecStart=/home/sri/myapp/script/my_app prefork -m production -l http://*:8080
KillMode=process

[Install]
WantedBy=multi-user.target

=head2 Morbo

After reading the L<Mojolicious::Guides::Tutorial>, you should already be
Expand All @@ -104,7 +121,7 @@ script.

=head2 Hypnotoad

For bigger applications L<Mojolicious> contains the UNIX optimized preforking
For bigger applications L<Mojolicious> contains the UNIX optimized pre-forking
web server L<Mojo::Server::Hypnotoad>, which can take advantage of multiple CPU
cores and copy-on-write memory management to scale up to thousands of
concurrent client connections.
Expand All @@ -115,7 +132,7 @@ concurrent client connections.
|- Mojo::Server::Daemon [3]
+- Mojo::Server::Daemon [4]

It is based on the L<Mojo::Server::Prefork> web server, which adds preforking
It is based on the L<Mojo::Server::Prefork> web server, which adds pre-forking
to L<Mojo::Server::Daemon>, but optimized specifically for production
environments out of the box. To start applications with it you can use the
L<hypnotoad> script, which listens on port C<8080>, automatically daemonizes
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Guides/FAQ.pod
Expand Up @@ -252,7 +252,7 @@ be closed immediately.
=head2 What does "Worker 31842 has no heartbeat, restarting" mean?

As long as they are accepting new connections, worker processes of all built-in
preforking web servers send heartbeat messages to the manager process at
pre-forking web servers send heartbeat messages to the manager process at
regular intervals, to signal that they are still responsive. A blocking
operation such as an infinite loop in your application can prevent this, and
will force the affected worker to be restarted after a timeout. This timeout
Expand Down

0 comments on commit eed9a2b

Please sign in to comment.