Commit 9c29795e by source_reader

added more nginx configs and hostapd tools

parent 5498d8c2
All data collected by Joule is stored in a Postgresql database. If you
think this system may loose power unexpectedly you should enable data
journaling. Creating a separate partition or using a secondary storage
volume for the database will prevent the system from running out of
memory if the database fills up and also makes it easier to collect
data from persistent instllations.
-------------------
# Enable data journaling
Edit /etc/fstab to add data=journal to the mount options
Adding noatime as well should reduce the speed impact. The last two
fields should be 0 and 2 for a second partition or drive.
**If this is the root volume you must enable it on the drive as well**
$> sudo tune2fs -o journal_data_writeback /dev/DEVCIE
-----------------
# Change data directory
To view the postgresql data directory and config file run:
$> sudo -u postgres psql -c "show data_directory"
$> sudo -u postgres psql -c "show config_file"
1.) Stop postgres
$> sudo service postgresql stop
2.) Copy the data directory to the new location
Note the copy is at the "postgresql" level, this preserves
permissions within the directory tree for compatability with future
upgrades to the package:
$> sudo rsync -av /var/lib/postgresql /new/data/dir
3.) Rename the old dir in case we want to revert
$> sudo mv /var/lib/postgresql/X.X/main /var/lib/postgresql/X.X/main.bak
4.) Edit the configuration file to point to the new directory
usually /etc/postgresql/X.X/main/postgresql.conf:
data_directory = '/new/data/dir/X.X/main'
5.) Restart postgres:
$> sudo service postgres restart
6.) Confirm new data directory:
$> sudo -u postgres psql -c "show data_directory"
---------JOIN A NETWORK -------------
To join an existing network either use raspi-config or
1.) Add to the end /etc/wpa_supplicant/wpa_supplicant.conf
network={
ssid="testing"
psk="testingPassword"
}
2.) Reconfigure the interface with
$> wpa_cli -i wlan0 reconfigure
--------CREATE A NETWORK --------------
This system can run as a standalone wireless access point (AP)
1.) Configure /etc/hostapd/hostapd.conf with:
* SSID
* Password
2.) Uncomment the ###HOSTAPD### section in /etc/dhcpcd.conf
2.) Enable both hostapd and dnsmasq:
$> sudo systemctl enable dnsmasq
$> sudo sysetmctl unmask hostapd
$> sudo systemctl enable hostapd
3.)
Either reboot, or start services manually:
$> sudo systemctl start dnsmasq
$> sudo systemctl start hostapd
source ENV['GEM_SOURCE'] || 'https://rubygems.org'
puppetversion = ENV.key?('PUPPET_VERSION') ? ENV['PUPPET_VERSION'] : ['>= 3.3']
gem 'metadata-json-lint'
gem 'puppet', puppetversion
gem 'puppetlabs_spec_helper', '>= 1.2.0'
gem 'puppet-lint', '>= 1.0.0'
gem 'facter', '>= 1.7.0'
gem 'rspec-puppet'
# rspec must be v2 for ruby 1.8.7
if RUBY_VERSION >= '1.8.7' && RUBY_VERSION < '1.9'
gem 'rspec', '~> 2.0'
gem 'rake', '~> 10.0'
else
# rubocop requires ruby >= 1.9
gem 'rubocop'
end
# hostapd
#### Table of Contents
1. [Description](#description)
1. [Setup - The basics of getting started with hostapd](#setup)
* [What hostapd affects](#what-hostapd-affects)
* [Setup requirements](#setup-requirements)
* [Beginning with hostapd](#beginning-with-hostapd)
1. [Usage - Configuration options and additional functionality](#usage)
1. [Reference - An under-the-hood peek at what the module is doing and how](#reference)
1. [Limitations - OS compatibility, etc.](#limitations)
1. [Development - Guide for contributing to the module](#development)
## Description
Start with a one- or two-sentence summary of what the module does and/or what
problem it solves. This is your 30-second elevator pitch for your module.
Consider including OS/Puppet version it works with.
You can give more descriptive information in a second paragraph. This paragraph
should answer the questions: "What does this module *do*?" and "Why would I use
it?" If your module has a range of functionality (installation, configuration,
management, etc.), this is the time to mention it.
## Setup
### What hostapd affects **OPTIONAL**
If it's obvious what your module touches, you can skip this section. For
example, folks can probably figure out that your mysql_instance module affects
their MySQL instances.
If there's more that they should know about, though, this is the place to mention:
* A list of files, packages, services, or operations that the module will alter,
impact, or execute.
* Dependencies that your module automatically installs.
* Warnings or other important notices.
### Setup Requirements **OPTIONAL**
If your module requires anything extra before setting up (pluginsync enabled,
etc.), mention it here.
If your most recent release breaks compatibility or requires particular steps
for upgrading, you might want to include an additional "Upgrading" section
here.
### Beginning with hostapd
The very basic steps needed for a user to get the module up and running. This
can include setup steps, if necessary, or it can be an example of the most
basic use of the module.
## Usage
This section is where you describe how to customize, configure, and do the
fancy stuff with your module here. It's especially helpful if you include usage
examples and code samples for doing things with your module.
## Reference
Users need a complete list of your module's classes, types, defined types providers, facts, and functions, along with the parameters for each. You can provide this list either via Puppet Strings code comments or as a complete list in this Reference section.
* If you are using Puppet Strings code comments, this Reference section should include Strings information so that your users know how to access your documentation.
* If you are not using Puppet Strings, include a list of all of your classes, defined types, and so on, along with their parameters. Each element in this listing should include:
* The data type, if applicable.
* A description of what the element does.
* Valid values, if the data type doesn't make it obvious.
* Default value, if any.
## Limitations
This is where you list OS compatibility, version compatibility, etc. If there
are Known Issues, you might want to include them under their own heading here.
## Development
Since your module is awesome, other users will want to play with it. Let them
know what the ground rules for contributing are.
## Release Notes/Contributors/Etc. **Optional**
If you aren't using changelog, put your release notes here (though you should
consider using changelog). You can also add any additional sections you feel
are necessary or important to include here. Please use the `## ` header.
require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet-lint/tasks/puppet-lint'
require 'metadata-json-lint/rake_task'
if RUBY_VERSION >= '1.9'
require 'rubocop/rake_task'
RuboCop::RakeTask.new
end
PuppetLint.configuration.send('disable_80chars')
PuppetLint.configuration.relative = true
PuppetLint.configuration.ignore_paths = ['spec/**/*.pp', 'pkg/**/*.pp']
desc 'Validate manifests, templates, and ruby files'
task :validate do
Dir['manifests/**/*.pp'].each do |manifest|
sh "puppet parser validate --noop #{manifest}"
end
Dir['spec/**/*.rb', 'lib/**/*.rb'].each do |ruby_file|
sh "ruby -c #{ruby_file}" unless ruby_file =~ %r{spec/fixtures}
end
Dir['templates/**/*.erb'].each do |template|
sh "erb -P -x -T '-' #{template} | ruby -c"
end
end
desc 'Run lint, validate, and spec tests.'
task :test do
[:lint, :validate, :spec].each do |test|
Rake::Task[test].invoke
end
end
# The baseline for module testing used by Puppet Inc. is that each manifest
# should have a corresponding test manifest that declares that class or defined
# type.
#
# Tests are then run by using puppet apply --noop (to check for compilation
# errors and view a log of events) or by fully applying the test in a virtual
# environment (to compare the resulting system state to the desired state).
#
# Learn more about module testing here:
# https://docs.puppet.com/guides/tests_smoke.html
#
include ::hostapd
# A sample configuration for dhcpcd.
# See dhcpcd.conf(5) for details.
# Allow users of this group to interact with dhcpcd via the control socket.
#controlgroup wheel
# Inform the DHCP server of our hostname for DDNS.
hostname
# Use the hardware address of the interface for the Client ID.
clientid
# or
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
# Some non-RFC compliant DHCP servers do not reply with this set.
# In this case, comment out duid and enable clientid above.
#duid
# Persist interface configuration when dhcpcd exits.
persistent
# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit
# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Respect the network MTU. This is applied to DHCP routes.
option interface_mtu
# Most distributions have NTP support.
#option ntp_servers
# A ServerID is required by RFC2131.
require dhcp_server_identifier
# Generate SLAAC address using the Hardware Address of the interface
#slaac hwaddr
# OR generate Stable Private IPv6 Addresses based from the DUID
slaac private
##### BEGIN HOSTAPD SECTION #####
# interface wlan0
# static ip_address=192.168.1.1/24
##### END HOSTAPD SECTION ####
# It is possible to fall back to a static IP if DHCP fails:
# define static profile
profile static_eth0
static ip_address=192.168.2.200
static routers=192.168.2.1
# fallback to static profile on eth0
interface eth0
fallback static_eth0
interface=wlan0
dhcp-range=192.168.1.100,192.168.1.150,12h
# Delays sending DHCPOFFER and proxydhcp replies for at least the specified number of seconds.
dhcp-mac=set:client_is_a_pi,B8:27:EB:*:*:*
dhcp-reply-delay=tag:client_is_a_pi,2
### CHANGE THESE VALUES ###
ssid=wattsworth
wpa_passphrase=topsecret
###########################
country_code=US
interface=wlan0
driver=nl80211
wpa=2
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
macaddr_acl=0
logger_syslog=0
logger_syslog_level=4
logger_stdout=-1
logger_stdout_level=0
hw_mode=a
wmm_enabled=1
# N
ieee80211n=1
require_ht=1
ht_capab=[MAX-AMSDU-3839][HT40+][SHORT-GI-20][SHORT-GI-40][DSSS_CCK-40]
# AC
ieee80211ac=1
require_vht=1
ieee80211d=0
ieee80211h=0
vht_capab=[MAX-AMSDU-3839][SHORT-GI-80]
vht_oper_chwidth=1
channel=36
vht_oper_centr_freq_seg0_idx=42
\ No newline at end of file
class hostapd::config{
notice("including hostapd config")
file {'/etc/hostapd/hostapd.conf':
owner => root,
group => root,
source => 'puppet:///modules/hostapd/pi/hostapd.conf'
}
file {'/etc/dnsmasq.conf':
owner => root,
group => root,
source => 'puppet:///modules/hostapd/pi/dnsmasq.conf'
}
file{'/etc/dhcpcd.conf':
owner => root,
group => root,
source => 'puppet:///modules/hostapd/pi/dhcpcd.conf'
}
}
# Class: hostapd
# ===========================
#
# Provide packages and config files for access point
# Do not start the access point
#
#
class hostapd {
contain hostapd::install
contain hostapd::config
contain hostapd::service
Class['::hostapd::install']
-> Class['::hostapd::config']
~> Class['::hostapd::service']
}
class hostapd::install{
notice("including hostapd install")
package{'hostapd':
ensure => present
}
package{'dnsmasq':
ensure => present
}
}
class hostapd::service{
notice("including hostapd service")
service{'hostapd':
enable => false,
ensure => stopped,
}
service{'dnsmasq':
enable => false,
ensure => stopped
}
}
{
"name": "jdonnal-hostapd",
"version": "0.1.0",
"author": "jdonnal",
"summary": null,
"license": "Apache-2.0",
"source": "",
"project_page": null,
"issues_url": null,
"dependencies": [
{
"name": "puppetlabs-stdlib",
"version_requirement": ">= 1.0.0"
}
],
"data_provider": null
}
require 'spec_helper'
describe 'hostapd' do
context 'with default values for all parameters' do
it { should contain_class('hostapd') }
end
end
require 'puppetlabs_spec_helper/module_spec_helper'
# Joule API
location /joule/ {
proxy_pass http://unix:/tmp/joule/api:/;
proxy_set_header X-Auth-Required "true";
proxy_set_header X-Api-Port "443";
proxy_set_header X-Api-Scheme "https";
proxy_set_header X-Api-Base-Uri "/joule";
}
# Do not proxy this path
# This route lists all active data apps
location /joule/app.json {
proxy_pass http://unix:/tmp/joule/api:/app.json;
proxy_set_header X-Auth-Required "true";
}
# Reverse proxy for data apps
location /joule/app {
auth_request /proxy;
auth_request_set $proxy_url $upstream_http_x_proxy_path;
proxy_pass $proxy_url$joule_proxy_uri?$args;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
# Proxy authorization
location = /proxy {
internal;
proxy_pass http://unix:/tmp/joule/api:/app/auth;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-App-Id $joule_proxy_id;
proxy_set_header X-Auth-Required "true";
}
# Lumen API
location /lumen/ {
proxy_pass http://unix:/tmp/joule/api:/;
proxy_set_header X-Auth-Required "true";
}
map $request_uri $joule_proxy_id {
"~^/joule/app/(?<id>[m|p]\d*)/(?<path>.*)$" $id;
default "";
}
map $uri $joule_proxy_uri {
"~^/joule/app/[m|p]\d*/(?<path>.*)$" $path;
default "";
}
map $uri $lumen_proxy_id {
"~^/app/(?<id>\d*)" $id; #/(?<path>.*)$" $id;
default "";
}
map $uri $lumen_proxy_uri {
"~^/app/(?<id>\d*)/(?<path>.*)$" $path;
default "";
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server{
listen 80;
root /var/www/frontend;
# Help documentation
location /docs {
root /var/www;
}
# Lumen frontend
location / {
root /var/www/frontend;
try_files $uri $uri/ /index.html;
}
# Lumen backend (on Passenger)
......@@ -65,49 +41,3 @@ server{
proxy_set_header Content-Length "";
proxy_set_header X-Original-URI $request_uri;
}
}
server{
listen 443;
# Joule API
location /joule/ {
proxy_pass http://unix:/tmp/joule/api:/;
proxy_set_header X-Auth-Required "true";
proxy_set_header X-Api-Port "443";
proxy_set_header X-Api-Scheme "https";
proxy_set_header X-Api-Base-Uri "/joule";
}
# Do not proxy this path
# This route lists all active data apps
location /joule/app.json {
proxy_pass http://unix:/tmp/joule/api:/app.json;
proxy_set_header X-Auth-Required "true";
}
# Reverse proxy for data apps
location /joule/app {
auth_request /proxy;
auth_request_set $proxy_url $upstream_http_x_proxy_path;
proxy_pass $proxy_url$joule_proxy_uri?$args;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
# Proxy authorization
location = /proxy {
internal;
proxy_pass http://unix:/tmp/joule/api:/app/auth;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-App-Id $joule_proxy_id;
proxy_set_header X-Auth-Required "true";
}
# Lumen API
location /lumen/ {
proxy_pass http://unix:/tmp/joule/api:/;
proxy_set_header X-Auth-Required "true";
}
# Security configuration
ssl on;
ssl_certificate /etc/joule/security/server.crt;
ssl_certificate_key /etc/joule/security/server.key;
}
\ No newline at end of file
map $request_uri $joule_proxy_id {
"~^/joule/app/(?<id>[m|p]\d*)/(?<path>.*)$" $id;
default "";
}
map $uri $joule_proxy_uri {
"~^/joule/app/[m|p]\d*/(?<path>.*)$" $path;
default "";
}
map $uri $lumen_proxy_id {
"~^/app/(?<id>\d*)" $id; #/(?<path>.*)$" $id;
default "";
}
map $uri $lumen_proxy_uri {
"~^/app/(?<id>\d*)/(?<path>.*)$" $path;
default "";
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
......@@ -54,10 +54,25 @@ http {
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
include /etc/nginx/conf.d/*.conf;
##
# Virtual Host Configs
# Site Settings
##
include /etc/nginx/map.conf;
server{
listen 80;
include /etc/nginx/lumen.conf;
}
server{
listen 443;
include /etc/nginx/lumen.conf;
include /etc/nginx/joule.conf;
# Security configuration
ssl on;
ssl_certificate /etc/joule/security/server.crt;
ssl_certificate_key /etc/joule/security/server.key;
}
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/site.conf;
}
......@@ -20,8 +20,23 @@ class nginx::pi{
mode => '0644',
require => File['/etc/nginx']
}
file {'/etc/nginx/site.conf':
source => 'puppet:///modules/nginx/site.conf',
file {'/etc/nginx/lumen.conf':
source => 'puppet:///modules/nginx/lumen.conf',
owner => root,
group => root,
mode => '0644',
require => File['/etc/nginx']
}
file {'/etc/nginx/joule.conf':
source => 'puppet:///modules/nginx/joule.conf',
owner => root,
group => root,
mode => '0644',
require => File['/etc/nginx']
}
file {'/etc/nginx/map.conf':
source => 'puppet:///modules/nginx/map.conf',
owner => root,
group => root,
mode => '0644',
......@@ -79,7 +94,7 @@ class nginx::pi{
ensure => "6.0.4",
provider => gem,
}
package {'libcurl4-openssl-dev':
package {'libcurl4-openssl-dev':
ensure => present,
}
exec {'install-agent':
......@@ -90,7 +105,7 @@ class nginx::pi{
}
service {'nginx':
ensure => running,
enable => true,
require => [File['/etc/systemd/system/nginx.service'],
Package['passenger']]
}
......
......@@ -25,15 +25,30 @@ class nginx::ubuntu{
mode => '0644',
require => Package['nginx'],
}
file {'/etc/nginx/site.conf':
source => 'puppet:///modules/nginx/site.conf',
file {'/etc/nginx/joule.conf':
source => 'puppet:///modules/nginx/joule.conf',
owner => root,
group => root,
mode => '0644',
require => Package['nginx'],
}
file {'/etc/nginx/lumen.conf':
source => 'puppet:///modules/nginx/lumen.conf',
owner => root,
group => root,
mode => '0644',
require => Package['nginx'],
}
file {'/etc/nginx/map.conf':
source => 'puppet:///modules/nginx/map.conf',
owner => root,
group => root,
mode => '0644',
require => Package['nginx'],
}
service {'nginx':
ensure => running,
require => [File['/etc/nginx/site.conf','/etc/nginx/nginx.conf'], Package['libnginx-mod-http-passenger']]
enable => true,
require => [File['/etc/nginx/nginx.conf'], Package['libnginx-mod-http-passenger']]
}
}
......@@ -4,8 +4,9 @@ node 'default' {
include joule
include static_sites
include rails_api
include joule_labjack
# include joule_labjack
include nginx
include hostapd
}
node 'nilm'{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment