/
smartos-gz-fat.erb
104 lines (87 loc) · 3.36 KB
/
smartos-gz-fat.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# Chef Custom Bootstrap for SmartOS (GZ) Using Joyent Ops Fat Client
#
bash -c '
<%= "export http_proxy=\"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] -%>
if [ ! -f /opt/chef/bin/chef-client ]; then
cd /tmp && /usr/bin/curl -Os http://8.12.35.49/smartos/Chef-fatclient-SmartOS-10.14.2.tar.bz2
cd / && /usr/bin/gtar xfj /tmp/Chef-fatclient-SmartOS-10.14.2.tar.bz2
cp /usr/bin/gtar /opt/chef/bin/tar
fi
mkdir -p /var/chef /opt/custom/smf 2>/dev/null
## Copy in the Validation Key
(
cat <<'EOP'
<%= validation_key %>
EOP
) > /tmp/validation.pem
/usr/xpg4/bin/awk NF /tmp/validation.pem > /var/chef/validation.pem
rm /tmp/validation.pem
## Copy in Data Bag Secret
<% if @chef_config[:encrypted_data_bag_secret] -%>
(
cat <<'EOP'
<%= encrypted_data_bag_secret %>
EOP
) > /tmp/encrypted_data_bag_secret
/usr/xpg4/bin/awk NF /tmp/encrypted_data_bag_secret > /var/chef/encrypted_data_bag_secret
rm /tmp/encrypted_data_bag_secret
<% end -%>
## Copy in Client Configuration
(
cat <<'EOP'
validation_key "/var/chef/validation.pem"
client_key "/var/chef/client.pem"
<%= config_content %>
EOP
) > /var/chef/client.rb
## Copy in Initial Run List
(
cat <<'EOP'
<%= { "run_list" => @run_list }.to_json %>
EOP
) > /var/chef/first-boot.json
## Copy in the SMF XML
(
cat <<'EOX'
<?xml version='1.0'?>
<!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'>
<service_bundle type='manifest' name='export'>
<service name='application/management/chef-client' type='service' version='0'>
<create_default_instance enabled='true'/>
<single_instance/>
<dependency name='milestone' grouping='require_all' restart_on='none' type='service'>
<service_fmri value='svc:/milestone/sysconfig'/>
</dependency>
<dependency name='fs-local' grouping='require_all' restart_on='none' type='service'>
<service_fmri value='svc:/system/filesystem/local'/>
</dependency>
<dependency name='name-services' grouping='optional_all' restart_on='none' type='service'>
<service_fmri value='svc:/milestone/name-services'/>
</dependency>
<dependency name='network' grouping='require_all' restart_on='restart' type='service'>
<service_fmri value='svc:/milestone/network'/>
</dependency>
<dependency name='config-file' grouping='require_all' restart_on='refresh' type='path'>
<service_fmri value='file://localhost/var/chef/client.rb'/>
</dependency>
<exec_method name='start' type='method' exec='/opt/chef/bin/chef-client --daemonize --config /var/chef/client.rb --logfile /var/log/chef.log' timeout_seconds='60'>
<method_context working_directory="/var/chef">
<method_credential user="root" group="root" />
<method_environment>
<envvar name="PATH" value="/opt/chef/bin:/usr/bin:/usr/sbin:/smartdc/bin:/opt/local/bin:/opt/local/sbin" />
</method_environment>
</method_context>
</exec_method>
<exec_method name='stop' type='method' exec=':kill' timeout_seconds='60'/>
<template>
<common_name>
<loctext xml:lang='C'>Opscode Chef Client</loctext>
</common_name>
</template>
</service>
</service_bundle>
EOX
) > /opt/custom/smf/chef-client.xml
## Process first run, if successful enable the chef-client in daemon mode.
/opt/chef/bin/chef-client --config /var/chef/client.rb -j /var/chef/first-boot.json && \
/usr/sbin/svccfg import /opt/custom/smf/chef-client.xml'