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

h2o Server::Starter how to use ? #84

Open
centminmod opened this Issue Dec 28, 2014 · 11 comments

Comments

Projects
None yet
3 participants
@centminmod

centminmod commented Dec 28, 2014

Could you add some documentation on how to use Server::Starter or a init.d script to properly start, stop and start h2o on server reboot ?

cheers

@kazuho

This comment has been minimized.

Show comment
Hide comment
@kazuho

kazuho Dec 29, 2014

Member

Server::Starter is a set of superdaemon program (named start_server) and a support library written in Perl, for hot-deploying TCP servers. Suggested reads are:

H2O implements the support-library-side in C by itself. So if you want to run H2O that bounds to 0.0.0.0:80 under Server::Starter, the invocation command would look like:

$ start_server --port=0.0.0.0:80 -- h2o -c h2o.conf

The bind address specified within h2o.conf should match exactly that is defined as part of the argument to start_server, e.g. in the case above, h2o.conf should contain:

listen:
  host: 0.0.0.0
  port: 80

Note that since Server::Starter does not yet support IPv6, it is mandatory to specify the host directive with an IPv4 address in h2o.conf.

Member

kazuho commented Dec 29, 2014

Server::Starter is a set of superdaemon program (named start_server) and a support library written in Perl, for hot-deploying TCP servers. Suggested reads are:

H2O implements the support-library-side in C by itself. So if you want to run H2O that bounds to 0.0.0.0:80 under Server::Starter, the invocation command would look like:

$ start_server --port=0.0.0.0:80 -- h2o -c h2o.conf

The bind address specified within h2o.conf should match exactly that is defined as part of the argument to start_server, e.g. in the case above, h2o.conf should contain:

listen:
  host: 0.0.0.0
  port: 80

Note that since Server::Starter does not yet support IPv6, it is mandatory to specify the host directive with an IPv4 address in h2o.conf.

@kazuho kazuho added the FAQ label Dec 29, 2014

@kazuho

This comment has been minimized.

Show comment
Hide comment
@kazuho

kazuho Dec 29, 2014

Member

Regarding how to install Server::Starter (in case you are not familiar to Perl), the easiest way might be to first install cpanm and then use it to install Server::Starter.

Member

kazuho commented Dec 29, 2014

Regarding how to install Server::Starter (in case you are not familiar to Perl), the easiest way might be to first install cpanm and then use it to install Server::Starter.

@centminmod

This comment has been minimized.

Show comment
Hide comment
@centminmod

centminmod Dec 30, 2014

thanks @kazuho instructions for cpanm etc are helpful. However 2 issues cpanm via https doesn't work probably due to poodle SSLv3 attack and disabling of SSLv3 so used non-http install. But second issue is Server::Starter failed to install via cpanm

Did the following

yum -y install perl-devel perl-CPAN

curl -L https://cpanmin.us | perl - App::cpanminus
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (35) SSL connect error

curl -L http://cpanmin.us | perl - App::cpanminus

cpanm Server::Starter

ended in the following at end

Test Summary Report
-------------------
t/06-autorestart.t (Wstat: 256 Tests: 28 Failed: 1)
  Failed test:  6
  Non-zero exit status: 1
Files=8, Tests=103, 85 wallclock secs ( 0.05 usr  0.03 sys +  2.52 cusr  0.40 csys =  3.00 CPU)
Result: FAIL
Failed 1/8 test programs. 1/103 subtests failed.
make: *** [test_dynamic] Error 255
-> FAIL Installing Server::Starter failed. See /root/.cpanm/work/1419945442.19792/build.log for details. Retry with --force to     force install it.
7 distributions installed

full log posted at https://gist.github.com/centminmod/302638c5791dd274a859

tried --force install and start_server errors when run

start_server --port=0.0.0.0:8080 -- /usr/local/bin/h2o -c /usr/local/h2o/h2o.conf

worker 21581 died unexpectedly with status:19968, restarting
starting new worker 21582
[/usr/local/h2o/h2o.conf:3] in command listen, tcp socket:(null):8080 is not being bound to the server

