chef 0.7.16 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of chef might be problematic. Click here for more details.
- data/README.rdoc +11 -10
- data/bin/chef-client +2 -2
- data/bin/chef-solo +1 -1
- data/bin/knife +27 -0
- data/bin/shef +49 -0
- data/distro/README +2 -0
- data/distro/{debian → common}/man/man1/chef-indexer.1 +0 -0
- data/distro/{debian → common}/man/man1/chef-server.1 +0 -0
- data/distro/{debian → common}/man/man8/chef-client.8 +0 -0
- data/distro/{debian → common}/man/man8/chef-solo.8 +0 -0
- data/distro/common/man/man8/knife.8 +375 -0
- data/distro/redhat/etc/init.d/chef-client +8 -4
- data/distro/redhat/etc/init.d/chef-server +16 -15
- data/distro/redhat/etc/init.d/chef-server-webui +78 -0
- data/distro/redhat/etc/init.d/chef-solr +76 -0
- data/distro/redhat/etc/init.d/chef-solr-indexer +75 -0
- data/distro/redhat/etc/sysconfig/chef-client +10 -0
- data/distro/redhat/etc/sysconfig/chef-server +10 -0
- data/distro/redhat/etc/sysconfig/chef-server-webui +10 -0
- data/distro/redhat/etc/sysconfig/chef-solr +9 -0
- data/distro/redhat/etc/sysconfig/chef-solr-indexer +7 -0
- data/distro/suse/etc/init.d/chef-client +121 -0
- data/lib/chef.rb +1 -1
- data/lib/chef/api_client.rb +263 -0
- data/lib/chef/application.rb +1 -1
- data/lib/chef/application/client.rb +21 -3
- data/lib/chef/application/knife.rb +144 -0
- data/lib/chef/application/server.rb +2 -1
- data/lib/chef/application/solo.rb +9 -2
- data/lib/chef/cache.rb +61 -0
- data/lib/chef/cache/checksum.rb +70 -0
- data/lib/chef/certificate.rb +154 -0
- data/lib/chef/client.rb +123 -220
- data/lib/chef/compile.rb +9 -21
- data/lib/chef/config.rb +67 -10
- data/lib/chef/cookbook.rb +49 -22
- data/lib/chef/cookbook/metadata.rb +85 -5
- data/lib/chef/cookbook_loader.rb +4 -4
- data/lib/chef/couchdb.rb +99 -30
- data/lib/chef/daemon.rb +1 -1
- data/lib/chef/data_bag.rb +215 -0
- data/lib/chef/data_bag_item.rb +219 -0
- data/lib/chef/exceptions.rb +3 -0
- data/lib/chef/index_queue.rb +29 -0
- data/lib/chef/index_queue/amqp_client.rb +106 -0
- data/lib/chef/index_queue/consumer.rb +76 -0
- data/lib/chef/index_queue/indexable.rb +74 -0
- data/lib/chef/knife.rb +309 -0
- data/lib/chef/knife/client_bulk_delete.rb +40 -0
- data/lib/chef/knife/client_create.rb +62 -0
- data/lib/chef/knife/client_delete.rb +37 -0
- data/lib/chef/knife/client_edit.rb +37 -0
- data/lib/chef/knife/client_list.rb +40 -0
- data/lib/chef/knife/client_reregister.rb +48 -0
- data/lib/chef/knife/client_show.rb +42 -0
- data/lib/chef/knife/configure.rb +123 -0
- data/lib/chef/knife/cookbook_bulk_delete.rb +46 -0
- data/lib/chef/knife/cookbook_delete.rb +41 -0
- data/lib/chef/knife/cookbook_download.rb +57 -0
- data/lib/chef/knife/cookbook_list.rb +41 -0
- data/lib/chef/knife/cookbook_metadata.rb +87 -0
- data/lib/chef/knife/cookbook_show.rb +75 -0
- data/lib/chef/knife/cookbook_upload.rb +179 -0
- data/lib/chef/knife/data_bag_create.rb +43 -0
- data/lib/chef/knife/data_bag_delete.rb +43 -0
- data/lib/chef/knife/data_bag_edit.rb +49 -0
- data/lib/chef/knife/data_bag_list.rb +42 -0
- data/lib/chef/knife/data_bag_show.rb +40 -0
- data/lib/chef/knife/ec2_instance_data.rb +46 -0
- data/lib/chef/knife/index_rebuild.rb +51 -0
- data/lib/chef/knife/node_bulk_delete.rb +43 -0
- data/lib/chef/knife/node_create.rb +39 -0
- data/lib/chef/knife/node_delete.rb +36 -0
- data/lib/chef/knife/node_edit.rb +36 -0
- data/lib/chef/knife/node_from_file.rb +42 -0
- data/lib/chef/knife/node_list.rb +41 -0
- data/lib/chef/knife/node_run_list_add.rb +64 -0
- data/lib/chef/knife/node_run_list_remove.rb +45 -0
- data/lib/chef/knife/node_show.rb +46 -0
- data/lib/chef/knife/role_bulk_delete.rb +44 -0
- data/lib/chef/knife/role_create.rb +44 -0
- data/lib/chef/knife/role_delete.rb +36 -0
- data/lib/chef/knife/role_edit.rb +37 -0
- data/lib/chef/knife/role_from_file.rb +46 -0
- data/lib/chef/knife/role_list.rb +40 -0
- data/lib/chef/knife/role_show.rb +43 -0
- data/lib/chef/knife/search.rb +94 -0
- data/lib/chef/knife/ssh.rb +170 -0
- data/lib/chef/log.rb +30 -8
- data/lib/chef/mixin/checksum.rb +2 -7
- data/lib/chef/mixin/command.rb +32 -13
- data/lib/chef/mixin/convert_to_class_name.rb +15 -0
- data/lib/chef/mixin/deep_merge.rb +199 -11
- data/lib/chef/mixin/generate_url.rb +18 -9
- data/lib/chef/mixin/language.rb +29 -1
- data/lib/chef/mixin/language_include_attribute.rb +56 -0
- data/lib/chef/mixin/language_include_recipe.rb +53 -0
- data/lib/chef/mixin/params_validate.rb +25 -12
- data/lib/chef/mixin/recipe_definition_dsl_core.rb +2 -0
- data/lib/chef/mixin/template.rb +11 -1
- data/lib/chef/mixin/xml_escape.rb +87 -0
- data/lib/chef/node.rb +144 -122
- data/lib/chef/openid_registration.rb +12 -5
- data/lib/chef/platform.rb +89 -47
- data/lib/chef/provider/breakpoint.rb +36 -0
- data/lib/chef/provider/cron.rb +5 -6
- data/lib/chef/provider/deploy.rb +43 -10
- data/lib/chef/provider/deploy/revision.rb +2 -3
- data/lib/chef/provider/erl_call.rb +72 -0
- data/lib/chef/provider/file.rb +8 -4
- data/lib/chef/provider/git.rb +10 -5
- data/lib/chef/provider/group/dscl.rb +128 -0
- data/lib/chef/provider/http_request.rb +6 -2
- data/lib/chef/provider/ifconfig.rb +1 -0
- data/lib/chef/provider/link.rb +1 -1
- data/lib/chef/provider/log.rb +53 -0
- data/lib/chef/provider/mdadm.rb +88 -0
- data/lib/chef/provider/mount/mount.rb +1 -1
- data/lib/chef/provider/package.rb +1 -1
- data/lib/chef/provider/package/easy_install.rb +106 -0
- data/lib/chef/provider/package/pacman.rb +101 -0
- data/lib/chef/provider/package/portage.rb +1 -1
- data/lib/chef/provider/package/rpm.rb +10 -8
- data/lib/chef/provider/package/yum-dump.py +22 -3
- data/lib/chef/provider/package/yum.rb +32 -8
- data/lib/chef/provider/package/zypper.rb +132 -0
- data/lib/chef/provider/remote_directory.rb +58 -49
- data/lib/chef/provider/remote_file.rb +1 -1
- data/lib/chef/provider/route.rb +136 -80
- data/lib/chef/provider/ruby_block.rb +18 -1
- data/lib/chef/provider/service/arch.rb +109 -0
- data/lib/chef/provider/service/freebsd.rb +0 -1
- data/lib/chef/provider/service/simple.rb +2 -3
- data/lib/chef/provider/service/upstart.rb +191 -0
- data/lib/chef/provider/subversion.rb +12 -4
- data/lib/chef/provider/template.rb +85 -53
- data/lib/chef/provider/user.rb +1 -1
- data/lib/chef/provider/user/dscl.rb +277 -0
- data/lib/chef/provider/user/useradd.rb +1 -0
- data/lib/chef/recipe.rb +2 -41
- data/lib/chef/resource.rb +9 -3
- data/lib/chef/resource/breakpoint.rb +35 -0
- data/lib/chef/resource/deploy.rb +16 -2
- data/lib/chef/resource/easy_install_package.rb +41 -0
- data/lib/chef/resource/erl_call.rb +83 -0
- data/lib/chef/resource/freebsd_package.rb +35 -0
- data/lib/chef/resource/log.rb +62 -0
- data/lib/chef/resource/mdadm.rb +82 -0
- data/lib/chef/resource/pacman_package.rb +33 -0
- data/lib/chef/resource/ruby_block.rb +21 -2
- data/lib/chef/resource/scm.rb +8 -0
- data/lib/chef/resource/subversion.rb +1 -0
- data/lib/chef/resource/user.rb +5 -2
- data/lib/chef/resource/yum_package.rb +36 -0
- data/lib/chef/resource_collection.rb +17 -9
- data/lib/chef/resource_collection/stepable_iterator.rb +124 -0
- data/lib/chef/rest.rb +166 -81
- data/lib/chef/role.rb +114 -38
- data/lib/chef/run_list.rb +15 -6
- data/lib/chef/runner.rb +13 -11
- data/lib/chef/search/query.rb +60 -0
- data/lib/chef/shef.rb +220 -0
- data/lib/chef/shef/ext.rb +297 -0
- data/lib/chef/shef/shef_session.rb +175 -0
- data/lib/chef/streaming_cookbook_uploader.rb +187 -0
- data/lib/chef/tasks/chef_repo.rake +53 -155
- data/lib/chef/util/file_edit.rb +94 -96
- data/lib/chef/webui_user.rb +233 -0
- metadata +219 -63
- data/distro/debian/etc/init.d/chef-indexer +0 -175
- data/distro/redhat/etc/chef/client.rb +0 -16
- data/distro/redhat/etc/chef/indexer.rb +0 -10
- data/distro/redhat/etc/chef/server.rb +0 -22
- data/distro/redhat/etc/init.d/chef-indexer +0 -76
- data/lib/chef/application/indexer.rb +0 -141
- data/lib/chef/queue.rb +0 -145
- data/lib/chef/search.rb +0 -88
- data/lib/chef/search/result.rb +0 -64
- data/lib/chef/search_index.rb +0 -77
- data/lib/chef/util/fileedit.rb +0 -121
@@ -1,175 +0,0 @@
|
|
1
|
-
#! /bin/sh
|
2
|
-
### BEGIN INIT INFO
|
3
|
-
# Provides: chef-indexer
|
4
|
-
# Required-Start: $network
|
5
|
-
# Required-Stop: $network
|
6
|
-
# Default-Start: 2 3 4 5
|
7
|
-
# Default-Stop: 0 1 6
|
8
|
-
# Short-Description: Start a chef-indexer.
|
9
|
-
### END INIT INFO
|
10
|
-
#
|
11
|
-
# Copyright (c) 2009 Joshua Timberman, <joshua@opscode.com>
|
12
|
-
#
|
13
|
-
# chef-indexer Startup script for chef-indexer.
|
14
|
-
# chkconfig: - 98 02
|
15
|
-
# description: starts up chef-indexer in daemon mode.
|
16
|
-
|
17
|
-
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
18
|
-
DAEMON=/usr/bin/chef-indexer
|
19
|
-
NAME=chef-indexer
|
20
|
-
DESC=chef-indexer
|
21
|
-
LOGDIR=/var/log/chef
|
22
|
-
CONFIG=/etc/chef/indexer.rb
|
23
|
-
PIDFILE=/var/run/chef/indexer.pid
|
24
|
-
|
25
|
-
test -x $DAEMON || exit 0
|
26
|
-
|
27
|
-
. /lib/lsb/init-functions
|
28
|
-
|
29
|
-
if [ ! -d /var/run/chef ]; then
|
30
|
-
mkdir /var/run/chef
|
31
|
-
fi
|
32
|
-
|
33
|
-
DAEMON_OPTS="-d -c $CONFIG"
|
34
|
-
|
35
|
-
running_pid() {
|
36
|
-
pid=$1
|
37
|
-
name=$2
|
38
|
-
[ -z "$pid" ] && return 1
|
39
|
-
[ ! -d /proc/$pid ] && return 1
|
40
|
-
cmd=`cat /proc/$pid/cmdline | tr '\000' '\n' | awk 'NR==2'`
|
41
|
-
[ "$cmd" != "$name" ] && return 1
|
42
|
-
return 0
|
43
|
-
}
|
44
|
-
|
45
|
-
running() {
|
46
|
-
[ ! -f "$PIDFILE" ] && return 1
|
47
|
-
pid=`cat $PIDFILE`
|
48
|
-
running_pid $pid $DAEMON || return 1
|
49
|
-
return 0
|
50
|
-
}
|
51
|
-
|
52
|
-
start_server() {
|
53
|
-
if [ -z "$DAEMONUSER" ] ; then
|
54
|
-
start_daemon -p $PIDFILE $DAEMON $DAEMON_OPTS
|
55
|
-
errcode=$?
|
56
|
-
else
|
57
|
-
start-stop-daemon --start --quiet --pidfile $PIDFILE \
|
58
|
-
--chuid $DAEMONUSER \
|
59
|
-
--exec $DAEMON -- $DAEMON_OPTS
|
60
|
-
errcode=$?
|
61
|
-
fi
|
62
|
-
return $errcode
|
63
|
-
}
|
64
|
-
|
65
|
-
stop_server() {
|
66
|
-
if [ -z "$DAEMONUSER" ] ; then
|
67
|
-
killproc -p $PIDFILE $DAEMON
|
68
|
-
errcode=$?
|
69
|
-
else
|
70
|
-
start-stop-daemon --stop --quiet --pidfile $PIDFILE \
|
71
|
-
--user $DAEMONUSER \
|
72
|
-
--exec $DAEMON
|
73
|
-
errcode=$?
|
74
|
-
fi
|
75
|
-
return $errcode
|
76
|
-
}
|
77
|
-
|
78
|
-
reload_server() {
|
79
|
-
[ ! -f "$PIDFILE" ] && return 1
|
80
|
-
pid=pidofproc $PIDFILE # This is the daemon's pid
|
81
|
-
/bin/kill -1 $pid
|
82
|
-
return $?
|
83
|
-
}
|
84
|
-
|
85
|
-
force_stop() {
|
86
|
-
[ ! -e "$PIDFILE" ] && return
|
87
|
-
if running ; then
|
88
|
-
/bin/kill -15 $pid
|
89
|
-
sleep "$DIETIME"s
|
90
|
-
if running ; then
|
91
|
-
/bin/kill -9 $pid
|
92
|
-
sleep "$DIETIME"s
|
93
|
-
if running ; then
|
94
|
-
echo "Cannot kill $NAME (pid=$pid)!"
|
95
|
-
exit 1
|
96
|
-
fi
|
97
|
-
fi
|
98
|
-
fi
|
99
|
-
rm -f $PIDFILE
|
100
|
-
}
|
101
|
-
|
102
|
-
case "$1" in
|
103
|
-
start)
|
104
|
-
log_daemon_msg "Starting $DESC " "$NAME"
|
105
|
-
if running ; then
|
106
|
-
log_progress_msg "apparently already running"
|
107
|
-
log_end_msg 0
|
108
|
-
exit 3
|
109
|
-
fi
|
110
|
-
if start_server ; then
|
111
|
-
[ -n "$STARTTIME" ] && sleep $STARTTIME # Wait some time
|
112
|
-
if running ; then
|
113
|
-
log_end_msg 0
|
114
|
-
else
|
115
|
-
log_end_msg 1
|
116
|
-
fi
|
117
|
-
else
|
118
|
-
log_end_msg 1
|
119
|
-
fi
|
120
|
-
;;
|
121
|
-
stop)
|
122
|
-
log_daemon_msg "Stopping $DESC" "$NAME"
|
123
|
-
if running ; then
|
124
|
-
errcode=0
|
125
|
-
stop_server || errcode=$?
|
126
|
-
log_end_msg $errcode
|
127
|
-
else
|
128
|
-
log_progress_msg "apparently not running"
|
129
|
-
log_end_msg 0
|
130
|
-
exit 0
|
131
|
-
fi
|
132
|
-
;;
|
133
|
-
force-stop)
|
134
|
-
$0 stop
|
135
|
-
if running; then
|
136
|
-
log_daemon_msg "Stopping (force) $DESC" "$NAME"
|
137
|
-
errcode=0
|
138
|
-
force_stop || errcode=$?
|
139
|
-
log_end_msg $errcode
|
140
|
-
fi
|
141
|
-
;;
|
142
|
-
restart|force-reload)
|
143
|
-
log_daemon_msg "Restarting $DESC" "$NAME"
|
144
|
-
errcode=0
|
145
|
-
stop_server || errcode=$?
|
146
|
-
[ -n "$DIETIME" ] && sleep $DIETIME
|
147
|
-
start_server || errcode=$?
|
148
|
-
[ -n "$STARTTIME" ] && sleep $STARTTIME
|
149
|
-
running || errcode=$?
|
150
|
-
log_end_msg $errcode
|
151
|
-
;;
|
152
|
-
status)
|
153
|
-
log_daemon_msg "Checking status of $DESC" "$NAME"
|
154
|
-
if running ; then
|
155
|
-
log_progress_msg "running"
|
156
|
-
log_end_msg 0
|
157
|
-
else
|
158
|
-
log_progress_msg "apparently not running"
|
159
|
-
log_end_msg 1
|
160
|
-
exit 1
|
161
|
-
fi
|
162
|
-
;;
|
163
|
-
reload)
|
164
|
-
log_warning_msg "Reloading $NAME daemon: not implemented, as the daemon"
|
165
|
-
log_warning_msg "cannot re-read the config file (use restart)."
|
166
|
-
;;
|
167
|
-
*)
|
168
|
-
N=/etc/init.d/$NAME
|
169
|
-
echo "Usage: $N {start|stop|force-stop|restart|force-reload|status}" >&2
|
170
|
-
exit 1
|
171
|
-
;;
|
172
|
-
esac
|
173
|
-
|
174
|
-
exit 0
|
175
|
-
|
@@ -1,16 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Chef Client Config File
|
3
|
-
#
|
4
|
-
|
5
|
-
log_level :info
|
6
|
-
ssl_verify_mode :verify_none
|
7
|
-
registration_url "http://127.0.0.1:4000"
|
8
|
-
openid_url "http://127.0.0.1:4001"
|
9
|
-
template_url "http://127.0.0.1:4000"
|
10
|
-
remotefile_url "http://127.0.0.1:4000"
|
11
|
-
search_url "http://127.0.0.1:4000"
|
12
|
-
|
13
|
-
pid_file "/var/run/chef/chef-client.pid"
|
14
|
-
|
15
|
-
#interval 1800
|
16
|
-
#splay 0
|
@@ -1,22 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Chef Server Config File
|
3
|
-
#
|
4
|
-
|
5
|
-
log_level :info
|
6
|
-
ssl_verify_mode :verify_none
|
7
|
-
registration_url "http://cserver:4000"
|
8
|
-
openid_url "http://cserver:4001"
|
9
|
-
template_url "http://cserver:4000"
|
10
|
-
remotefile_url "http://cserver:4000"
|
11
|
-
search_url "http://cserver:4000"
|
12
|
-
cookbook_path [ "/var/lib/chef/site-cookbooks", "/var/lib/chef/cookbooks" ]
|
13
|
-
|
14
|
-
merb_root "/var/lib/chef/merb"
|
15
|
-
node_path "/etc/chef/node"
|
16
|
-
file_store_path "/var/lib/chef/store"
|
17
|
-
search_index_path "/var/lib/chef/search_index"
|
18
|
-
openid_store_path "/var/lib/chef/openid/db"
|
19
|
-
openid_cstore_path "/var/lib/chef/openid/cstore"
|
20
|
-
file_cache_path "/var/lib/chef/cache"
|
21
|
-
|
22
|
-
Chef::Log::Formatter.show_time = false
|
@@ -1,76 +0,0 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
# Startup script for chef-indexer
|
3
|
-
#
|
4
|
-
# chkconfig: - 75 25
|
5
|
-
# description: Server component of the Chef systems integration framework.
|
6
|
-
# processname: chef-indexer
|
7
|
-
#
|
8
|
-
# config: /etc/sysconfig/chef-indexer
|
9
|
-
# pidfile: /var/run/chef/chef-indexer.pid
|
10
|
-
|
11
|
-
# Source function library
|
12
|
-
. /etc/init.d/functions
|
13
|
-
|
14
|
-
[ -f /etc/sysconfig/chef-indexer ] && . /etc/sysconfig/chef-indexer
|
15
|
-
|
16
|
-
prog="chef-indexer"
|
17
|
-
PIDFILE=/var/run/chef/chef-indexer.pid
|
18
|
-
LOCKFILE=/var/lock/subsys/$prog
|
19
|
-
CONFIG=/etc/chef/indexer.rb
|
20
|
-
USER="chef"
|
21
|
-
GROUP="chef"
|
22
|
-
LOGFILE=/var/log/chef/chef-indexer.log
|
23
|
-
OPTIONS=
|
24
|
-
|
25
|
-
start() {
|
26
|
-
echo -n "Starting $prog:"
|
27
|
-
daemon chef-indexer -d -c "$CONFIG" -u "$USER" -g "$GROUP" -L "$LOGFILE" "$OPTIONS" ">/dev/null"
|
28
|
-
RETVAL=$?
|
29
|
-
echo
|
30
|
-
[ $RETVAL -eq 0 ] && touch ${LOCKFILE}
|
31
|
-
return $RETVAL
|
32
|
-
}
|
33
|
-
|
34
|
-
stop() {
|
35
|
-
echo -n "Stopping $prog: "
|
36
|
-
if [ -f $PIDFILE ]; then
|
37
|
-
killproc chef-indexer
|
38
|
-
RETVAL=$?
|
39
|
-
if [ $RETVAL -ne 0 ]; then
|
40
|
-
failure;
|
41
|
-
fi;
|
42
|
-
else
|
43
|
-
RETVAL=1
|
44
|
-
failure;
|
45
|
-
fi
|
46
|
-
rm -f $LOCKFILE
|
47
|
-
echo
|
48
|
-
return $RETVAL
|
49
|
-
}
|
50
|
-
|
51
|
-
case "$1" in
|
52
|
-
start)
|
53
|
-
start
|
54
|
-
;;
|
55
|
-
stop)
|
56
|
-
stop
|
57
|
-
;;
|
58
|
-
restart)
|
59
|
-
stop
|
60
|
-
start
|
61
|
-
;;
|
62
|
-
condrestart)
|
63
|
-
if [ -f $LOCKFILE ]; then
|
64
|
-
stop
|
65
|
-
start
|
66
|
-
fi
|
67
|
-
;;
|
68
|
-
status)
|
69
|
-
status chef-indexer
|
70
|
-
;;
|
71
|
-
*)
|
72
|
-
echo "Usage: $0 {start|stop|restart|condrestart|status}"
|
73
|
-
exit 1
|
74
|
-
esac
|
75
|
-
|
76
|
-
exit $RETVAL
|
@@ -1,141 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: AJ Christensen (<aj@opscode.com>)
|
3
|
-
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
4
|
-
# License:: Apache License, Version 2.0
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
|
18
|
-
require 'chef/application'
|
19
|
-
require 'chef/queue'
|
20
|
-
require 'chef/search'
|
21
|
-
require 'chef/search_index'
|
22
|
-
require 'chef/config'
|
23
|
-
require 'chef/daemon'
|
24
|
-
require 'chef/log'
|
25
|
-
|
26
|
-
|
27
|
-
class Chef::Application::Indexer < Chef::Application
|
28
|
-
|
29
|
-
option :config_file,
|
30
|
-
:short => "-c CONFIG",
|
31
|
-
:long => "--config CONFIG",
|
32
|
-
:default => "/etc/chef/server.rb",
|
33
|
-
:description => "The configuration file to use"
|
34
|
-
|
35
|
-
option :log_level,
|
36
|
-
:short => "-l LEVEL",
|
37
|
-
:long => "--log_level LEVEL",
|
38
|
-
:description => "Set the log level (debug, info, warn, error, fatal)",
|
39
|
-
:proc => lambda { |l| l.to_sym }
|
40
|
-
|
41
|
-
option :log_location,
|
42
|
-
:short => "-L LOGLOCATION",
|
43
|
-
:long => "--logfile LOGLOCATION",
|
44
|
-
:description => "Set the log file location, defaults to STDOUT - recommended for daemonizing",
|
45
|
-
:proc => nil
|
46
|
-
|
47
|
-
option :help,
|
48
|
-
:short => "-h",
|
49
|
-
:long => "--help",
|
50
|
-
:description => "Show this message",
|
51
|
-
:on => :tail,
|
52
|
-
:boolean => true,
|
53
|
-
:show_options => true,
|
54
|
-
:exit => 0
|
55
|
-
|
56
|
-
option :user,
|
57
|
-
:short => "-u USER",
|
58
|
-
:long => "--user USER",
|
59
|
-
:description => "User to set privilege to",
|
60
|
-
:proc => nil
|
61
|
-
|
62
|
-
option :group,
|
63
|
-
:short => "-g GROUP",
|
64
|
-
:long => "--group GROUP",
|
65
|
-
:description => "Group to set privilege to",
|
66
|
-
:proc => nil
|
67
|
-
|
68
|
-
option :daemonize,
|
69
|
-
:short => "-d",
|
70
|
-
:long => "--daemonize",
|
71
|
-
:description => "Daemonize the process",
|
72
|
-
:proc => lambda { |p| true }
|
73
|
-
|
74
|
-
option :version,
|
75
|
-
:short => "-v",
|
76
|
-
:long => "--version",
|
77
|
-
:description => "Show chef version",
|
78
|
-
:boolean => true,
|
79
|
-
:proc => lambda {|v| puts "Chef: #{::Chef::VERSION}"},
|
80
|
-
:exit => 0
|
81
|
-
|
82
|
-
def initialize
|
83
|
-
super
|
84
|
-
|
85
|
-
@chef_search_indexer = nil
|
86
|
-
end
|
87
|
-
|
88
|
-
# Create a new search indexer and connect to the stomp queues
|
89
|
-
def setup_application
|
90
|
-
Chef::Daemon.change_privilege
|
91
|
-
|
92
|
-
@chef_search_indexer = Chef::SearchIndex.new
|
93
|
-
Chef::Queue.connect
|
94
|
-
Chef::Queue.subscribe(:queue, "index")
|
95
|
-
Chef::Queue.subscribe(:queue, "remove")
|
96
|
-
end
|
97
|
-
|
98
|
-
# Run the indexer, optionally daemonizing.
|
99
|
-
def run_application
|
100
|
-
if Chef::Config[:daemonize]
|
101
|
-
Chef::Daemon.daemonize("chef-indexer")
|
102
|
-
end
|
103
|
-
|
104
|
-
if Chef::Config[:queue_prefix]
|
105
|
-
queue_prefix = Chef::Config[:queue_prefix]
|
106
|
-
queue_partial_url = "/queue/#{queue_prefix}/chef"
|
107
|
-
else
|
108
|
-
queue_partial_url = "/queue/chef"
|
109
|
-
end
|
110
|
-
|
111
|
-
loop do
|
112
|
-
object, headers = Chef::Queue.receive_msg
|
113
|
-
Chef::Log.info("Headers #{headers.inspect}")
|
114
|
-
if headers["destination"] == "#{queue_partial_url}/index"
|
115
|
-
start_timer = Time.new
|
116
|
-
@chef_search_indexer.add(object)
|
117
|
-
@chef_search_indexer.commit
|
118
|
-
final_timer = Time.new
|
119
|
-
Chef::Log.info("Indexed object from #{headers['destination']} in #{final_timer - start_timer} seconds")
|
120
|
-
elsif headers["destination"] == "#{queue_partial_url}/remove"
|
121
|
-
start_timer = Time.new
|
122
|
-
@chef_search_indexer.delete(object)
|
123
|
-
@chef_search_indexer.commit
|
124
|
-
final_timer = Time.new
|
125
|
-
Chef::Log.info("Removed object from #{headers['destination']} in #{final_timer - start_timer} seconds")
|
126
|
-
end
|
127
|
-
end
|
128
|
-
rescue SystemExit => e
|
129
|
-
raise
|
130
|
-
rescue Exception => e
|
131
|
-
if Chef::Config[:interval]
|
132
|
-
Chef::Log.error("#{e.class}")
|
133
|
-
Chef::Log.fatal("#{e}\n#{e.backtrace.join("\n")}")
|
134
|
-
Chef::Log.fatal("Sleeping for #{Chef::Config[:delay]} seconds before trying again")
|
135
|
-
sleep Chef::Config[:delay]
|
136
|
-
retry
|
137
|
-
else
|
138
|
-
raise
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
data/lib/chef/queue.rb
DELETED
@@ -1,145 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
-
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
4
|
-
# License:: Apache License, Version 2.0
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
#
|
18
|
-
|
19
|
-
require 'chef/mixin/params_validate'
|
20
|
-
require 'json'
|
21
|
-
require 'stomp'
|
22
|
-
|
23
|
-
class Chef
|
24
|
-
class Queue
|
25
|
-
|
26
|
-
@client = nil
|
27
|
-
@queue_retry_delay = Chef::Config[:queue_retry_delay]
|
28
|
-
@queue_retry_count = Chef::Config[:queue_retry_count]
|
29
|
-
|
30
|
-
class << self
|
31
|
-
include Chef::Mixin::ParamsValidate
|
32
|
-
|
33
|
-
def connect
|
34
|
-
queue_user = Chef::Config[:queue_user]
|
35
|
-
queue_password = Chef::Config[:queue_password]
|
36
|
-
queue_host = Chef::Config[:queue_host]
|
37
|
-
queue_port = Chef::Config[:queue_port]
|
38
|
-
queue_retries = 1 unless queue_retries
|
39
|
-
|
40
|
-
# Connection.open(login = "", passcode = "", host='localhost', port=61613, reliable=FALSE, reconnectDelay=5)
|
41
|
-
@client = Stomp::Connection.open(queue_user, queue_password, queue_host, queue_port, false)
|
42
|
-
|
43
|
-
rescue Errno::ECONNREFUSED
|
44
|
-
Chef::Log.error("Connection refused connecting to stomp queue at #{queue_host}:#{queue_port}, retry #{queue_retries}/#{@queue_retry_count}")
|
45
|
-
sleep(@queue_retry_delay)
|
46
|
-
retry if (queue_retries += 1) < @queue_retry_count
|
47
|
-
raise Errno::ECONNREFUSED, "Connection refused connecting to stomp queue at #{queue_host}:#{queue_port}, giving up"
|
48
|
-
rescue Timeout::Error
|
49
|
-
Chef::Log.error("Timeout connecting to stomp queue at #{queue_host}:#{queue_port}, retry #{queue_retries}/#{@queue_retry_count}")
|
50
|
-
sleep(@queue_retry_delay)
|
51
|
-
retry if (queue_retries += 1) < @queue_retry_count
|
52
|
-
raise Timeout::Error, "Timeout connecting to stomp queue at #{queue_host}:#{queue_port}, giving up"
|
53
|
-
else
|
54
|
-
queue_retries = 1 # reset the number of retries on success
|
55
|
-
end
|
56
|
-
|
57
|
-
def make_url(type, name)
|
58
|
-
validate(
|
59
|
-
{
|
60
|
-
:queue_type => type.to_sym,
|
61
|
-
:queue_name => name.to_sym,
|
62
|
-
},
|
63
|
-
{
|
64
|
-
:queue_type => {
|
65
|
-
:equal_to => [ :topic, :queue ],
|
66
|
-
},
|
67
|
-
:queue_name => {
|
68
|
-
:kind_of => [ String, Symbol ],
|
69
|
-
}
|
70
|
-
}
|
71
|
-
)
|
72
|
-
if Chef::Config[:queue_prefix]
|
73
|
-
queue_prefix = Chef::Config[:queue_prefix]
|
74
|
-
queue_url = "/#{type}/#{queue_prefix}/chef/#{name}"
|
75
|
-
else
|
76
|
-
queue_url = "/#{type}/chef/#{name}"
|
77
|
-
end
|
78
|
-
queue_url
|
79
|
-
end
|
80
|
-
|
81
|
-
def subscribe(type, name)
|
82
|
-
queue_url = make_url(type, name)
|
83
|
-
Chef::Log.debug("Subscribing to #{queue_url}")
|
84
|
-
connect if @client == nil
|
85
|
-
@client.subscribe(queue_url)
|
86
|
-
end
|
87
|
-
|
88
|
-
def send_msg(type, name, msg)
|
89
|
-
queue_retries = 1 unless queue_retries
|
90
|
-
validate(
|
91
|
-
{
|
92
|
-
:message => msg,
|
93
|
-
},
|
94
|
-
{
|
95
|
-
:message => {
|
96
|
-
:respond_to => :to_json
|
97
|
-
}
|
98
|
-
}
|
99
|
-
)
|
100
|
-
queue_url = make_url(type, name)
|
101
|
-
json = msg.to_json
|
102
|
-
connect if @client == nil
|
103
|
-
Chef::Log.debug("Sending to #{queue_url}: #{json}")
|
104
|
-
begin
|
105
|
-
@client.send(queue_url, json)
|
106
|
-
rescue Errno::EPIPE
|
107
|
-
Chef::Log.debug("Lost connection to stomp queue, reconnecting")
|
108
|
-
connect
|
109
|
-
retry if (queue_retries += 1) < @queue_retry_count
|
110
|
-
raise Errno::EPIPE, "Lost connection to stomp queue, giving up"
|
111
|
-
else
|
112
|
-
queue_retries = 1 # reset the number of retries on success
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
def receive_msg
|
117
|
-
connect if @client == nil
|
118
|
-
begin
|
119
|
-
raw_msg = @client.receive()
|
120
|
-
Chef::Log.debug("Received Message from #{raw_msg.headers["destination"]} containing: #{raw_msg.body}")
|
121
|
-
rescue
|
122
|
-
Chef::Log.debug("Received nil message from stomp, retrying")
|
123
|
-
retry
|
124
|
-
end
|
125
|
-
msg = JSON.parse(raw_msg.body)
|
126
|
-
return msg, raw_msg.headers
|
127
|
-
end
|
128
|
-
|
129
|
-
def poll_msg
|
130
|
-
connect if @client == nil
|
131
|
-
raw_msg = @client.poll()
|
132
|
-
if raw_msg
|
133
|
-
msg = JSON.parse(raw_msg.body)
|
134
|
-
else
|
135
|
-
nil
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
def disconnect
|
140
|
-
raise ArgumentError, "You must call connect before you can disconnect!" unless @client
|
141
|
-
@client.disconnect
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|