#cloud-boothook #!/bin/bash set -x # This EC2 user-data file will run a Mapserver docker container. # Still working on getting it to reboot properly. See this link for more info on user-data scripts # http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html#user-data-shell-scripts # Because this setup uses data stored in an S3 bucket located in the standard region, it needs to be run in us-east-1 (Virginia Region). # It mounts S3 data by using danilop/yas3fs. USDA CONUS NAIP data, Mapfile and shapefile indexes are made available to Mapserver in this way. # Just running this instance will give you access to all of the NAIP data via the EC2 instance's filesystem. # One caveat is that the combination of mapfile and UTM projected geotifs only supports WMS requests near native 1m/pixel resolution or level 17, # meaning it gets slow at level 15. # For the container to work, you need to run this using an EC2 type that includes ephemeral storage. Local SSDs. It works with m3.medium, # but something larger such as c3.2xlarge is better. exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1 # fix for "unable to resolve host" error even when dns hostnames/resolution are turned on for VPC echo "127.0.0.1 $(hostname)" >> /etc/hosts function mountbucket { echo "Running Yas3fs" # use yas3fs to mount s3 buckets # first one is CONUS NAIP in experimental Amazon S3 bucket named AWS. The bucket is marked 'requester pays' yas3fs --mkdir --requester-pays --no-metadata --cache-check=100 --cache-path=/mnt/cache/naip --cache-disk-size 102400 --download-num=16 s3://aws-naip /data/naip # second bucket has mapfiles and shapefile indexes to RGB files in aws-naip yas3fs --mkdir --no-metadata --cache-check=100 --cache-path=/mnt/cache/map --cache-disk-size 102400 s3://aws-naip-config /data/map } if [ -x "$(command -v docker)" ] then echo "Already ran" # Use yas3fs to mount S3 buckets mountbucket else echo "Running first time install scripts." apt-get update -y DEBIAN_FRONTEND=noninteractive apt-get install -y fuse python-pip linux-image-extra-$(uname -r) pip install yas3fs # assume root installation # fuse config sed -i'' 's/^# *user_allow_other/user_allow_other/' /etc/fuse.conf chmod a+r /etc/fuse.conf # use yas3fs to mount S3 buckets mountbucket # install docker modprobe aufs #curl -sSL https://get.docker.com/ | sh wget -O docker.deb https://apt.dockerproject.org/repo/pool/main/d/docker-engine/docker-engine_1.9.1-0~trusty_amd64.deb dpkg -i docker.deb # run mwkorver/docker-mapserver7 image from docker hub docker run --detach --publish 80:8080 --restart="always" -v /data/naip:/data/naip:ro -v /data/map:/data/map --name mapserver mwkorver/mapserver7 # log file setup in the now running mapserver container # the location of the log file is dependent on what you specify in your map file. # looks like - CONFIG "MS_ERRORFILE" "/var/log/ms_error.log" in map file docker exec mapserver touch /var/log/ms_error.log docker exec mapserver chown www-data /var/log/ms_error.log docker exec mapserver chmod 644 /var/log/ms_error.log fi