Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Green committed May 7, 2013
0 parents commit 76c90b3
Show file tree
Hide file tree
Showing 10 changed files with 356 additions and 0 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# CHANGELOG for watcher

This file is used to list changes made in each version of watcher.

## 0.1.0:

* Initial release of watcher

- - -
Check the [Markdown Syntax Guide](http://daringfireball.net/projects/markdown/syntax) for help with Markdown.

The [Github Flavored Markdown page](http://github.github.com/github-flavored-markdown/) describes the differences between markdown on github and standard markdown.
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2013 Peter Green

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
98 changes: 98 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
watcher Cookbook
================
This cookbook installs and configures the Python Watcher daemon (https://github.com/greggoryhz/Watcher), which uses
the inotify kernel subsystem to monitor for file system changes and perform arbitrary actions.

Requirements
------------
Platform
--------

* Red Hat, CentOS - I will be working on Debian support as I have a system that needs it!

#### cookbooks
- `git` - needed to clone the latest version of the tool.
- `python` - required for installing python dependencies and to execute the tool.

Attributes
----------

#### watcher::default
<table>
<tr>
<th>Key</th>
<th>Type</th>
<th>Description</th>
<th>Default</th>
</tr>
<tr>
<td><tt>['watcher']['repo_url']</tt></td>
<td>String</td>
<td>The Git repository to clone the daemon from.</td>
<td><tt>https://github.com/greggoryhz/Watcher.git</tt></td>
</tr>
<tr>
<td><tt>['watcher']['install_path']</tt></td>
<td>String</td>
<td>Destination for the cloned tool.</td>
<td><tt>/usr/local/watcher</tt></td>
</tr>
<tr>
<td><tt>['watcher']['jobs']</tt></td>
<td>Array</td>
<td>A set of jobs for the Watcher daemon to manage.</td>
<td><tt>[]</tt></td>
</tr>
</table>

Usage
-----
#### watcher::default
e.g.
Just include `watcher` in your node's `run_list`:

```json
{
"name":"my_node",
"run_list": [
"recipe[watcher]"
]
}
```

Resources/Providers
===================

This cookbook's resources are for other cookbooks to manage jobs for the daemon.

`job`
----------

Manage jobs on the server.

### Actions

- :create: create a job

### Attribute Parameters

- name: name attribute. Name of the job.
- label: description of the task.
- path: file system path to monitor.
- monitor: file system events to monitor (create, move_to, delete, etc.).
- recursive: should the path be monitored recursively?
- command: the command to be executed following a detected event.

Contributing
------------

1. Fork the repository on Github
2. Create a named feature branch (like `add_component_x`)
3. Write you change
4. Write tests for your change (if applicable)
5. Run the tests, ensuring they all pass
6. Submit a Pull Request using Github

License and Authors
-------------------
Authors: Peter Green
7 changes: 7 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
default['watcher']['repo_url'] = "https://github.com/greggoryhz/Watcher.git"
default['watcher']['install_path'] = "/usr/local/watcher"
default['watcher']['pid_file'] = "/var/run/watcher.pid"
default['watcher']['log_file'] = "/var/log/watcher.log"
default['watcher']['user'] = "root"
default['watcher']['jobs'] = []

9 changes: 9 additions & 0 deletions metadata.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name 'watcher'
maintainer 'Peter Green'
maintainer_email '[email protected]'
license 'Apache 2.0'
description 'Installs/Configures the Python Watcher daemon'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '0.1.1'
depends 'git'
depends 'python'
20 changes: 20 additions & 0 deletions providers/job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

action :create do


node['watcher']['jobs'] << {
"name" => new_resource.name,
"label" => new_resource.label,
"path" => new_resource.path,
"monitor" => new_resource.monitor,
"recursive" => new_resource.recursive,
"command" => new_resource.command
}

template "/root/.watcher/jobs.yml" do
source "jobs.yml.erb"
notifies :restart, "service[watcher]"
cookbook "watcher"
end

end
43 changes: 43 additions & 0 deletions recipes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# Cookbook Name:: watcher
# Recipe:: default
#
# Copyright 2013, Dachis Group
#
# All rights reserved - Do Not Redistribute
include_recipe "git"
include_recipe "python"

package "libyaml-devel"

python_pip "pyinotify" do
action :install
end

python_pip "PyYAML" do
action :install
end

git "clone watcher repo" do
repository node['watcher']['repo_url']
revision "HEAD"
destination node['watcher']['install_path']
action :sync
end

template "/etc/init.d/watcher" do
source "watcher.init.d.sh.erb"
owner "root"
group "root"
mode "0755"
variables "binary" => "/usr/local/watcher/watcher.py"
end

directory "/root/.watcher" do
action :create
end

service "watcher" do
action [ :start, :enable ]
end

8 changes: 8 additions & 0 deletions resources/job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
actions :create

attribute :name, :kind_of => String, :name_attribute => true
attribute :label, :kind_of => String
attribute :path, :kind_of => String
attribute :monitor, :kind_of => String
attribute :recursive, :kind_of => [TrueClass, FalseClass]
attribute :command, :kind_of => String
8 changes: 8 additions & 0 deletions templates/default/jobs.yml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<% node['watcher']['jobs'].each do |job| -%>
<%= job['name'] %>:
label: <%= job['label'] %>
watch: <%= job['path'] %>
events: [ <%= job['monitor'] %> ]
recursive: <%= job['recursive'] %>
command: <%= job['command'] %>
<% end -%>
138 changes: 138 additions & 0 deletions templates/default/watcher.init.d.sh.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
#!/bin/bash
#
# Script to run watcher in daemon mode at boot time.
#
# Check http://www.gaztronics.net/ for the
# most up-to-date version of this script.
#
# This script is realeased under the terms of the GPL.
# You can source a copy at:
# http://www.fsf.org/copyleft/copyleft.html
#
# Please feel free to modify the script to suite your own needs.
# I always welcome email feedback with suggestions for improvements.
# Please do not email for general support. I do not have time to answer
# personal help requests.

# Author: Gary Myers MIET MBCS CITP
# Revision 1.0 - 4th March 2005

#====================================================================
# Run level information:
#
# chkconfig: 2345 99 99
# description: Secure Tunnel
# processname: watcher
#
# Run "/sbin/chkconfig --add watcher" to add the Run levels.
# This will setup the symlinks and set the process to run at boot.
#====================================================================

#====================================================================
# Paths and variables and system checks.
export HOME=/root

# Source function library (It's a Red Hat thing!)
. /etc/rc.d/init.d/functions

# Check that networking is up.
#
[ ${NETWORKING} ="yes" ] || exit 0

# Path to the executable.
#
SEXE=<%= @binary %>

# Path to the configuration file.
#
CONF=$HOME/.watcher/jobs.yml

# Check the configuration file exists.
#
if [ ! -f $CONF ] ; then
echo "The configuration file cannot be found!"
exit 0
fi

# Path to the lock file.
#
LOCK_FILE=$HOME/.watcher/watcher.pid

#====================================================================

#====================================================================
# Run controls:

prog=$"watcher"

RETVAL=0

# Start watcher as daemon.
#
start() {
if [ -f $LOCK_FILE ]; then
echo "watcher is already running!"
exit 0
else
echo -n $"Starting $prog: "
$SEXE start
fi

RETVAL=$?
[ $RETVAL -eq 0 ] && success
echo
[ $RETVAL -eq 0 ] && touch $LOCK_FILE
return $RETVAL
}


# Stop watcher.
#
stop() {
if [ ! -f $LOCK_FILE ]; then
echo "watcher is not running!"
exit 0

else

echo -n $"Shutting down $prog: "
$SEXE stop
RETVAL=$?
[ $RETVAL -eq 0 ]
rm -f $LOCK_FILE
echo
return $RETVAL

fi
}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
condrestart)
if [ -f $LOCK_FILE ]; then
stop
start
RETVAL=$?
fi
;;
status)
status watcher
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
RETVAL=1
esac

exit $RETVAL

0 comments on commit 76c90b3

Please sign in to comment.