PageRenderTime 58ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/Library/Formula/lighttpd.rb

https://github.com/Drarok/homebrew
Ruby | 141 lines | 112 code | 20 blank | 9 comment | 2 complexity | 7faab03212ce5413f552e9d096d7edf7 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. --sbindir=#{bin}
  30. --with-openssl
  31. --with-ldap
  32. --with-zlib
  33. --with-bzip2
  34. --with-attr
  35. ]
  36. args << "--with-lua" if build.with? 'lua'
  37. args << "--with-libev" if build.with? 'libev'
  38. # fixed upstream, should be in next release: http://redmine.lighttpd.net/issues/2517
  39. inreplace 'src/Makefile.am', '$(LDAP_LIB)', '$(SSL_LIB) $(LDAP_LIB)'
  40. # autogen must be run, otherwise prebuilt configure may complain
  41. # about a version mismatch between included automake and Homebrew's
  42. system "./autogen.sh"
  43. system "./configure", *args
  44. system "make install"
  45. unless File.exist? config_path
  46. config_path.install "doc/config/lighttpd.conf", "doc/config/modules.conf"
  47. (config_path/"conf.d/").install Dir["doc/config/conf.d/*.conf"]
  48. inreplace config_path+"lighttpd.conf" do |s|
  49. s.sub!(/^var\.log_root\s*=\s*".+"$/,"var.log_root = \"#{log_path}\"")
  50. s.sub!(/^var\.server_root\s*=\s*".+"$/,"var.server_root = \"#{www_path}\"")
  51. s.sub!(/^var\.state_dir\s*=\s*".+"$/,"var.state_dir = \"#{run_path}\"")
  52. s.sub!(/^var\.home_dir\s*=\s*".+"$/,"var.home_dir = \"#{run_path}\"")
  53. s.sub!(/^var\.conf_dir\s*=\s*".+"$/,"var.conf_dir = \"#{config_path}\"")
  54. s.sub!(/^server\.port\s*=\s*80$/,'server.port = 8080')
  55. s.sub!(/^server\.document-root\s*=\s*server_root + "\/htdocs"$/,'server.document-root = server_root')
  56. # get rid of "warning: please use server.use-ipv6 only for hostnames, not
  57. # without server.bind / empty address; your config will break if the kernel
  58. # default for IPV6_V6ONLY changes" warning
  59. s.sub!(/^server.use-ipv6\s*=\s*"enable"$/,'server.use-ipv6 = "disable"')
  60. s.sub!(/^server\.username\s*=\s*".+"$/,'server.username = "_www"')
  61. s.sub!(/^server\.groupname\s*=\s*".+"$/,'server.groupname = "_www"')
  62. s.sub!(/^server\.event-handler\s*=\s*"linux-sysepoll"$/,'server.event-handler = "select"')
  63. s.sub!(/^server\.network-backend\s*=\s*"linux-sendfile"$/,'server.network-backend = "writev"')
  64. # "max-connections == max-fds/2",
  65. # http://redmine.lighttpd.net/projects/1/wiki/Server_max-connectionsDetails
  66. s.sub!(/^server\.max-connections = .+$/,'server.max-connections = ' + (MAX_FDS / 2).to_s())
  67. end
  68. end
  69. log_path.mkpath
  70. (www_path/'htdocs').mkpath
  71. run_path.mkpath
  72. end
  73. test do
  74. system "#{bin}/lighttpd", '-t', '-f', "#{config_path}lighttpd.conf"
  75. end
  76. def caveats; <<-EOS.undent
  77. Docroot is: #{www_path}
  78. The default port has been set in #{config_path}lighttpd.conf to 8080 so that
  79. lighttpd can run without sudo.
  80. EOS
  81. end
  82. plist_options :manual => "lighttpd -f #{HOMEBREW_PREFIX}/etc/lighttpd/lighttpd.conf"
  83. def plist; <<-EOS.undent
  84. <?xml version="1.0" encoding="UTF-8"?>
  85. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  86. <plist version="1.0">
  87. <dict>
  88. <key>Label</key>
  89. <string>#{plist_name}</string>
  90. <key>ProgramArguments</key>
  91. <array>
  92. <string>#{opt_bin}/lighttpd</string>
  93. <string>-D</string>
  94. <string>-f</string>
  95. <string>#{config_path}lighttpd.conf</string>
  96. </array>
  97. <key>RunAtLoad</key>
  98. <true/>
  99. <key>KeepAlive</key>
  100. <false/>
  101. <key>WorkingDirectory</key>
  102. <string>#{HOMEBREW_PREFIX}</string>
  103. <key>StandardErrorPath</key>
  104. <string>#{log_path}/output.log</string>
  105. <key>StandardOutPath</key>
  106. <string>#{log_path}/output.log</string>
  107. <key>HardResourceLimits</key>
  108. <dict>
  109. <key>NumberOfFiles</key>
  110. <integer>#{MAX_FDS}</integer>
  111. </dict>
  112. <key>SoftResourceLimits</key>
  113. <dict>
  114. <key>NumberOfFiles</key>
  115. <integer>#{MAX_FDS}</integer>
  116. </dict>
  117. </dict>
  118. </plist>
  119. EOS
  120. end
  121. end