current h2o.conf based on example template https://github.com/h2o/h2o/blob/master/examples/h2o/h2o.conf

# to find out the configuration commands, run: h2o --help

listen: 8080
max-connections: 10240
http1-request-timeout: 10
limit-request-body: 536870912
http1-upgrade-to-http2: ON
http2-idle-timeout: 10
http2-max-concurrent-requests-per-connection: 16
num-threads: 2
user: nginx
listen:
  port: 8081
  ssl:
    certificate-file: /usr/local/h2o/server.crt
    key-file: /usr/local/h2o/server.key
hosts:
  "0.0.0.0:8080":
    paths:
      /:
        file.dir: /usr/local/nginx/html
    access-log: /usr/local/h2o/logs/access.log
  "alternate.127.0.0.1.xip.io:8081":
    listen:
      port: 8081
      ssl:
        certificate-file: /usr/local/h2o/alternate.crt
        key-file: /usr/local/h2o/alternate.key
    paths:
      /:
        file.dir: /usr/local/nginx/html.alternat

centminmod commented Dec 30, 2014

thanks @kazuho instructions for cpanm etc are helpful. However 2 issues cpanm via https doesn't work probably due to poodle SSLv3 attack and disabling of SSLv3 so used non-http install. But second issue is Server::Starter failed to install via cpanm

Did the following

yum -y install perl-devel perl-CPAN

curl -L https://cpanmin.us | perl - App::cpanminus
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (35) SSL connect error

curl -L http://cpanmin.us | perl - App::cpanminus

cpanm Server::Starter

ended in the following at end

Test Summary Report
-------------------
t/06-autorestart.t (Wstat: 256 Tests: 28 Failed: 1)
  Failed test:  6
  Non-zero exit status: 1
Files=8, Tests=103, 85 wallclock secs ( 0.05 usr  0.03 sys +  2.52 cusr  0.40 csys =  3.00 CPU)
Result: FAIL
Failed 1/8 test programs. 1/103 subtests failed.
make: *** [test_dynamic] Error 255
-> FAIL Installing Server::Starter failed. See /root/.cpanm/work/1419945442.19792/build.log for details. Retry with --force to     force install it.
7 distributions installed

full log posted at https://gist.github.com/centminmod/302638c5791dd274a859

tried --force install and start_server errors when run

start_server --port=0.0.0.0:8080 -- /usr/local/bin/h2o -c /usr/local/h2o/h2o.conf

worker 21581 died unexpectedly with status:19968, restarting
starting new worker 21582
[/usr/local/h2o/h2o.conf:3] in command listen, tcp socket:(null):8080 is not being bound to the server

current h2o.conf based on example template https://github.com/h2o/h2o/blob/master/examples/h2o/h2o.conf

# to find out the configuration commands, run: h2o --help

listen: 8080
max-connections: 10240
http1-request-timeout: 10
limit-request-body: 536870912
http1-upgrade-to-http2: ON
http2-idle-timeout: 10
http2-max-concurrent-requests-per-connection: 16
num-threads: 2
user: nginx
listen:
  port: 8081
  ssl:
    certificate-file: /usr/local/h2o/server.crt
    key-file: /usr/local/h2o/server.key
hosts:
  "0.0.0.0:8080":
    paths:
      /:
        file.dir: /usr/local/nginx/html
    access-log: /usr/local/h2o/logs/access.log
  "alternate.127.0.0.1.xip.io:8081":
    listen:
      port: 8081
      ssl:
        certificate-file: /usr/local/h2o/alternate.crt
        key-file: /usr/local/h2o/alternate.key
    paths:
      /:
        file.dir: /usr/local/nginx/html.alternat
@centminmod

This comment has been minimized.

Show comment
Hide comment
@centminmod

centminmod Dec 30, 2014

with the complexity, might be easier to bundle with h2o it's own init.d/systemd compatibility startup scripts

centminmod commented Dec 30, 2014

with the complexity, might be easier to bundle with h2o it's own init.d/systemd compatibility startup scripts

@kazuho

This comment has been minimized.

Show comment
Hide comment
@kazuho

