Wednesday, April 25, 2012

quick PuppetMaster Service Script for gem installed puppet set-up

On easy rubygem-way `gem install puppet` installation method for Puppet doesn't get you the *nix platforms service script... so here is one allowing you to perform Start||Stop||Restart||Status service task for puppetmaster.
  • Save the file below as '/etc/init.d/puppetmaster'
    $ sudo curl -L -o /etc/init.d/puppetmaster https://gist.github.com/raw/2479100/15f79c68be3f6f6bf516adf385aac1f29f802a45/gistfile1.rb
  • and turn on its eXecutable bit
    $ sudo chmod +x /etc/init.d/puppetmaster
  • Now you can use it as
    $ service puppetmaster status
PuppetMaster Service Script
#!/usr/bin/env ruby
module PuppetMaster
def self.puppetmaster_cmd
'puppet master --debug --verbose'
end
def self.start
puts "Starting Puppet Master in Debug+Verbose+Daemon mode logging to /var/log/puppet/a.log"
puts "Started." if system("#{puppetmaster_cmd} >> /var/log/puppet/a.log")
end
def self.stop
puppet_master_ps = %x{ps aux | grep -e '#{puppetmaster_cmd}' | grep -v grep}
puppet_master_pid = puppet_master_ps.split[1]
if system("kill -9 #{puppet_master_pid}")
puts "PuppetMaster with pid:#{puppet_master_pid} has been killed."
else
puts "Failure killing PuppetMaster with pid:#{puppet_master_pid}."
end
end
def self.status
puppet_master_ps = %x{ps aux | grep -e '#{puppetmaster_cmd}' | grep -v grep}
puppet_master_pid = puppet_master_ps.split[1]
if puppet_master_pid.nil?
puts "No PuppetMaster found."
else
puts "Running @ #{puppet_master_ps}"
end
end
end
case ARGV.first
when 'start'
PuppetMaster.start
when 'stop'
PuppetMaster.stop
when 'restart'
PuppetMaster.stop
PuppetMaster.start
when 'status'
PuppetMaster.status
else
puts <<-PMUSAGE
$service puppetmaster (start|stop|restart|status)
PMUSAGE
end
view raw gistfile1.rb hosted with ❤ by GitHub