~johnsca/charms/trusty/tomcat/explicit

« back to all changes in this revision

Viewing changes to hooks/terracotta.sh

  • Committer: matthew.bruzek at canonical
  • Date: 2014-03-17 23:06:03 UTC
  • Revision ID: matthew.bruzek@canonical.com-20140317230603-9a3jwpe5oqy0h9lb
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# This file contains the terracotta functions for the tomcat charm.
 
2
 
 
3
add_jndi_terracotta_server () {
 
4
  juju-log "Adding terracotta server ${JUJU_REMOTE_UNIT} to jndi configuration"
 
5
  add_file_row "/etc/${VERSION}/${REMOTE_SERVICE}.jndi_tc" \
 
6
   "${JUJU_REMOTE_UNIT}" `relation-get private-address`:9510
 
7
}
 
8
 
 
9
add_terracotta_server () {
 
10
  juju-log "Adding terracotta server ${JUJU_REMOTE_UNIT} to configuration"
 
11
  add_file_row /etc/${VERSION}/terracotta.servers "${JUJU_REMOTE_UNIT}" \
 
12
   `relation-get private-address`:9510
 
13
}
 
14
 
 
15
configure_jndi_terracotta () {
 
16
  # Get the path of the .d directory where the server.xml file is built.
 
17
  server_dir=`dotdee -d /etc/${VERSION}/server.xml`
 
18
  rm -f "${server_dir}"/12-terracotta-*
 
19
  # Get the path of the .d directory where the context.xml file is built.
 
20
  context_dir=`dotdee -d /etc/${VERSION}/context.xml`
 
21
  rm -f "${context_dir}"/15-terracotta-*
 
22
  for name in "${!jndi_terracotta_service[@]}"; do
 
23
    service=${jndi_terracotta_service[${name}]}
 
24
    if [ -n "${service}" ] && [ -e "/etc/${VERSION}/${service}.jndi_tc" ]; then
 
25
      jndi_name=`escape_name ${name}`
 
26
      (umask 0027; config_environment "${name}" `format_terracotta_servers "/etc/${VERSION}/${service}.jndi_tc"` java.lang.String > "${server_dir}/12-terracotta-${jndi_name}")
 
27
      config_resource_link "${name}" java.lang.String \
 
28
        > "${context_dir}/15-terracotta-${jndi_name}"
 
29
    fi
 
30
  done
 
31
  # The dotdee update function performs an alphanumeric concatenation of all
 
32
  # files in the managed collection in /etc/dotdee/etc/path/to/some.conf.d/*
 
33
  # to the build target file /etc/dotdee/etc/path/to/some.conf
 
34
  dotdee -u /etc/${VERSION}/server.xml
 
35
  dotdee -u /etc/${VERSION}/context.xml
 
36
}
 
37
 
 
38
config_terracotta_valve () {
 
39
  echo "  <Valve className=\"$1\" tcConfigUrl=\"$2\"/>"
 
40
}
 
41
 
 
42
configure_terracotta () {
 
43
  juju-log "Configuring terracotta"
 
44
  # Get the path of the .d directory where the context.xml file is built.
 
45
  dir=`dotdee -d /etc/${VERSION}/context.xml`
 
46
  if [ ${VERSION} != tomcat6 ]; then
 
47
    class=org.terracotta.session.TerracottaTomcat70xSessionValve
 
48
  else
 
49
    class=org.terracotta.session.TerracottaTomcat60xSessionValve
 
50
  fi
 
51
  config_terracotta_valve ${class} `format_terracotta_servers /etc/${VERSION}/terracotta.servers` \
 
52
    > "${dir}/45-terracotta"
 
53
  # Build the target file /etc/dotdee/etc/tomcatX/context.xml from context.xml.d
 
54
  dotdee -u /etc/${VERSION}/context.xml
 
55
}
 
56
 
 
57
create_terracotta_log_directory () {
 
58
  if [ ! -e /var/log/terracotta ]; then
 
59
    (umask 0027; mkdir /var/log/terracotta)
 
60
    chown ${VERSION}:adm /var/log/terracotta
 
61
  fi
 
62
}
 
63
 
 
64
format_terracotta_servers () {
 
65
  cut -f 2 "$1" | cut -d $'\n' -f 1- --output-delimiter=,
 
66
}
 
67
 
 
68
install_terracotta () {
 
69
  if [ ! -e /usr/local/lib/terracotta ]; then
 
70
    juju-log "Downloading terracotta..."
 
71
    url=`config-get terracotta_url`
 
72
    wget -nv -c -P "${TEMP}" "${url}"
 
73
    dist=`basename ${url}`
 
74
    check_checksum "${TEMP}/${dist}" `config-get terracotta_md5`
 
75
 
 
76
    juju-log "Installing terracotta..."
 
77
    tar -C /usr/local/lib -xzf "${TEMP}/${dist}"
 
78
    (cd /usr/local/lib; ln -s terracotta-* terracotta)
 
79
    (cd /usr/share/${VERSION}/lib; ln -s ../../../local/lib/terracotta/sessions/terracotta-session-*.jar)
 
80
    (cd /usr/share/${VERSION}/lib; ln -s ../../../local/lib/terracotta/common/terracotta-toolkit-*.jar)
 
81
  fi
 
82
}
 
83
 
 
84
parse_jndi_terracotta_config () {
 
85
  unset jndi_terracotta_service
 
86
  declare -Ag jndi_terracotta_service
 
87
  IFS="," read -a tokens <<<"`config-get jndi_terracotta_config`"
 
88
  for token in "${tokens[@]}"; do
 
89
    IFS=":" read name service <<<"${token}"
 
90
    if [ -n "${name}" ] && [ -n "${service}" ]; then
 
91
      jndi_terracotta_service[${name}]=${service}
 
92
    fi
 
93
  done
 
94
}
 
95
 
 
96
remove_jndi_terracotta () {
 
97
  juju-log "Removing terracotta jndi configuration"
 
98
  rm -f "/etc/${VERSION}/${REMOTE_SERVICE}.jndi_tc"
 
99
}
 
100
 
 
101
remove_jndi_terracotta_server () {
 
102
  juju-log "Removing terracotta server ${JUJU_REMOTE_UNIT} from jndi configuration"
 
103
  remove_file_row "/etc/${VERSION}/${REMOTE_SERVICE}.jndi_tc" "${JUJU_REMOTE_UNIT}"
 
104
}
 
105
 
 
106
remove_terracotta () {
 
107
  juju-log "Removing terracotta"
 
108
  rm -f /etc/${VERSION}/terracotta.servers
 
109
  # Get the path of the .d directory where the context.xml file is built.
 
110
  dir=`dotdee -d /etc/${VERSION}/context.xml`
 
111
  rm -f "${dir}/45-terracotta"
 
112
  # Build the target file /etc/dotdee/etc/tomcatX/context.xml from context.xml.d
 
113
  dotdee -u /etc/${VERSION}/context.xml
 
114
}
 
115
 
 
116
remove_terracotta_server () {
 
117
  juju-log "Removing terracotta server ${JUJU_REMOTE_UNIT} from configuration"
 
118
  remove_file_row /etc/${VERSION}/terracotta.servers "${JUJU_REMOTE_UNIT}"
 
119
}