kazuho Dec 30, 2014

Member

@centminmod

The --port arguments passed to start_server and the listen directives in h2o.conf should match (and only IPv4 is supported by the former while the latter by default tries to bind to both IPv4 and IPv6 addresses unless host is specified).

So if the invocation command is start_server --port=0.0.0.0:8080 then there all the listen directives in h2o.conf should be:

listen:
    host: 0.0.0.0
    port: 8080

The directive may appear more than once in different host-based contexts. They may also have their ssl property set using different key/certificate pairs for each host.

with the complexity, might be easier to bundle with h2o it's own init.d/systemd compatibility startup scripts

Agreed.

Member

kazuho commented Dec 30, 2014

@centminmod

The --port arguments passed to start_server and the listen directives in h2o.conf should match (and only IPv4 is supported by the former while the latter by default tries to bind to both IPv4 and IPv6 addresses unless host is specified).

So if the invocation command is start_server --port=0.0.0.0:8080 then there all the listen directives in h2o.conf should be:

listen:
    host: 0.0.0.0
    port: 8080

The directive may appear more than once in different host-based contexts. They may also have their ssl property set using different key/certificate pairs for each host.

with the complexity, might be easier to bundle with h2o it's own init.d/systemd compatibility startup scripts

Agreed.

@centminmod

This comment has been minimized.

Show comment
Hide comment
@centminmod

centminmod Dec 30, 2014

Does that mean the change i would need made for my example h2o.conf would be changing "alternate.127.0.0.1.xip.io:8081" to "0.0.0.0:8081" ?

# to find out the configuration commands, run: h2o --help

listen: 8080
max-connections: 10240
http1-request-timeout: 10
limit-request-body: 536870912
http1-upgrade-to-http2: ON
http2-idle-timeout: 10
http2-max-concurrent-requests-per-connection: 16
num-threads: 2
user: nginx
listen:
  port: 8081
  ssl:
    certificate-file: /usr/local/h2o/server.crt
    key-file: /usr/local/h2o/server.key
hosts:
  "0.0.0.0:8080":
    paths:
      /:
        file.dir: /usr/local/nginx/html
    access-log: /usr/local/h2o/logs/access.log
  "0.0.0.0:8081":
    listen:
      port: 8081
      ssl:
        certificate-file: /usr/local/h2o/alternate.crt
        key-file: /usr/local/h2o/alternate.key
    paths:
      /:
        file.dir: /usr/local/nginx/html.alternate

centminmod commented Dec 30, 2014

Does that mean the change i would need made for my example h2o.conf would be changing "alternate.127.0.0.1.xip.io:8081" to "0.0.0.0:8081" ?

# to find out the configuration commands, run: h2o --help

listen: 8080
max-connections: 10240
http1-request-timeout: 10
limit-request-body: 536870912
http1-upgrade-to-http2: ON
http2-idle-timeout: 10
http2-max-concurrent-requests-per-connection: 16
num-threads: 2
user: nginx
listen:
  port: 8081
  ssl:
    certificate-file: /usr/local/h2o/server.crt
    key-file: /usr/local/h2o/server.key
hosts:
  "0.0.0.0:8080":
    paths:
      /:
        file.dir: /usr/local/nginx/html
    access-log: /usr/local/h2o/logs/access.log
  "0.0.0.0:8081":
    listen:
      port: 8081
      ssl:
        certificate-file: /usr/local/h2o/alternate.crt
        key-file: /usr/local/h2o/alternate.key
    paths:
      /:
        file.dir: /usr/local/nginx/html.alternate
@kazuho

This comment has been minimized.

Show comment
Hide comment
@kazuho

kazuho Dec 31, 2014

Member

@centminmod

Does that mean the change i would need made for my example h2o.conf would be changing "alternate.127.0.0.1.xip.io:8081" to "0.0.0.0:8081" ?

No. The keys of the host mapping is used for matching the Host: header of HTTP/1 (or the :authority: header of HTTP/2).

It is the listen directive that controls to which ports the server binds. In case of examples/h2o/h2o.conf, tweaks like https://gist.github.com/kazuho/7c634fce977b13c55a98/revisions should be made.

