簡體   English   中英

使用開源 puppet 運行 cmd 命令

[英]Run cmd commands with open source puppet

有人可以幫我處理開源木偶嗎?
我想向 windows 客戶端提供 jar 文件,並使用命令行執行 .jar 文件。
.jar 文件實際上是作為服務運行的應用程序的更新。

我對 puppet 語言不太熟悉,但會猜想這樣來執行 jar 文件:

exec { 'jar_execution':
  command => 'cmd.exe /c java -jar foo.jar',
} 

這應該是清單的一部分,看起來像這樣嗎?

service { 'fooservice':
  name      => foo_service,
  ensure    => running,
  enable    => true,
}

file { 'foo.jar':
  path => 'C:/foo/temp/foo.jar',
  ensure => file,
  source => "puppet:///modules/foo/foo.jar",
} 

exec { 'jar_execution':
  command => 'cmd.exe /c java -jar C:/foor/temp/foo.jar',
} 

代理如何實際運行此命令?

架構方面的考慮很少:

  • 使用archive資源(來自archive模塊)而不是:在模塊的.git歷史記錄中使用.jarfile
  • 讓其他服務(例如 Apache Archiva、Nexus 或 Artifactory 甚至 Puppet Server 本身)提供所有工件(例如二進制文件)。 如果.jar不是由您的公司開發的,您可能需要使用可能帶有一些內部緩存的權威來源。
  • 以對整個基礎架構全局的方式命名您的資源,否則您可能會遇到通知自己並產生不良結果的事件。
  • puppet 中的資源順序無關緊要。 您希望以對您有意義的方式對資源進行排序,並使用beforeafterrequirenotify來確保依賴性。

我建議將二進制文件放在模塊之外,因為不應該對二進制文件進行版本控制。 無論您使用 Puppet OSS 還是 Puppet Enterprise,您可能會有另一個可以提供文件的服務,甚至您的 puppet 基礎設施也可以提供這些包,就像它提供puppet-agent本身一樣。

archive { 'C:/foo/temp/foo.jar':
  source  => https://location/to/your/.jar,
}

exec { 'C:/foo/temp/foo.jar':  # notice in resource name recommended to use / not \
  command     => 'cmd.exe /c java -jar C:/foor/temp/foo.jar',
  refreshonly => true # this one executes exec only if the file was re-downloaded (maybe it's signature has changed), or the file was removed from disk and was re-downloaded.
  onlyif      => 'test -f C:\foo\temp\foo.jar' # or some command that guards you to not run this .jar every time you run puppet
  subscribe   => Archive['C:/foo/temp/foo.jar'],
  notify      => Service['foo_service'] # most probably you need to restart the service after you ran the .jar, otherwise you wouldn't have added in your question.
}

service { 'foo_service':
  ensure    => running,
  enable    => true,
}

我注意到在您的示例中,您不需要在執行后刪除.jar 如果您需要,另一個exec命令可以刪除相同下載的文件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM