This page contains some simple examples that show you how to get started writing your own policies, and demonstates how files are laid out.
There are further examples listed in the The Definitive Slaughter Guide.
The most basic policy would involve no dynamic fetches, and no file-serving.
Assuming you have central server running a webserver, with a DocumentRoot set to /var/www/ then create the following directory tree:/var/www/ /var/www/slaughter/ /var/www/slaughter/policies/
Save the default.policy file as:/var/www/slaughter/policies/default.policy
Now, on a system with client installed execute:slaughter --prefix=http://your.server/ --transport=http
You should see output like this:I am running via Slaughter.
As the examples are hosted on this server you can test by running:root@precious:~# slaughter --transport=http \ --prefix=http://www.steve.org.uk/Software/slaughter/examples/basic/ I am running via Slaughter.
Here you see that "/policies/default.policy" has been automatically appended to the value you specified in the --prefix argument - which in the second example has lead to the fetching of the file http://www.steve.org.uk/Software/slaughter/examples/basic/policies/default.policy.
The next most interesting example follows a similar pattern:
- The value /policies/default.policy is appended to the initial prefix for finding the policy to execute.
- Similarly the value /files/ is appended for any file fetches.
The next example will have a DocumentRoot looking like this:/var/www/ /var/www/slaughter/ /var/www/slaughter/policies/ /var/www/slaughter/policies/default.policy /var/www/slaughter/files/ /var/www/slaughter/files/etc/ /var/www/slaughter/files/etc/motd
If you wish to run this code against your own system please note it will replace your /etc/motd file - as it uses the FetchFile primitive.
Running code code hosted here would be achieved via this command line:root@precious:~# slaughter --transport=http \ --prefix=http://www.steve.org.uk/Software/slaughter/examples/file-copy The local file /etc/motd was updated
(Running it a second time will result in no output - as the file won't have changed.)
If this code were hosted upon your server you'd instead use your own server-name and prefix location, as per the previous example.
Both the previous examples have used --transport=http, this is because this server happens to run a webserver, and people are familiar with them.
Slaughter is supplied with the facility to fetch policies via several different mechanisms, including remote GIT repositories, remote HTTP servers, and using the rsync protocol.
In each case the standard prefixes of /policies/ and /files must be present at the top-level of the prefix specified - this is documented in the TRANSPORTS file included within the distribution.
One of the simplest ways to test an alternative transport is to run slaughter using the examples supplied in the downloadable distribution.
Assuming you've fetched the latest archive, and unpackaged it, you should find the two examples we've previously referenced available:examples/ examples/basic/ examples/file-copy/
These could be directly executed using the "local" transport:skx@precious:~$ sudo rm /etc/motd skx@precious:~$ sudo slaughter --transport=local \ --prefix=/home/skx/hg/slaughter/examples/file-copy/ The local file /etc/motd was updated