Member

kazuho commented Dec 31, 2014

@centminmod

Does that mean the change i would need made for my example h2o.conf would be changing "alternate.127.0.0.1.xip.io:8081" to "0.0.0.0:8081" ?

No. The keys of the host mapping is used for matching the Host: header of HTTP/1 (or the :authority: header of HTTP/2).

It is the listen directive that controls to which ports the server binds. In case of examples/h2o/h2o.conf, tweaks like https://gist.github.com/kazuho/7c634fce977b13c55a98/revisions should be made.

@centminmod

This comment has been minimized.

Show comment
Hide comment
@centminmod

centminmod Dec 31, 2014

Ah that gist clarifies things alot ... thanks !

so if I understand, my configure should be something like this now for starters ?

# bind all listening ports to "0.0.0.0", so it can start with: start_server --port 0.0.0.0:8080 --port 0.0.0.0:8081 -- /usr/local/bin/h2o -c /usr/local/h2o/h2o.conf

listen:
  host: 0.0.0.0
  port: 8080
max-connections: 10240
http1-request-timeout: 10
limit-request-body: 536870912
http1-upgrade-to-http2: ON
http2-idle-timeout: 10
http2-max-concurrent-requests-per-connection: 16
num-threads: 2
user: nginx
listen:
  host: 0.0.0.0
  port: 8081
  ssl:
    certificate-file: /usr/local/h2o/server.crt
    key-file: /usr/local/h2o/server.key
hosts:
  "0.0.0.0:8080":
    paths:
      /:
        file.dir: /usr/local/nginx/html
    access-log: /usr/local/h2o/logs/access.log
  "alternate.127.0.0.1.xip.io:8081":
    listen:
      host: 0.0.0.0
      port: 8081
      ssl:
        certificate-file: /usr/local/h2o/alternate.crt
        key-file: /usr/local/h2o/alternate.key
    paths:
      /:
        file.dir: /usr/local/nginx/html.alternate
    access-log: /usr/local/h2o/logs/access-alternate.log

centminmod commented Dec 31, 2014

Ah that gist clarifies things alot ... thanks !

so if I understand, my configure should be something like this now for starters ?

# bind all listening ports to "0.0.0.0", so it can start with: start_server --port 0.0.0.0:8080 --port 0.0.0.0:8081 -- /usr/local/bin/h2o -c /usr/local/h2o/h2o.conf

listen:
  host: 0.0.0.0
  port: 8080
max-connections: 10240
http1-request-timeout: 10
limit-request-body: 536870912
http1-upgrade-to-http2: ON
http2-idle-timeout: 10
http2-max-concurrent-requests-per-connection: 16
num-threads: 2
user: nginx
listen:
  host: 0.0.0.0
  port: 8081
  ssl:
    certificate-file: /usr/local/h2o/server.crt
    key-file: /usr/local/h2o/server.key
hosts:
  "0.0.0.0:8080":
    paths:
      /:
        file.dir: /usr/local/nginx/html
    access-log: /usr/local/h2o/logs/access.log
  "alternate.127.0.0.1.xip.io:8081":
    listen:
      host: 0.0.0.0
      port: 8081
      ssl:
        certificate-file: /usr/local/h2o/alternate.crt
        key-file: /usr/local/h2o/alternate.key
    paths:
      /:
        file.dir: /usr/local/nginx/html.alternate
    access-log: /usr/local/h2o/logs/access-alternate.log
@centminmod

This comment has been minimized.

Show comment
Hide comment
@centminmod

centminmod Dec 31, 2014

Just an update seems to work and using --force install for start_server despite the error, seems to work - well I assume it's correct :)

start

start_server --port 0.0.0.0:8080 --port 0.0.0.0:8081 --pid-file=/var/run/h2o.pid --status-file=/usr/local/h2o/h2o_status -- /usr/local/bin/h2o -c /usr/local/h2o/h2o.conf &
[1] 10219

start_server (pid:10219) starting now...
starting new worker 10220
h2o server (pid:10220) is ready to serve requests

