File tree Expand file tree Collapse file tree 5 files changed +34
-2
lines changed Expand file tree Collapse file tree 5 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -65,7 +65,8 @@ Required fields:
6565 when you want your job to run. Corresponds to the ` OnCalendar ` field of the
6666 systemd timer. See below for helpers to generate common calendar patterns.
6767* ` command ` : The command to run. Corresponds to the ` ExecStart ` field of the
68- systemd service.
68+ systemd service. Specify a Proc to lazily evaluate the command string, useful
69+ for an attribute-driven command.
6970* ` commands ` : The commands to run. Will generate several ` ExecStart ` lines.
7071 Useful if you want to run multiple commands in sequence, without forking to
7172 bash. Mixing ` commands ` and ` command ` will produce a warning, but the
Original file line number Diff line number Diff line change 156156 'command' => '/usr/local/bin/foobar.sh' ,
157157 'timer_options' => { 'OnBootSec' => '1s' } ,
158158 } ,
159+ 'lazy' => {
160+ 'calendar' => '*:0/15:0' ,
161+ 'command' => proc { '/usr/local/bin/foobar.sh' } ,
162+ } ,
159163 }
160164 end
161165 end
Original file line number Diff line number Diff line change 1+ # This file managed by chef.
2+ # Local changes to this file will be overwritten.
3+
4+ [Unit]
5+ Description =Run scheduled task lazy
6+ After =network.target
7+
8+ [Service]
9+ Type =oneshot
10+ Slice =system-timers-lazy.slice
11+ ExecStart =/usr/local/bin/foobar.sh
12+ TimeoutStopSec =90s
Original file line number Diff line number Diff line change 1+ # This file managed by chef.
2+ # Local changes to this file will be overwritten.
3+
4+ [Unit]
5+ Description=Run scheduled task lazy
6+
7+ [Install]
8+ WantedBy=timers.target
9+
10+ [Timer]
11+ OnCalendar=*:0/15:0
12+ AccuracySec=1s
13+ Persistent=false
14+ RandomizedDelaySec=0s
15+ Unit=lazy.service
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ EnvironmentFile=<%= @conf['envfile'] %>
2626Slice=system-timers-<%= @conf['name'] %> .slice
2727<% end %>
2828<% @conf['commands'].each do |command| %>
29- ExecStart=<%= command %>
29+ ExecStart=<%= if command.instance_of?(Proc) then command.call() else command end %>
3030<% end %>
3131<% if @conf['timeout'] %>
3232TimeoutStartSec=<%= @conf['timeout'] %>
You can’t perform that action at this time.
0 commit comments