Skip to content

Instantly share code, notes, and snippets.

@sawanoboly
Last active August 29, 2015 13:59
Show Gist options
  • Select an option

  • Save sawanoboly/10700229 to your computer and use it in GitHub Desktop.

Select an option

Save sawanoboly/10700229 to your computer and use it in GitHub Desktop.
サービス名が不定のデーモンをChefのlazyで遅延処理する ref: http://qiita.com/sawanoboly/items/b7238b97012f2df486cd
# chef-apply test.rb
Recipe: (chef-apply cookbook)::(chef-apply recipe)
* service[test] action nothing (up to date)
* file[/tmp/hoge] action create
- update content in file /tmp/hoge from 2b795c to 04db98
--- /tmp/hoge 2014-04-15 03:13:48.000000000 +0000
+++ /tmp/.hoge20140415-4288-ulgn9f 2014-04-15 03:15:43.000000000 +0000
@@ -1,2 +1,2 @@
-2014-04-15 03:13:48 +0000
+2014-04-15 03:15:43 +0000
* service[test] action restart
- restart service service[test]
cron[4831]: (CRON) INFO (pidfile fd = 3)
cron[4832]: (CRON) STARTUP (fork ok)
##-本来はLibrariesに書く
module ::Helper
def self.get_cron_service_name
## 本当は泥臭い判別処理を記述して、使用できる文字列を返す
'cron'
end
end
## サービス名を実行時に取得するリソース定義
service 'test' do
service_name lazy { ::Helper.get_cron_service_name }
# subscribes :restart, 'file[/tmp/hoge]', :immediately ## subscribesでもOK
end
file '/tmp/hoge' do
content Time.now.to_s
notifies :restart, 'service[test]', :immediately
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment