Skip to content

Instantly share code, notes, and snippets.

@fnando
Created December 23, 2012 21:25
Show Gist options
  • Save fnando/4366250 to your computer and use it in GitHub Desktop.
Save fnando/4366250 to your computer and use it in GitHub Desktop.
class apt-get::update {
exec { "apt-get update":
command => "apt-get update"
}
}
import "apt-get"
class nginx {
include apt-get::update
exec { "nginx:import-gpg-key":
command => "wget -q -O - http://nginx.org/keys/nginx_signing.key | sudo apt-key add -",
}
exec { "nginx:add-repo":
command => "echo 'deb http://nginx.org/packages/ubuntu/ precise nginx' | sudo tee /etc/apt/sources.list.d/nginx.list",
require => Exec["nginx:import-gpg-key"],
}
file { "nginx:source.list":
ensure => file,
path => "/etc/apt/sources.list.d/nginx.list",
content => "deb http://nginx.org/packages/ubuntu/ precise nginx",
require => Exec["nginx:add-repo"],
owner => "root",
group => "root",
}
package { "nginx":
ensure => installed,
require => [File["nginx:source.list"], Exec["apt-get update"]],
}
file { "/etc/nginx/conf.d/default":
ensure => absent,
require => Package["nginx"],
}
file { "/etc/nginx/nginx.conf":
ensure => file,
content => template("nginx/nginx.conf.erb"),
require => Package["nginx"],
owner => "root",
group => "root",
}
file { "/etc/nginx/sites-enabled":
ensure => absent,
recurse => true,
force => true,
require => Package["nginx"],
}
file { "/etc/nginx/sites-available":
ensure => absent,
recurse => true,
force => true,
require => Package["nginx"],
}
file { "/var/www":
ensure => directory,
owner => "www-data",
group => "www-data",
mode => "0770",
}
file { "/etc/nginx/ssl":
ensure => directory,
owner => "root",
group => "root",
mode => "0700",
require => Package["nginx"]
}
exec { "nginx:test":
command => "nginx -t",
require => File["/etc/nginx/nginx.conf"],
}
service { "nginx":
ensure => running,
enable => true,
hasrestart => true,
hasstatus => true,
subscribe => File["/etc/nginx/nginx.conf"],
require => Exec["nginx:restart"],
}
exec { "nginx:restart":
command => "/etc/init.d/nginx restart",
require => Exec["nginx:test"],
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment