<commit_before># Copyright (c) 2013-2014 Irrational Industries Inc. d.b.a. Nitrous.IO
# This software is licensed under the [BSD 2-Clause license](https://raw.github.com/nitrous-io/autoparts/master/LICENSE).

module Autoparts
  module Packages
    class Apache2 < Package
      name 'apache2'
      version '2.4.7-nitrous1'
      description 'Apache Web Server: A cross-platform open-source HTTP server for modern operating systems'
      category Category::WEB_DEVELOPMENT

      source_url 'http://www.us.apache.org/dist//httpd/httpd-2.4.7.tar.gz'
      source_sha1 '9a73783b0f75226fb2afdcadd30ccba77ba05149'
      source_filetype 'tar.gz'

      depends_on 'apr'
      depends_on 'apr_util'

      def compile
        Dir.chdir('httpd-2.4.7') do
          File.open('config.layout', 'a') do |f|
            f.write config_layout_file
          end

          args = [
            "--with-apr=#{get_dependency("apr").prefix_path}",
            "--with-apr-util=#{get_dependency("apr_util").prefix_path}",
            "--enable-layout=Autoparts",
            # features
            "--disable-debug",
            "--disable-dependency-tracking",
            "--enable-so",
            "--enable-ssl",
            "--with-port=3000"
          ]
          execute './configure', *args
          execute 'make'
        end
      end

      def install
        Dir.chdir('httpd-2.4.7') do
          execute 'make install'
        end
      end

      def post_install
        execute 'mkdir', '-p', Path.var + 'apache2' + 'run'
        execute 'mkdir', '-p', Path.var + 'apache2' + 'log'

        # Setup configs.
        if apache_config_path.exist?
          FileUtils.cp apache_config_path, apache_config_path.to_s + "." + Time.now.to_s
        else
          FileUtils.mkdir_p(File.dirname(apache_config_path))
        end
        rewrite_config
        unless user_config_path.exist?
          user_config_path.mkpath
        end

        # Setup mime.types.
        FileUtils.cp '/etc/mime.types', mime_types_path

        # Setup document root.
        execute 'mkdir', '-p', htdocs_path
        if home_workspace_path.directory?
          home_workspace_htdocs_path.make_symlink(htdocs_path) unless home_workspace_htdocs_path.exist?
        end
      end

      def post_uninstall
        home_workspace_htdocs_path.unlink if home_workspace_htdocs_path.symlink?
      end

      def start
        execute bin_path + "apachectl", "start"
      end

      def stop
        execute bin_path + "apachectl", "stop"
      end

      def running?
        pid = Path.var + name + "run" + "httpd.pid"
        pid.exist?
      end

      def tips
        <<-EOS.unindent
          To start the Apache server:
            $ parts start apache2

          To stop the Apache server:
            $ parts stop apache2

          Apache config is located at:
            $ #{apache_config_path}

          Default document root is located at:
            $ #{htdocs_path}
        EOS
      end

      def rewrite_config
        File.open(apache_config_path, 'w') { |f| f.write apache_config }
      end

      def apache_config_path
        Path.etc + name + 'httpd.conf'
      end

      def apache_custom_config_path
        Path.etc + name + 'config'
      end

      def mime_types_path
        Path.etc + name + 'mime.types'
      end

      def htdocs_path
        return @htdocs_path if @htdocs_path
        if home_workspace_path.directory?
          home_workspace_htdocs_path.mkpath unless home_workspace_htdocs_path.exist?
          @htdocs_path = home_workspace_htdocs_path
        else
          @htdocs_path = Path.share + name + 'htdocs'<commit_msg>fixed apache2 not restarting after force quit/reboot<commit_after># Copyright (c) 2013-2014 Irrational Industries Inc. d.b.a. Nitrous.IO
# This software is licensed under the [BSD 2-Clause license](https://raw.github.com/nitrous-io/autoparts/master/LICENSE).