restart

start_server --restart --port 0.0.0.0:8080 --port 0.0.0.0:8081 --pid-file=/var/run/h2o.pid --status-file=/usr/local/h2o/h2o_status -- /usr/local/bin/h2o -c /usr/local/h2o/h2o.conf &
[2] 10239
received HUP (num_old_workers=0)
spawning a new worker (num_old_workers=0)
starting new worker 10240
h2o server (pid:10240) is ready to serve requests
new worker is now running, sending TERM to old workers:10220
sleep 0 secs
killing old workers
old worker 10220 died, status:15

Eventually I will be doing comparison benchmarks with Nginx via my Centmin Mod LEMP web stack to see how static file serving fairs and will use http://wordpress7.centminmod.com/ as the test site for it :)

centminmod commented Dec 31, 2014

Just an update seems to work and using --force install for start_server despite the error, seems to work - well I assume it's correct :)

start

start_server --port 0.0.0.0:8080 --port 0.0.0.0:8081 --pid-file=/var/run/h2o.pid --status-file=/usr/local/h2o/h2o_status -- /usr/local/bin/h2o -c /usr/local/h2o/h2o.conf &
[1] 10219

start_server (pid:10219) starting now...
starting new worker 10220
h2o server (pid:10220) is ready to serve requests

restart

start_server --restart --port 0.0.0.0:8080 --port 0.0.0.0:8081 --pid-file=/var/run/h2o.pid --status-file=/usr/local/h2o/h2o_status -- /usr/local/bin/h2o -c /usr/local/h2o/h2o.conf &
[2] 10239
received HUP (num_old_workers=0)
spawning a new worker (num_old_workers=0)
starting new worker 10240
h2o server (pid:10240) is ready to serve requests
new worker is now running, sending TERM to old workers:10220
sleep 0 secs
killing old workers
old worker 10220 died, status:15

Eventually I will be doing comparison benchmarks with Nginx via my Centmin Mod LEMP web stack to see how static file serving fairs and will use http://wordpress7.centminmod.com/ as the test site for it :)

@aboe76

This comment has been minimized.

Show comment
Hide comment
@aboe76

aboe76 Feb 13, 2015

Here is a systemd service file that I hacked together:

what's missing is that h2o write's a pid file or an option to write a pid file.
Something like /run/h2o.pid

[Unit]
Description=h2o optimized HTTP server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=simple
PIDFile=/run/h2o/h2o.pid
WorkingDirectory=/etc/h2o
ExecStart=/usr/bin/h2o -c /etc/h2o/h2o.conf &
ExecReload=/usr/bin/kill -HUP $MAINPID
PrivateDevices=yes
PrivateTmp=true
LimitNOFILE=infinity

[Install]
WantedBy=multi-user.target

systemd example updated by merge #152

aboe76 commented Feb 13, 2015

Here is a systemd service file that I hacked together:

what's missing is that h2o write's a pid file or an option to write a pid file.
Something like /run/h2o.pid

[Unit]
Description=h2o optimized HTTP server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=simple
PIDFile=/run/h2o/h2o.pid
WorkingDirectory=/etc/h2o
ExecStart=/usr/bin/h2o -c /etc/h2o/h2o.conf &
ExecReload=/usr/bin/kill -HUP $MAINPID
PrivateDevices=yes
PrivateTmp=true
LimitNOFILE=infinity

[Install]
WantedBy=multi-user.target

systemd example updated by merge #152

@kazuho kazuho referenced this issue Feb 14, 2015

Closed

pid file #152

@kazuho

This comment has been minimized.

Show comment
Hide comment
@kazuho

kazuho Feb 14, 2015

Member

@aboe76 Great! It is great to know that H2O works well with systemd.

And thank you for the suggestion. I will work on adding a configuration directive for specifying the pid file, which will be tracked in #152.

Member

kazuho commented Feb 14, 2015

@aboe76 Great! It is great to know that H2O works well with systemd.

And thank you for the suggestion. I will work on adding a configuration directive for specifying the pid file, which will be tracked in #152.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment