Skip to content
This repository has been archived by the owner on May 18, 2021. It is now read-only.

Commit

Permalink
Merge bb3b6e3 into 38b6b5b
Browse files Browse the repository at this point in the history
  • Loading branch information
stephencassidy-r7 committed Jan 17, 2019
2 parents 38b6b5b + bb3b6e3 commit 05beeea
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
20 changes: 14 additions & 6 deletions cookbook/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,19 @@
notifies :restart, 'service[turnstile]' if node['turnstile']['enable']
end

## Upstart Service
template '/etc/init/turnstile.conf' do
source 'upstart.conf.erb'
if Chef::VersionConstraint.new("> 14.04").include?(node['platform_version'])
service_script_path = '/etc/systemd/system/turnstile.service'
service_script = 'systemd.service.erb'
service_provider = Chef::Provider::Service::Systemd
else
service_script_path = '/etc/init/turnstile.conf'
service_script = 'upstart.conf.erb'
service_provider = Chef::Provider::Service::Upstart
end

# Set service script
template service_script_path do
source service_script
variables(
:description => 'turnstile configuration service',
:user => node['turnstile']['user'],
Expand All @@ -59,8 +69,6 @@
"-c #{node['turnstile']['paths']['configuration']}"
]
)

notifies :restart, 'service[turnstile]' if node['turnstile']['enable']
end

directory 'turnstile-configuration-directory' do
Expand All @@ -81,5 +89,5 @@

service 'turnstile' do
action node['turnstile']['enable'] ? [:start, :enable] : [:stop, :disable]
provider Chef::Provider::Service::Upstart
provider service_provider
end
11 changes: 11 additions & 0 deletions cookbook/templates/default/systemd.service.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=<%= @description %>

[Service]
ExecStart=<%= ([@executable] + @flags).join(' ') %>
<% unless @user.nil? %>User=<%= @user %><% end %>
<% unless @group.nil? %>Group=<%= @group %><% end %>
Restart=on-abort

[Install]
WantedBy=multi-user.target

0 comments on commit 05beeea

Please sign in to comment.