module Autoparts
  module Packages
    class Apache2 < Package
      name 'apache2'
      version '2.4.7-nitrous1'
      description 'Apache Web Server: A cross-platform open-source HTTP server for modern operating systems'
      category Category::WEB_DEVELOPMENT

      source_url 'http://www.us.apache.org/dist//httpd/httpd-2.4.7.tar.gz'
      source_sha1 '9a73783b0f75226fb2afdcadd30ccba77ba05149'
      source_filetype 'tar.gz'

      depends_on 'apr'
      depends_on 'apr_util'

      def compile
        Dir.chdir('httpd-2.4.7') do
          File.open('config.layout', 'a') do |f|
            f.write config_layout_file
          end

          args = [
            "--with-apr=#{get_dependency("apr").prefix_path}",
            "--with-apr-util=#{get_dependency("apr_util").prefix_path}",
            "--enable-layout=Autoparts",
            # features
            "--disable-debug",
            "--disable-dependency-tracking",
            "--enable-so",
            "--enable-ssl",
            "--with-port=3000"
          ]
          execute './configure', *args
          execute 'make'
        end
      end

      def install
        Dir.chdir('httpd-2.4.7') do
          execute 'make install'
        end
      end

      def post_install
        execute 'mkdir', '-p', Path.var + 'apache2' + 'run'
        execute 'mkdir', '-p', Path.var + 'apache2' + 'log'

        # Setup configs.
        if apache_config_path.exist?
          FileUtils.cp apache_config_path, apache_config_path.to_s + "." + Time.now.to_s
        else
          FileUtils.mkdir_p(File.dirname(apache_config_path))
        end
        rewrite_config
        unless user_config_path.exist?
          user_config_path.mkpath
        end

        # Setup mime.types.
        FileUtils.cp '/etc/mime.types', mime_types_path

        # Setup document root.
        execute 'mkdir', '-p', htdocs_path
        if home_workspace_path.directory?
          home_workspace_htdocs_path.make_symlink(htdocs_path) unless home_workspace_htdocs_path.exist?
        end
      end

      def post_uninstall
        home_workspace_htdocs_path.unlink if home_workspace_htdocs_path.symlink?
      end

      def start
        execute bin_path + "apachectl", "start"
      end

      def stop
        execute bin_path + "apachectl", "stop"
      end

      def running?
        if apache_pid_file_path.exist?
          pid = File.read(apache_pid_file_path).strip
          if pid.length > 1 && `ps -o cmd= #{pid}`.include?(httpd_path.basename.to_s)
            return true
          end
        end
        false
      end

      def tips
        <<-EOS.unindent
          To start the Apache server:
            $ parts start apache2

          To stop the Apache server:
            $ parts stop apache2

          Apache config is located at:
            $ #{apache_config_path}

          Default document root is located at:
            $ #{htdocs_path}
        EOS
      end

      def rewrite_config
        File.open(apache_config_path, 'w') { |f| f.write apache_config }
      end

      def apache_config_path
        Path.etc + name + 'httpd.conf'
      end

      def apache_custom_config_path
        Path.etc + name + 'config'
      end

      def mime_types_path
        Path.etc + name + 'mime.types'
      end

      def httpd_path
        bin_path + 'httpd'
      end

      def apache_pid_file_path
        Path.var + name + 'run' + 'httpd.pid'
      end

      def htdocs_path
        return @htdocs_path if @htdocs_path
        if home_workspace_path.directory?
          home_workspace_htdocs_path.mkpath unless home_workspace_htdocs_path.exist?
          @htdocs_path = home_workspace_htdocs_path
        else
          @htdocs_path = Path.share + name + 'htdocs'
{'fraction_non_alphanumeric': 0.09405165666579703, 'fraction_numerical': 0.014609966084007305, 'mean_word_length': 1.910782080485953, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 4, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4419680', 'n_tokens_mistral': 2477, 'n_tokens_neox': 2341, 'n_words': 521}