22
22
chef-server-webui )
24
# Non-configurable parameters
28
# Configurable parameters
25
29
CHEF_VERSION=$(config-get chef-version)
26
30
HOST_IP=$(unit-get private-address)
27
31
WEBUI_PORT=$(config-get webui-port)
28
32
REST_API_PORT=$(config-get restapi-port)
29
33
SOLR_PORT=$(config-get solr-port)
30
RABBIT_PORT=$(config-get rabbit-port)
31
34
WEBUI_USER=$(config-get webui-user)
32
35
WEBUI_PW=$(config-get webui-pw)
33
AMQP_PW=$(config-get amqp-pw)
34
36
KNIFE_USER=$(config-get knife-user)
36
38
# Make sure we do not get any intercativity when installing packages
39
41
# Bring our little helpers into the frame
40
42
source ${CWD}/functions
44
mkdir -p `dirname ${CONFIG_CACHE}`
46
# IMPORTANT: if a new setting is added to config it must also be added here.
47
function dump_config ()
51
log_info "dumping config to '${target}'"
53
cat << __EOF__ > $target
65
# Determine whether current config is different from the last one.
66
function config_has_changed ()
68
if [ ! -f ${CONFIG_CACHE} ]
70
log_info "config cache '${CONFIG_CACHE}' does not exist"
74
dump_config "${CONFIG_CACHE}.tmp"
77
diff "${CONFIG_CACHE}" "${CONFIG_CACHE}.tmp" 1>/dev/null || rc=$?
80
log_info "config has changed"
83
log_info "config has not changed"
88
function assert_cfg_change_successful ()
94
log_error "unable to apply setting '${setting}'"
42
99
function set_service_config_data ()
44
101
log_info "setting user config data"
46
if [ -z "${WEBUI_USER}" ] || [ -z "${WEBUI_PW}" ];
104
local cfg_file=${CHEF_CFG_DIR}/webui.rb
106
if [ -z "${WEBUI_USER}" ]
48
log_info "null config setting"
108
log_info "WEBUI_USER is null"
50
local cfg_file=${CHEF_CFG_DIR}/webui.rb
52
110
key="web_ui_admin_user_name"
53
111
val="${WEBUI_USER}"
54
sed -e "s/${key} \".+?\"/${key} \"${val}\"/g" ${cfg_file} -i
112
sed -E "s/^${key}\s+\".+?\"/${key} \"${val}\"/g" ${cfg_file} -i
113
grep -qE "^${key}\s+\"${val}\"" ${cfg_file} || rc=$?
114
assert_cfg_change_successful $rc "webui-user"
117
if [ -z "${WEBUI_PW}" ]
119
log_info "WEBUI_PW is null"
56
121
key="web_ui_admin_default_password"
58
sed -e "s/${key} \".+?\"/${key} \"${val}\"/g" ${cfg_file} -i
123
sed -E "s/^${key}\s+\".+?\"/${key} \"${val}\"/g" ${cfg_file} -i
124
grep -qE "^${key}\s+\"${val}\"" ${cfg_file} || rc=$?
125
assert_cfg_change_successful $rc "webui-pw"
62
129
function setup_knife_user ()
132
id $KNIFE_USER || rc=$?
68
135
log_warning "user '${KNIFE_USER}' does not exist so cannot create knife config"
73
139
LOCAL_CHEF_DIR=/home/$KNIFE_USER/.chef
74
140
mkdir -p /home/$KNIFE_USER/.chef
95
161
log_info "installing '${JUJU_UNIT_NAME}' - chef-server version ${CHEF_VERSION}"
163
# IMPORTANT: this MUST be the first action
164
log_info "deleting config cache '${CONFIG_CACHE}'"
165
rm -f "${CONFIG_CACHE}"
97
167
echo "deb http://apt.opscode.com/ precise-${CHEF_VERSION} main" > ${APT_LIST_PATH}
99
169
mkdir -p /etc/apt/trusted.gpg.d
115
185
# Chef server installs a rabbitmq-server which will not install/run if the
116
186
# following is not set.
118
`grep -q 127.0.1.1 $HOSTS_FILE`
188
grep -q 127.0.1.1 $HOSTS_FILE || rc=$?
121
191
echo -e "\n# Added by juju charm for '${JUJU_UNIT_NAME}' install\n127.0.1.1 `hostname`" >> $HOSTS_FILE
125
194
apt-get install chef chef-server $APT_FLAGS
127
196
# Stop the service until we have finished configuring
129
197
upstart_stop chef-server
140
207
set_service_config_data
142
209
# Restart the chef-server and related services
144
210
check_upstart_services_running ${CORE_CHEF_SERVICES[@]}
147
212
log_info "service unit '${JUJU_UNIT_NAME}' installed."
148
213
hostname=$(unit-get public-address)
149
214
log_info "you can now 'juju expose' the '${JUJU_UNIT_NAME}' service and visit http://${hostname}:${WEBUI_PORT}"
216
# IMPORTANT: this MUST be the last action.
217
dump_config "${CONFIG_CACHE}"
152
220
function stop_all_services ()
154
222
for srvc in ${CORE_CHEF_SERVICES[@]}
157
224
upstart_stop $srvc
162
228
function service_start ()
164
230
log_info "starting service unit '${JUJU_UNIT_NAME}'"
166
231
check_upstart_services_running ${CORE_CHEF_SERVICES[@]}
168
232
log_info "service unit '${JUJU_UNIT_NAME}' started."
178
242
function service_upgrade ()
180
244
log_info "upgrading service unit '${JUJU_UNIT_NAME}'"
245
# Make sure the config really has changed befaore re-installing
246
if config_has_changed
251
log_info "config has not changed so skipping re-install - checking services instead"
252
check_upstart_services_running ${CORE_CHEF_SERVICES[@]}
183
254
log_info "service unit '${JUJU_UNIT_NAME}' upgraded."