Skip to content

Instantly share code, notes, and snippets.

@mark-schaal
Created July 27, 2017 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mark-schaal/37deb949ec518bdf36e75d650d90e92b to your computer and use it in GitHub Desktop.
Save mark-schaal/37deb949ec518bdf36e75d650d90e92b to your computer and use it in GitHub Desktop.
rEC2InstanceAtlassianConfluence:
Type: AWS::EC2::Instance
Metadata:
AWS::CloudFormation::Init:
configSets:
bootstrap:
- security-updates
- perl-installation
- psql-tools-installation
- mount-ebs
- confluence-installation
- confluence-modify-serverXML
- cloudwatch-monitoring-init
security-updates:
commands:
0-write-test-file:
command: touch ~/security-updates.txt
1-yum-updates:
command: sudo yum -y update
perl-installation:
packages:
yum:
perl-Switch: []
perl-DateTime: []
perl-Sys-Syslog: []
perl-LWP-Protocol-https: []
psql-tools-installation:
packages:
yum:
postgresql95: []
postgresql95-devel: []
postgresql95-libs: []
mount-ebs:
commands:
mount1:
command: mkfs -t ext4 /dev/xvdf
mount2:
command: mkdir /atlassian
mount3:
command: mount /dev/xvdf /atlassian
mount4:
command: echo "/dev/xvdf /atlassian ext4 defaults,nofail 0 2"
>> /etc/fstab
confluence-installation:
packages:
yum:
tomcat-native: []
groups: {}
users: {}
sources: {}
files:
"/tmp/response.varfile":
content:
Fn::Join:
- ''
- - "#install4j response file for Confluence 6.0.3\n"
- 'launch.application$Boolean=true
'
- 'rmiPort$Long=8000
'
- 'app.install.service$Boolean=true
'
- 'existingInstallationDir=/opt/Confluence
'
- 'sys.confirmedUpdateInstallationString=false
'
- 'sys.languageId=en
'
- 'sys.installationDir=/opt/atlassian/confluence
'
- 'app.confHome=/atlassian/application-data/confluence
'
- 'executeLauncherAction$Boolean=true
'
- 'httpPort$Long=8090
'
- 'portChoice=default
'
mode: '000644'
owner: root
group: root
commands:
0-write-test-file:
command: touch ~/confluence-6.0.3-download.txt
1-download-confluence-6.0.3:
command: sudo wget https://www.atlassian.com/software/confluence/downloads/binary/atlassian-confluence-6.0.3-x64.bin
cwd: "/tmp"
2-make-confluence-6.0.3-executable:
command: sudo chmod a+x atlassian-confluence-6.0.3-x64.bin
cwd: "/tmp"
3-install-confluence-6.0.3:
command: sudo ./atlassian-confluence-6.0.3-x64.bin -q -varfile response.varfile
cwd: "/tmp"
service: {}
confluence-modify-serverXML:
packages:
yum:
xmlstarlet: []
commands:
modifyConf1:
command: xmlstarlet ed --inplace --insert "/Server/Service/Connector"
--type attr -n scheme -v https /opt/atlassian/confluence/server.xml
modifyConf2:
command: xmlstarlet ed --inplace --insert "/Server/Service/Connector"
--type attr -n proxyPort -v 443 /opt/atlassian/confluence/server.xml
modifyConf3:
command: xmlstarlet ed --inplace --insert "/Server/Service/Connector"
--type attr -n secure -v true /opt/atlassian/confluence/server.xml
modifyConf4:
command: service confluence restart
cloudwatch-monitoring-init:
commands:
0-CloudWatchScriptDownload:
command: wget -O /tmp/cloudwatch-monitoring.zip https://ec2-downloads.s3.amazonaws.com/cloudwatch-samples/CloudWatchMonitoringScripts-v1.1.0.zip
1-CloudWatchScriptExtration:
command: unzip /tmp/cloudwatch-monitoring.zip -d /tmp/
2-CronPatternDefinition:
command: echo '*/5 * * * * /tmp/aws-scripts-mon/mon-put-instance-data.pl
--mem-used --mem-avail --swap-used --disk-space-util --disk-space-used
--disk-space-avail --disk-path=/ --disk-path=/atlassian' >>/etc/cron.cloudwatch
3-CronTabIntegration:
command: crontab /etc/cron.cloudwatch
@antaltshul
Copy link

antaltshul commented Jul 27, 2017

To preserve string-encapsulated newlines (eg. '
') with \n, as it appears to be in the source JSON, use

Most readable (with concession to preserving last new line)

"/tmp/response.varfile":
  content:
    !Join
    - '\n'
    - - "#install4j response file for Confluence 6.0.3"
      - 'launch.application$Boolean=true'
      - 'rmiPort$Long=8000'
      - 'app.install.service$Boolean=true'
      - 'existingInstallationDir=/opt/Confluence'
      - 'sys.confirmedUpdateInstallationString=false'
      - 'sys.languageId=en'
      - 'sys.installationDir=/opt/atlassian/confluence'
      - 'app.confHome=/atlassian/application-data/confluence'
      - 'executeLauncherAction$Boolean=true'
      - 'httpPort$Long=8090'
      - 'portChoice=default'
      - ''
  mode: '000644'
  owner: root
  group: root

(terminating newline preserved manually, but if unnecessary this would appear cleaner without it)
To preserve the original's presentation (in code, in addition to the result), use

"/tmp/response.varfile":
  content:
    !Join
    - ''
    - - "#install4j response file for Confluence 6.0.3\n"
      - 'launch.application$Boolean=true\n'
      - 'rmiPort$Long=8000\n'
      - 'app.install.service$Boolean=true\n'
      - 'existingInstallationDir=/opt/Confluence\n'
      - 'sys.confirmedUpdateInstallationString=false\n'
      - 'sys.languageId=en\n'
      - 'sys.installationDir=/opt/atlassian/confluence\n'
      - 'app.confHome=/atlassian/application-data/confluence\n'
      - 'executeLauncherAction$Boolean=true\n'
      - 'httpPort$Long=8090\n'
      - 'portChoice=default\n'
  mode: '000644'
  owner: root
  group: root

The multi-line commands (e.g.

              command: echo '*/5 * * * * /tmp/aws-scripts-mon/mon-put-instance-data.pl
                --mem-used --mem-avail --swap-used --disk-space-util --disk-space-used
                --disk-space-avail --disk-path=/ --disk-path=/atlassian'  >>/etc/cron.cloudwatch

should parse correctly, but are kinda visually troubling due to the --. Just an observation, no action required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment