PageRenderTime 52ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/Library/Formula/lighttpd.rb

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