class Lighttpd < Formula desc "Small memory footprint, flexible web-server" homepage "https://www.lighttpd.net/" url "https://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-1.4.38.tar.xz" sha256 "4912568b7befcf3f552ca4668bd7f38cd85f42a22944359d00816ec27eb1e504" bottle do revision 1 sha256 "c88a139e5914a38194eba56154f3472cb6467ef343bc3c0b209f2df3e1e16c9a" => :el_capitan sha256 "aeada1a7d5c027b6716755b1e61a8a3d3dca3617e1f61a8318dc866617f60e3b" => :yosemite sha256 "a4a350a5ec1e2d295db457bfffb6e6ad238140e78d54de761c00002ac2ab759a" => :mavericks end # this patch can be removed with the next release # https://redmine.lighttpd.net/issues/2698 patch do url "https://redmine.lighttpd.net/attachments/download/1671/0001-core-fix-memset_s-call-fixes-2698.patch" sha256 "e04c11ce6ce5a32f1208311671acb7413fbeca5ce3fefa9a0e3121cd920a5cdb" end option "with-lua51", "Include Lua scripting support for mod_magnet" depends_on "pkg-config" => :build depends_on "autoconf" => :build depends_on "automake" => :build depends_on "libtool" => :build depends_on "pcre" depends_on "openssl" depends_on "lua51" => :optional depends_on "libev" => :optional # default max. file descriptors; this option will be ignored if the server is not started as root MAX_FDS = 512 def config_path etc+"lighttpd" end def log_path var+"log/lighttpd" end def www_path var+"www" end def run_path var+"lighttpd" end def install args = %W[ --disable-dependency-tracking --disable-silent-rules --prefix=#{prefix} --sbindir=#{bin} --with-openssl --with-ldap --with-zlib --with-bzip2 --with-attr ] args << "--with-lua" if build.with? "lua51" args << "--with-libev" if build.with? "libev" # autogen must be run, otherwise prebuilt configure may complain # about a version mismatch between included automake and Homebrew's system "./autogen.sh" system "./configure", *args system "make", "install" unless File.exist? config_path config_path.install "doc/config/lighttpd.conf", "doc/config/modules.conf" (config_path/"conf.d/").install Dir["doc/config/conf.d/*.conf"] inreplace config_path+"lighttpd.conf" do |s| s.sub!(/^var\.log_root\s*=\s*".+"$/, "var.log_root = \"#{log_path}\"") s.sub!(/^var\.server_root\s*=\s*".+"$/, "var.server_root = \"#{www_path}\"") s.sub!(/^var\.state_dir\s*=\s*".+"$/, "var.state_dir = \"#{run_path}\"") s.sub!(/^var\.home_dir\s*=\s*".+"$/, "var.home_dir = \"#{run_path}\"") s.sub!(/^var\.conf_dir\s*=\s*".+"$/, "var.conf_dir = \"#{config_path}\"") s.sub!(/^server\.port\s*=\s*80$/, "server.port = 8080") s.sub!(%r{^server\.document-root\s*=\s*server_root \+ "\/htdocs"$}, "server.document-root = server_root") # get rid of "warning: please use server.use-ipv6 only for hostnames, not # without server.bind / empty address; your config will break if the kernel # default for IPV6_V6ONLY changes" s.sub!(/^server.use-ipv6\s*=\s*"enable"$/, 'server.use-ipv6 = "disable"') s.sub!(/^server\.username\s*=\s*".+"$/, 'server.username = "_www"') s.sub!(/^server\.groupname\s*=\s*".+"$/, 'server.groupname = "_www"') s.sub!(/^server\.event-handler\s*=\s*"linux-sysepoll"$/, 'server.event-handler = "select"') s.sub!(/^server\.network-backend\s*=\s*"sendfile"$/, 'server.network-backend = "writev"') # "max-connections == max-fds/2", # https://redmine.lighttpd.net/projects/1/wiki/Server_max-connectionsDetails s.sub!(/^server\.max-connections = .+$/, "server.max-connections = " + (MAX_FDS / 2).to_s) end end log_path.mkpath (www_path/"htdocs").mkpath run_path.mkpath end def caveats; <<-EOS.undent Docroot is: #{www_path} The default port has been set in #{config_path}lighttpd.conf to 8080 so that lighttpd can run without sudo. EOS end test do system "#{bin}/lighttpd", "-t", "-f", config_path+"lighttpd.conf" end plist_options :manual => "lighttpd -f #{HOMEBREW_PREFIX}/etc/lighttpd/lighttpd.conf" def plist; <<-EOS.undent Label #{plist_name} ProgramArguments #{opt_bin}/lighttpd -D -f #{config_path}/lighttpd.conf RunAtLoad KeepAlive WorkingDirectory #{HOMEBREW_PREFIX} StandardErrorPath #{log_path}/output.log StandardOutPath #{log_path}/output.log HardResourceLimits NumberOfFiles #{MAX_FDS} SoftResourceLimits NumberOfFiles #{MAX_FDS} EOS end end