PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/Library/Formula/lighttpd.rb

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