PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Library/Formula/lighttpd.rb

https://github.com/olekristensen/homebrew
Ruby | 143 lines | 113 code | 21 blank | 9 comment | 2 complexity | 9e7cc0d55f21ce30aa0b08309420fb9c MD5 | raw file
  1. require 'formula'
  2. class Lighttpd < Formula
  3. homepage 'http://www.lighttpd.net/'
  4. url 'http://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-1.4.35.tar.bz2'
  5. sha256 '4a71c1f6d8af41ed894b507720c4c17184dc320590013881d5170ca7f15c5bf7'
  6. bottle do
  7. sha1 "39d57cd89e0b885ce706b4a39fe14a25a33929e9" => :mavericks
  8. sha1 "466c297940904499c24cf92550a0d7d5cc866994" => :mountain_lion
  9. sha1 "13e06e79a8af9406bcd9e9cfc3c6e40e9bfe6045" => :lion
  10. end
  11. option 'with-lua', 'Include Lua scripting support for mod_magnet'
  12. depends_on 'pkg-config' => :build
  13. depends_on 'autoconf' => :build
  14. depends_on 'automake' => :build
  15. depends_on 'libtool' => :build
  16. depends_on 'pcre'
  17. depends_on 'lua' => :optional
  18. depends_on 'libev' => :optional
  19. # default max. file descriptors; this option will be ignored if the server is not started as root
  20. MAX_FDS = 512
  21. def config_path; etc+"lighttpd/"; end
  22. def log_path; var+"log/lighttpd/"; end
  23. def www_path; var+"www/"; end
  24. def run_path; var+"lighttpd/"; end
  25. def install
  26. args = %W[
  27. --disable-dependency-tracking
  28. --prefix=#{prefix}
  29. --with-openssl
  30. --with-ldap
  31. --with-zlib
  32. --with-bzip2
  33. --with-attr
  34. ]
  35. args << "--with-lua" if build.with? 'lua'
  36. args << "--with-libev" if build.with? 'libev'
  37. # fixed upstream, should be in next release: http://redmine.lighttpd.net/issues/2517
  38. inreplace 'src/Makefile.am', '$(LDAP_LIB)', '$(SSL_LIB) $(LDAP_LIB)'
  39. # autogen must be run, otherwise prebuilt configure may complain
  40. # about a version mismatch between included automake and Homebrew's
  41. system "./autogen.sh"
  42. system "./configure", *args
  43. system "make install"
  44. mv sbin, bin
  45. unless File.exist? config_path
  46. config_path.install Dir["doc/config/lighttpd.conf"]
  47. config_path.install Dir["doc/config/modules.conf"]
  48. (config_path/"conf.d/").install Dir["doc/config/conf.d/*.conf"]
  49. inreplace config_path+"lighttpd.conf" do |s|
  50. s.sub!(/^var\.log_root\s*=\s*".+"$/,"var.log_root = \"#{log_path}\"")
  51. s.sub!(/^var\.server_root\s*=\s*".+"$/,"var.server_root = \"#{www_path}\"")
  52. s.sub!(/^var\.state_dir\s*=\s*".+"$/,"var.state_dir = \"#{run_path}\"")
  53. s.sub!(/^var\.home_dir\s*=\s*".+"$/,"var.home_dir = \"#{run_path}\"")
  54. s.sub!(/^var\.conf_dir\s*=\s*".+"$/,"var.conf_dir = \"#{config_path}\"")
  55. s.sub!(/^server\.port\s*=\s*80$/,'server.port = 8080')
  56. s.sub!(/^server\.document-root\s*=\s*server_root + "\/htdocs"$/,'server.document-root = server_root')
  57. # get rid of "warning: please use server.use-ipv6 only for hostnames, not
  58. # without server.bind / empty address; your config will break if the kernel
  59. # default for IPV6_V6ONLY changes" warning
  60. s.sub!(/^server.use-ipv6\s*=\s*"enable"$/,'server.use-ipv6 = "disable"')
  61. s.sub!(/^server\.username\s*=\s*".+"$/,'server.username = "_www"')
  62. s.sub!(/^server\.groupname\s*=\s*".+"$/,'server.groupname = "_www"')
  63. s.sub!(/^server\.event-handler\s*=\s*"linux-sysepoll"$/,'server.event-handler = "select"')
  64. s.sub!(/^server\.network-backend\s*=\s*"linux-sendfile"$/,'server.network-backend = "writev"')
  65. # "max-connections == max-fds/2",
  66. # http://redmine.lighttpd.net/projects/1/wiki/Server_max-connectionsDetails
  67. s.sub!(/^server\.max-connections = .+$/,'server.max-connections = ' + (MAX_FDS / 2).to_s())
  68. end
  69. end
  70. log_path.mkpath
  71. (www_path/'htdocs').mkpath
  72. run_path.mkpath
  73. end
  74. test do
  75. system "#{bin}/lighttpd", '-t', '-f', "#{config_path}lighttpd.conf"
  76. end
  77. def caveats; <<-EOS.undent
  78. Docroot is: #{www_path}
  79. The default port has been set in #{config_path}lighttpd.conf to 8080 so that
  80. lighttpd can run without sudo.
  81. EOS
  82. end
  83. plist_options :manual => "lighttpd -f #{HOMEBREW_PREFIX}/etc/lighttpd/lighttpd.conf"
  84. def plist; <<-EOS.undent
  85. <?xml version="1.0" encoding="UTF-8"?>
  86. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  87. <plist version="1.0">
  88. <dict>
  89. <key>Label</key>
  90. <string>#{plist_name}</string>
  91. <key>ProgramArguments</key>
  92. <array>
  93. <string>#{opt_bin}/lighttpd</string>
  94. <string>-D</string>
  95. <string>-f</string>
  96. <string>#{config_path}lighttpd.conf</string>
  97. </array>
  98. <key>RunAtLoad</key>
  99. <true/>
  100. <key>KeepAlive</key>
  101. <false/>
  102. <key>WorkingDirectory</key>
  103. <string>#{HOMEBREW_PREFIX}</string>
  104. <key>StandardErrorPath</key>
  105. <string>#{log_path}/output.log</string>
  106. <key>StandardOutPath</key>
  107. <string>#{log_path}/output.log</string>
  108. <key>HardResourceLimits</key>
  109. <dict>
  110. <key>NumberOfFiles</key>
  111. <integer>#{MAX_FDS}</integer>
  112. </dict>
  113. <key>SoftResourceLimits</key>
  114. <dict>
  115. <key>NumberOfFiles</key>
  116. <integer>#{MAX_FDS}</integer>
  117. </dict>
  118. </dict>
  119. </plist>
  120. EOS
  121. end
  122. end