Skip to content

Instantly share code, notes, and snippets.

@accasey
Last active October 9, 2018 13:43
Show Gist options
  • Select an option

  • Save accasey/fc839ed993f0f7b2eab34269928fd29f to your computer and use it in GitHub Desktop.

Select an option

Save accasey/fc839ed993f0f7b2eab34269928fd29f to your computer and use it in GitHub Desktop.
Create an Application Server service which uses ruby
LOG_FILE = "d:\\psoft\\config\\appserv\\CMAUAT03\\appserver_win_service.log"
begin
require 'rubygems'
require 'win32\\daemon'
include Win32
class AppServerDomainCMAUAT03Daemon < Daemon
def service_init
10.times{ |i|
File.open(LOG_FILE, 'a'){ |f| f.puts("#{i}") }
sleep 1
}
end
def service_main(*args)
system("d:\\psoft\\pt-8.56.10\\appserv\\psadmin -c start -d CMAUAT03")
# While we're in here the daemon is running.
while running?
if state == RUNNING
sleep 20
else # PAUSED or IDLE
sleep 0.5
end
end
end
# This event triggers when the service receives a signal to stop.
def service_stop
msg = 'Received stop signal at: ' + Time.now.to_s
File.open(LOG_FILE, 'a'){ |f| f.puts msg }
system("d:\\psoft\\pt-8.56.10\\appserv\\psadmin -c stop -d CMAUAT03")
end
# This event triggers when the service receives a signal to pause.
#
def service_pause
msg = 'Received pause signal at: ' + Time.now.to_s
File.open(LOG_FILE, 'a'){ |f| f.puts msg }
end
# This event triggers when the service receives a signal to resume
# from a paused state.
#
def service_resume
msg = 'Received resume signal at: ' + Time.now.to_s
File.open(LOG_FILE, 'a'){ |f| f.puts msg }
end
end
AppServerDomainCMAUAT03Daemon.mainloop
rescue Exception => err
File.open(LOG_FILE, 'a'){ |f|
f.puts "Daemon failure: #{err}"
f.puts "Daemon failure: #{err.backtrace}"
}
raise
end
# The Get-Credential will prompt for username and password.
$credential = Get-Credential
New-Service -BinaryPathName "C:\PROGRA~1\PUPPET~1\Puppet\sys\ruby\bin\ruby.exe d:\psoft\config\appserv\CMAUAT03\appserver_win_service.rb" `
-Name PsftAppServerDomainCMAUAT03Service `
-Credential $credential `
-Description "PeopleSoft AppServer Domain CMAUAT03 Service" `
-DisplayName PsftAppServerDomainCMAUAT03Service `
-StartupType Automatic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment