From 5416017c05e44fc635ad14ffdf1ac1163a4cc6e5 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Wed, 13 Apr 2005 15:23:57 +0000 Subject: reorganizing git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@95 980ebf18-57e1-0310-9a29-db15c13687c0 --- README | 32 +++++ bin/blinker | 89 +++++++++++++ bin/sleeper | 97 ++++++++++++++ examples/assignments | 1 + examples/code.bl | 1 + examples/code/file.bl | 7 + examples/cron2.bl | 57 +++++++++ examples/events.bl | 36 ++++++ examples/facts | 47 +++++++ examples/objects | 25 ++++ examples/one.bl | 30 +++++ examples/root/bin/sleeper | 97 ++++++++++++++ examples/root/etc/configfile | 0 examples/root/etc/init.d/sleeper | 25 ++++ examples/service.bl | 52 ++++++++ install.rb | 268 +++++++++++++++++++++++++++++++++++++++ notes/design | 99 +++++++++++++++ notes/execution | 28 ++++ notes/features | 13 ++ notes/goals | 17 +++ notes/issues | 43 +++++++ notes/language/notes | 7 + notes/notes | 44 +++++++ test/blinktest.rb | 43 +++++++ test/tc_basic.rb | 93 ++++++++++++++ test/tc_file.rb | 96 ++++++++++++++ test/tc_interpreter.rb | 34 +++++ test/tc_lexer.rb | 87 +++++++++++++ test/tc_oparse.rb | 111 ++++++++++++++++ test/tc_package.rb | 27 ++++ test/tc_parser.rb | 29 +++++ test/tc_selector.rb | 32 +++++ test/tc_service.rb | 73 +++++++++++ test/tc_symlink.rb | 59 +++++++++ test/text/assignments | 9 ++ test/text/facts | 9 ++ test/text/functions | 3 + test/text/groups | 7 + test/text/one | 5 + test/text/selectors | 27 ++++ test/ts_objects.rb | 6 + test/ts_other.rb | 6 + test/ts_parsing.rb | 5 + 43 files changed, 1876 insertions(+) create mode 100644 README create mode 100755 bin/blinker create mode 100755 bin/sleeper create mode 100644 examples/assignments create mode 100644 examples/code.bl create mode 100644 examples/code/file.bl create mode 100644 examples/cron2.bl create mode 100644 examples/events.bl create mode 100644 examples/facts create mode 100644 examples/objects create mode 100644 examples/one.bl create mode 100755 examples/root/bin/sleeper create mode 100644 examples/root/etc/configfile create mode 100755 examples/root/etc/init.d/sleeper create mode 100644 examples/service.bl create mode 100644 install.rb create mode 100644 notes/design create mode 100644 notes/execution create mode 100644 notes/features create mode 100644 notes/goals create mode 100644 notes/issues create mode 100644 notes/language/notes create mode 100644 notes/notes create mode 100644 test/blinktest.rb create mode 100644 test/tc_basic.rb create mode 100644 test/tc_file.rb create mode 100644 test/tc_interpreter.rb create mode 100644 test/tc_lexer.rb create mode 100644 test/tc_oparse.rb create mode 100644 test/tc_package.rb create mode 100644 test/tc_parser.rb create mode 100644 test/tc_selector.rb create mode 100644 test/tc_service.rb create mode 100644 test/tc_symlink.rb create mode 100644 test/text/assignments create mode 100644 test/text/facts create mode 100644 test/text/functions create mode 100644 test/text/groups create mode 100644 test/text/one create mode 100644 test/text/selectors create mode 100644 test/ts_objects.rb create mode 100644 test/ts_other.rb create mode 100644 test/ts_parsing.rb diff --git a/README b/README new file mode 100644 index 000000000..0731cdc0e --- /dev/null +++ b/README @@ -0,0 +1,32 @@ +$Id$ + +Introduction +============ +There are currently three main components to Blink: + +Objects +------- +These are the "primitives" of the language. If you want to affect the system, +these are the only way to do it. Their base class is in blink/objects.rb, and +they all inherit directly from that class. + +Attributes +---------- +Each of the Objects are basically a collection of attributes. The attributes +themselves are how the system is actually modified -- e.g., you set +'file("/etc/passwd").owner = X', which modifies an attribute value, and that +results in the system itelf being modified. + +Each attribute derives from blink/attribute.rb, but most attributes are actually +defined in the same file as the class that uses them (e.g., blink/objects/file.rb). + +The Wrapper +----------- +At the top level is the Blink module. It doesn't do much right now + +Starting +======== +You can start with bin/blinker, but it's probably better to just start in test/. +I've been writing simple unit tests for most of the work I've done, so you can +see how things do (and should) work by looking in there. Just run 'ruby +'. diff --git a/bin/blinker b/bin/blinker new file mode 100755 index 000000000..d54041dc5 --- /dev/null +++ b/bin/blinker @@ -0,0 +1,89 @@ +#!/usr/local/bin/ruby -w + +# $Id$ + +require 'blink' +require 'facter' + +# collect enough information to make some simple decisions +begin + facts = Facter.retrieve('OperatingSystem','OperatingSystemRelease','Hostname') +rescue => error + puts "Could not retrieve facts: %s" % error + exit(47) +end + +# set up how our environment will behave +args = Hash.new + +args[:debug] = 1 + +args[:depthfirst] = 1 +args[:opinstances] = 1 + +Blink.init(args) + +# and now build a simple component, consisting of a process +# that depends on a file +component = Blink::Component.new(:name => "sleeper") + +# add our testing directory to the search path for services +Blink::Objects::Service.addpath( + File.expand_path("~/svn/blink/examples/root/etc/init.d") +) + +# here's the process itself +sleeper = Blink::Objects::Service.new( + :running => 1, + :name => "sleeper" +) + +# add it to the component +component.push(sleeper) + +#groupselector = Blink::Selector.new( + # proc { facts['Hostname'] == 'culain' } => 'luke', + # proc { facts['Hostname'] == 'kirby' } => 'sysadmin' +#) + +# and the file that our component depends on +configfile = Blink::Objects::BFile.new( + :path => File.expand_path("~/svn/blink/examples/root/etc/configfile"), + :owner => "luke", + :group => "sysadmin", + :mode => 0644 +) + #:check => "md5" + +component.push(configfile) + +# i guess i should call subscribe on the object triggering the event, +# not the one responding.... +# except that really, the one responding is merely listening to events +# that pass through it... +# XXX okay, i need to decide whether i use generic components and lose +# the actual dependency information, or whether i use literal dependency +# information +configfile.subscribe( + :event => :inode_changed, + :object => sleeper +) { |me,object,event| + puts "#{me} restarting because of #{event} from #{object}" + me.callop("stop") + me.callop("start") +} + +component.retrieve() + +#unless component.insync? +# component.sync() +#end + +puts sleeper.insync?() +sleeper.sync() +sleeper.retrieve() +puts sleeper.insync?() + +#other.contains(test) + +#Blink.run diff --git a/bin/sleeper b/bin/sleeper new file mode 100755 index 000000000..5382383cd --- /dev/null +++ b/bin/sleeper @@ -0,0 +1,97 @@ +#!/usr/bin/perl -w + +### +# sleep indefinitely as a debug + +use strict; +use Getopt::Long; +use Pod::Usage; + +#----------------------------------------------------------------- +sub daemonize +{ + use POSIX 'setsid'; + $| = 1; + chdir '/' or die "Can't chdir to /: $!\n"; + open STDIN, "/dev/null" or die "Can't read /dev/null: $!\n"; + open STDOUT, "> /dev/null" or die "Can't write to /dev/null: $!\n"; + defined(my $pid = fork()) or die "Can't fork: $!\n"; + #print STDERR $pid, "\n"; + exit if $pid; + setsid or die "Can't start a new session: $!\n"; + open STDERR, ">&STDOUT" or die "Can't dup stdout: $!\n"; +} +#----------------------------------------------------------------- + +my ($help,$opt_result,$debug,$fun); + +$opt_result = GetOptions +( + "help" => \$help, + "debug" => \$debug, + "fun" => \$fun, +); + +if (! $opt_result) +{ + pod2usage('-exitval' => 1, '-verbose' => 0); + exit(1); +} + +if ($help) +{ + pod2usage('-exitval' => 1, '-verbose' => 2); + exit; +} + +unless ($debug) { + daemonize(); +} + +while(1){ + sleep 600; +} + +=head1 NAME + +template - this is a template script and should be copied and modded + +=head1 SYNOPSIS + +template [-help] + +=head1 DESCRIPTION + +B