caddyserver / caddy

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
https://caddyserver.com
Apache License 2.0
55.57k stars 3.91k forks source link

running caddy with inetd #374

Closed jungle-boogie closed 8 years ago

jungle-boogie commented 8 years ago

Hello,

panic: runtime error: index out of range

goroutine 1 [running]:
flag.init()
/usr/local/go/src/flag/flag.go:840 +0x11a
 main.init()
/tmp/custombuild_8950_524698905/src/github.com/mholt/caddy/main.go:174 +0x7e

As discussed on the slack channel thing, here's my report for caddy in a panic when using inetd: http://jungleboogie.me:2022/

 caddy2/caddy: ELF 64-bit LSB executable, x86-64, version 1 (FreeBSD), statically linked, not stripped

/etc/services caddy2 2022/tcp # caddy test

/etc/inetd.conf caddy2 stream tcp nowait/5/100 sean /home/sean/bin/caddy2/caddy

I've also tried with:

caddy2 stream tcp nowait.1000 sean /home/sean/bin/caddy2/caddy

with the same results.

Here's the freebsd vagrant machines: https://atlas.hashicorp.com/freebsd/

You could also spin up a DO droplet with freeBSD 10.2-release.

jungle-boogie commented 8 years ago

This is very, very likely a go/caddy problem and not an inetd and/or OS problem.

Fossil-SCM will allow inetd connections: http://www.fossil-scm.org/index.html/doc/trunk/www/server.wiki

This is my inetd.conf config option for fossil:

fossil stream tcp nowait.1000 sean /usr/local/bin/fossil /usr/local/bin/fossil http /home/sean/fossil/fossil.fossil

The above is running on some linux ubuntu like system and I have something very similar with freeBSD, too.

mholt commented 8 years ago

I am suspicious of this line in the standard library, as referenced in the stack trace: https://github.com/golang/go/blob/5dd372bd1e70949a432d9b7b8b021d13abf584d1/src/flag/flag.go#L840

mholt commented 8 years ago

@jungle-boogie Does inetd do anything funny with hyphens when executing the command? The only way I could see your panic happening has to do with these lines... I'd love to know exactly how inetd is running the command. Then we can know for sure if this is a Go bug.

jungle-boogie commented 8 years ago

inetd just launches the service when its called by the specified user.

caddy2 stream tcp nowait.1000 sean /home/sean/bin/caddy2/caddy /home/sean/bin/caddy2/caddy -conf="/home/sean/bin/caddy2/Caddyfile"

When I specify where the Caddyfile, I see this on the site:

2015/12/01 21:40:02 open "/home/sean/bin/caddy2/Caddyfile": no such file or directory

Caddyfile:

jungleboogie.me:2022 {
log access.log
gzip
ext .txt .csv
browse
root /home/sean/site
}

And yes, the caddyfile exists:

% ls -l /home/sean/bin/caddy2/Caddyfile
-rw-r--r--  1 sean  sean  87 Dec  1 21:39 /home/sean/bin/caddy2/Caddyfile
mholt commented 8 years ago

It looks like you have a file called "/home/sean/bin/caddy2/Caddyfile" in the path "/home/sean/bin/caddy2"... at least, when I run ls -l it doesn't usually show me the full path for each filename.

jungle-boogie commented 8 years ago

Hello,

Running inetd with debugging enabled, I see this:

inetd: someone wants caddy2
inetd: accept, ctrl 8
inetd: 52066 execl /home/sean/bin/caddy2/caddy
inetd: handling signal flag C
inetd: 52066 reaped, status 1

If I don't indicate where the caddyfile is, I see just this:

inetd: someone wants caddy2
inetd: accept, ctrl 8
inetd: 52079 execl /home/sean/bin/caddy2/caddy

Startup of caddy2:

ADD : caddy2 proto=tcp accept=1 max=0 user=sean group=(null)class=daemon builtin=0x0  server=/home/sean/bin/caddy2/caddy policy=""
inetd: caddy2/tcp: ipsec initialization failed; in entrust
inetd: caddy2/tcp: ipsec initialization failed; out entrust
inetd: enabling caddy2, fd 6
inetd: registered /home/sean/bin/caddy2/caddy on 6

Accessing my other inetd service, I see the same inetd procedures as reported above.

jungle-boogie commented 8 years ago

Hi @mholt,

I posted about the issue here on freeBSD forums: https://forums.freebsd.org/threads/inetd-app-startup-problem.54235/

Looks like caddy is just not aware of inetd, unfortunately.

I think Go will support inetd based on my cursory search of these things: https://twitter.com/dlsspy/status/167462730838708224 http://uwsgi-docs.readthedocs.org/en/latest/Inetd.html

So this is my plea to consider supporting inetd/xinetd with caddy.

Enabling inetd is much less complex than systemd or writing rc scripts. Caddy will not have to run as root with inetd. This inetd solution is also cross platform (excluding Windows).

here's the man page for inetd: https://www.freebsd.org/cgi/man.cgi?query=inetd&apropos=0&sektion=0&manpath=FreeBSD+10.2-RELEASE&arch=default&format=ascii

moorereason commented 8 years ago

Why aren't you using xinetd? Have you tried that?

jungle-boogie commented 8 years ago

Why aren't you using xinetd? Have you tried that?

No, not yet.

mholt commented 8 years ago

Hmm. SirDice ("Senior UNIX Engineer at Unix Support Nederland") on that forum says:

Besides that inetd(8) is a relic from the past and shouldn't be used at all.

Caddy is a progressive web server, meaning I'm trying to advance newer, future technologies - not older ones. Again, without knowing much about inetd, if it's true that it's getting old, I don't think changing Caddy to support it is within the scope of this project.