Created
February 18, 2015 22:20
-
-
Save popsikle/b228cc746f80066d654c to your computer and use it in GitHub Desktop.
CoreOS One APP_ENV to rule them all
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Crick API | |
After=docker.service | |
Requires=docker.service | |
[Service] | |
User=core | |
EnvironmentFile=/etc/environment | |
TimeoutStartSec=0 | |
ExecStartPre=-/usr/bin/docker kill dev-crick-api-A-%i | |
ExecStartPre=-/usr/bin/docker rm dev-crick-api-A-%i | |
ExecStartPre=/usr/bin/docker pull quay.io/keep/crick | |
ExecStart=/usr/bin/docker run -e APP_ENV=dev -e ETCDCTL_PEERS=http://${COREOS_PRIVATE_IPV4}:4001 --rm --name dev-crick-api-A-%i -p 9000 -v /dist:/dist quay.io/keep/crick /scripts/api.sh | |
ExecStop=/usr/bin/docker stop dev-crick-api-A-%i | |
[X-Fleet] | |
Conflicts=dev-crick-api-A@*.service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
bash /scripts/config.sh | |
if [ $? -ne 0 ]; then | |
echo "ERROR: Autoconfiguration FAILED" | |
exit 1 | |
fi | |
bash /scripts/fetch.sh | |
if [ $? -ne 0 ]; then | |
echo "ERROR: Fetching Application FAILED" | |
exit 1 | |
fi | |
if [ ! "$(pidof /usr/sbin/pgbouncer)" ]; then | |
su postgres /bin/bash -c "/usr/sbin/pgbouncer -d /etc/pgbouncer/pgbouncer.ini" | |
fi | |
su crick /bin/bash -c "/usr/local/bin/uwsgi --ini /opt/crick/etc/uwsgi_api.ini" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Sometimes we must wait for networking, sigh | |
echo -n "Waiting for resolvers to come up ..." | |
count=0 | |
ping -q -c 1 google.com > /dev/null 2> /dev/null | |
while [ $? -ne 0 ]; do | |
count=$((count+1)) | |
if [ $count -gt 40 ]; then | |
echo "FAIL" | |
exit 1 | |
fi | |
sleep .5 | |
echo -n "." | |
ping -q -c 1 google.com > /dev/null 2> /dev/null | |
done | |
echo "DONE" | |
#Make sure ETCD is up | |
echo -n "Waiting for ETCD Host ..." | |
count=0 | |
curl -X GET ${ETCDCTL_PEERS}/v2/stats/leader > /dev/null 2> /dev/null | |
while [ $? -ne 0 ]; do | |
count=$((count+1)) | |
if [ $count -gt 40 ]; then | |
echo "FAIL" | |
echo "ERROR: etcd peer is down, is ${ETCDCTL_PEERS} up?" | |
exit 1 | |
fi | |
sleep .5 | |
echo -n "." | |
curl -X GET ${ETCDCTL_PEERS}/v2/stats/leader > /dev/null 2> /dev/null | |
done | |
echo " DONE" | |
# Fetch encrypted data from etcd | |
export ACCOUNTS=`crypt get -secret-keyring ~/.secring.gpg -endpoint=${ETCDCTL_PEERS} /${APP_ENV}/apps/crick/accounts` | |
# Generate Templates | |
confd -onetime -prefix=/${APP_ENV} | |
# Remove encrypted data from env | |
unset ACCOUNTS | |
# File Perms (damn you confd) | |
chown -R postgres:postgres /etc/pgbouncer | |
chmod 640 /etc/pgbouncer/userlist.txt | |
chown -R crick:crick /opt/crick/etc/crick_override.yaml | |
chmod 640 /opt/crick/etc/crick_override.yaml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment