I have written a cloudformation script using Ubuntu 16.04 and have implemented the userdata/cloud init scripts. However, when it tries to start cfn-hup it fails based on the init.d script. The script is below. I have searched everywhere to understand the Default start levels, and I could edit them manually but I can't find anywhere in any other templates this is necessary so I must be doing something else wrong?! Script below.
If anyone has ideas please share, many thanks!
2018-01-17 11:58:36,562 P7799 [INFO] Command 01_enable_cfn_hup
2018-01-17 11:58:36,665 P7799 [INFO] -----------------------Command Output-----------------------
2018-01-17 11:58:36,665 P7799 [INFO] Synchronizing state of cfn-hup.service with SysV init with /lib/systemd/systemd-sysv-install...
2018-01-17 11:58:36,665 P7799 [INFO] Executing /lib/systemd/systemd-sysv-install enable cfn-hup
2018-01-17 11:58:36,665 P7799 [INFO] insserv: warning: script 'cfn-hup' missing LSB tags and overrides
2018-01-17 11:58:36,665 P7799 [INFO] update-rc.d: error: cfn-hup Default-Start contains no runlevels, aborting.
2018-01-17 11:58:36,665 P7799 [INFO] ------------------------------------------------------------
2018-01-17 11:58:36,665 P7799 [ERROR] Exited with error code 1
Script:
AppServerInstanceLaunchConfig:
Type: 'AWS::AutoScaling::LaunchConfiguration'
DependsOn: VPCGatewayAttachment
Properties:
AssociatePublicIpAddress: true
KeyName: !Ref KeyPairName
ImageId: !FindInMap
- AWSRegionArch2AMI
- !Ref 'AWS::Region'
- !FindInMap
- AWSInstanceType2Arch
- !Ref InstanceTypeParam
- Arch
InstanceType: !Ref InstanceTypeParam
SecurityGroups:
- !Ref PubSubnetSecurityGroup
UserData: !Base64
'Fn::Join':
- ''
- - |
#!/bin/bash -xe
- |
# Install AWS cfn-bootstrap utilities
apt-get update
apt-get -y install python-pip
- >
pip install
https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz
- |
ln -s /usr/local/bin/cfn-hup /etc/init.d/
- |
chmod 775 /etc/init.d/cfn-hup
- |
chown root:root /etc/init.d/cfn-hup
- /usr/local/bin/cfn-init
- ' --stack '
- !Ref 'AWS::StackName'
- ' --resource AppServerInstanceLaunchConfig'
- ' --configsets SetupAppServer'
- ' --region '
- !Ref 'AWS::Region'
- |+
- /usr/local/bin/cfn-signal -e $? --stack
- !Ref 'AWS::StackName'
- ' --resource AppServerInstanceGroup'
- ' --region '
- !Ref 'AWS::Region'
Metadata:
'AWS::CloudFormation::Designer':
id: 7f848ae7-0378-4ac3-800c-1f4c1ad4de4c
'AWS::CloudFormation::Init':
configSets:
SetupAppServer:
- config1
config1:
packages:
apt:
git: []
php: []
apache2: []
apt-transport-https: []
ca-certificates: []
curl: []
software-properties-common: []
commands:
01_enable_cfn_hup:
command: systemctl enable cfn-hup.service
02_start_cfn_hup:
command: systemctl start cfn-hup.service
files:
/etc/cfn/cfn-hup.conf:
content: !Join
- ''
- - |-
[main]
stack=
- !Ref 'AWS::StackName'
- |-
region=
- !Ref 'AWS::Region'
mode: '000400'
owner: root
group: root
/etc/cfn/hooks.d/cfn-auto-reloader.conf:
content: !Join
- ''
- - |
[cfn-auto-reloader-hook]
- |
triggers=post.update
- >
path=Resources.LaunchConfig.Metadata.AWS::CloudFormation::Init
- 'action=/usr/local/bin/cfn-init -v --stack '
- !Ref 'AWS::StackName'
- ' --resource AppServerInstanceLaunchConfig --region '
- !Ref 'AWS::Region'
- ''
- |
runas=root
/lib/systemd/system/cfn-hup.service:
content: !Join
- ''
- - |
[Unit]
- |+
Description=cfn-hup daemon
- |
[Service]
- |
Type=simple
- |
ExecStart=/usr/local/bin/cfn-hup
- |+
Restart=always
- |
[Install]
- WantedBy=multi-user.target
services:
sysvinit:
apache2:
enabled: true
ensureRunning: true
cfn-hup:
enabled: true
ensureRunning: true
files:
- /etc/cfn/cfn-hup.conf
- /etc/cfn/hooks.d/cfn-auto-reloader.conf