PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/Library/Formula/lighttpd.rb

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