Skip to content

Instantly share code, notes, and snippets.

@mattes
Last active August 29, 2015 14:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattes/11186897 to your computer and use it in GitHub Desktop.
Save mattes/11186897 to your computer and use it in GitHub Desktop.
#cloud-config
write_files:
- path: /home/core/journal2logentries.sh
permissions: '0744'
owner: root:root
content: |
#!/usr/bin/env bash
# CoreOS on Google Compute Engine: push systemd journal logs to logentries.com
# get your private token from logentries.com, see https://logentries.com/doc/input-token
# token in custom metadata?
token=$(curl --fail -s "http://metadata/computeMetadata/v1/instance/attributes/logentries-token" -H "X-Google-Metadata-Request: True")
if [[ ! $token ]]; then
# token in common metadata?
token=$(curl --fail -s "http://metadata/computeMetadata/v1/project/attributes/logentries-token" -H "X-Google-Metadata-Request: True")
fi
if [[ ! $token ]]; then
# we have a problem!
exit 10
fi
journalctl -o short -f | awk -v token=$token '{ print token, $0; fflush(); }' | ncat --ssl --ssl-verify data.logentries.com 20000
# should you have problems verifying SSL certificates, here are all certificates from logentries.com
# https://logentries.com/doc/certificates
# no ssl required?
# journalctl -o short -f | awk -v token=$token '{ print token, $0; fflush(); }' | ncat data.logentries.com 10000
coreos:
units:
- name: logentries.service
command: start
runtime: no
content: |
[Unit]
Description=Push journal logs to logentries.com
After=systemd-journald.service
After=systemd-networkd.service
[Service]
Restart=always
ExecStart=/bin/bash /home/core/journal2logentries.sh
[Install]
WantedBy=multi-user.target
- name: rotating-proxy.service
command: start
runtine: no
content: |
[Unit]
Description=Rotating Proxy container
After=docker.service
[Service]
Restart=always
ExecStart=/usr/bin/docker run -d -p 5566:5566 --env tors=25 --name rotating_proxy mattes/rotating-proxy
ExecStop=/bin/bash -c "/usr/bin/docker kill rotating_proxy || /usr/bin/sleep 2; /usr/bin/docker rm rotating_proxy"
[Install]
WantedBy=local.target
- name: scrapyd.service
command: start
runtine: no
content: |
[Unit]
Description=Scrapyd container
After=docker.service
After=rotating-proxy.service
[Service]
Restart=always
ExecStart=/bin/bash -c "/usr/bin/docker run -p 6801:6801 -d --name scrapyd --link "rotating_proxy:rp" mattes/scrapyd"
ExecStop=/bin/bash -c "/usr/bin/docker stop --time=120 scrapyd || /usr/bin/docker rm scrapyd"
[Install]
WantedBy=local.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment