Sha256: 5232cfdc9ed688a0046da10099888dc5fdac37a87a828eb27bddd382dfc2a7a4

Contents?: true

Size: 1.38 KB

Versions: 43

Compression:

Stored size: 1.38 KB

Contents

module Incline
  class CLI
    class Prepare
      
      # create setuid utilities to test the config and reload the config.
      
      UTIL_NGINX_RELOAD = <<-EOU
#include <unistd.h>

int main(int argc, char **argv)
{
  const char *args[] = { "??NG", "-s", "reload", NULL };
  setuid(0);
  execv(args[0], (char **)args);
  return 0;
}
      EOU

      UTIL_NGINX_TEST = <<-EOU
#include <unistd.h>

int main(int argc, char **argv)
{
  const char *args[] = { "??NG", "-t", "-q", NULL };
  setuid(0);
  execv(args[0], (char **)args);
  return 0;
}
      EOU


      private_constant :UTIL_NGINX_RELOAD, :UTIL_NGINX_TEST
      
      private
      
      def create_nginx_utils(shell)
        shell.with_status('Creating utilities') do
          nginx_path = shell.exec("which nginx").split("\n").first.to_s.strip
  
          { 'nginx-reload' => UTIL_NGINX_RELOAD, 'nginx-test' => UTIL_NGINX_TEST }.each do |util,src|
            shell.write_file "#{shell.home_path}/temp-util.c", src.gsub("??NG", nginx_path)
            shell.exec "gcc -o #{shell.home_path}/#{util} #{shell.home_path}/temp-util.c"
            shell.sudo_exec "chown root:root #{shell.home_path}/#{util} && chmod 4755 #{shell.home_path}/#{util}"
            shell.sudo_exec "mv -f #{shell.home_path}/#{util} /usr/local/bin/#{util}"
            shell.exec "rm #{shell.home_path}/temp-util.c"
          end
        end
      end
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
incline-0.3.14 lib/incline/cli/prepare/create_nginx_utils.rb
incline-0.3.13 lib/incline/cli/prepare/create_nginx_utils.rb
incline-0.3.12 lib/incline/cli/prepare/create_nginx_utils.rb
incline-0.3.11 lib/incline/cli/prepare/create_nginx_utils.rb
incline-0.3.10 lib/incline/cli/prepare/create_nginx_utils.rb
incline-0.3.9 lib/incline/cli/prepare/create_nginx_utils.rb
incline-0.3.8 lib/incline/cli/prepare/create_nginx_utils.rb
incline-0.3.7 lib/incline/cli/prepare/create_nginx_utils.rb
incline-0.3.6 lib/incline/cli/prepare/create_nginx_utils.rb
incline-0.3.5 lib/incline/cli/prepare/create_nginx_utils.rb
incline-0.3.4 lib/incline/cli/prepare/create_nginx_utils.rb
incline-0.3.3 lib/incline/cli/prepare/create_nginx_utils.rb
incline-0.3.2 lib/incline/cli/prepare/create_nginx_utils.rb
incline-0.3.1 lib/incline/cli/prepare/create_nginx_utils.rb
incline-0.3.0 lib/incline/cli/prepare/create_nginx_utils.rb
incline-0.2.36 lib/incline/cli/prepare/create_nginx_utils.rb
incline-0.2.35 lib/incline/cli/prepare/create_nginx_utils.rb
incline-0.2.34 lib/incline/cli/prepare/create_nginx_utils.rb
incline-0.2.28 lib/incline/cli/prepare/create_nginx_utils.rb
incline-0.2.27 lib/incline/cli/prepare/create_nginx_utils.rb