From f719fc14f7fff2e6b4c765a9cf3e1538b42eac85 Mon Sep 17 00:00:00 2001 From: kev Date: Thu, 1 Oct 2015 12:27:32 +0800 Subject: [PATCH] add confd config --- etcd-arm/bin/shadowsocks.sh | 35 +++++++++++++++++++ etcd-arm/etc/confd/conf.d/shadowsocks.toml | 7 ++++ etcd-arm/etc/confd/confd.toml | 6 ++++ .../etc/confd/templates/shadowsocks.json.tmpl | 16 +++++++++ etcd-arm/etc/systemd/system/confd.service | 9 +++++ 5 files changed, 73 insertions(+) create mode 100755 etcd-arm/bin/shadowsocks.sh create mode 100644 etcd-arm/etc/confd/conf.d/shadowsocks.toml create mode 100644 etcd-arm/etc/confd/confd.toml create mode 100644 etcd-arm/etc/confd/templates/shadowsocks.json.tmpl create mode 100644 etcd-arm/etc/systemd/system/confd.service diff --git a/etcd-arm/bin/shadowsocks.sh b/etcd-arm/bin/shadowsocks.sh new file mode 100755 index 0000000..9af532f --- /dev/null +++ b/etcd-arm/bin/shadowsocks.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# +# free shadowsocks +# + +{ + echo 'server,server_port,password,method,local_address,local_port,timeout' + curl -s 'http://www.ishadowsocks.com/' | + sed -n '/
/{/font/d;p}' | + grep -oP '(?<=

).*(?=

)' | + cut -d : -f 2 | + sed -e 'N;N;N;s/\n/,/g' \ + -e 's/$/,127.0.0.1/' \ + -e 's/$/,1080/' \ + -e 's/$/,300/' +} | + csvjson | + jq -c 'map( + .fast_open = true | + with_entries( + .key as $key | + if ((["server_port", "local_port", "timeout"] | index($key)) == null) + then + . + else + (.value |= tonumber) + end + ) + )[]' | + while read line + do + server=$(echo "$line" | jq -r .server) + etcdctl -C 192.168.1.228:2379 set "/services/shadowsocks/$server" "$line" + done + diff --git a/etcd-arm/etc/confd/conf.d/shadowsocks.toml b/etcd-arm/etc/confd/conf.d/shadowsocks.toml new file mode 100644 index 0000000..b9970ba --- /dev/null +++ b/etcd-arm/etc/confd/conf.d/shadowsocks.toml @@ -0,0 +1,7 @@ +[template] +src = "shadowsocks.json.tmpl" +dest = "/etc/shadowsocks/client.json" +keys = [ + "/services/shadowsocks" +] +#reload_cmd = "supervisorctl update" diff --git a/etcd-arm/etc/confd/confd.toml b/etcd-arm/etc/confd/confd.toml new file mode 100644 index 0000000..e8eb88e --- /dev/null +++ b/etcd-arm/etc/confd/confd.toml @@ -0,0 +1,6 @@ +backend = "etcd" +nodes = ["http://127.0.0.1:2379"] +confdir = "/etc/confd" +log-level = "info" +interval = 60 +watch = true diff --git a/etcd-arm/etc/confd/templates/shadowsocks.json.tmpl b/etcd-arm/etc/confd/templates/shadowsocks.json.tmpl new file mode 100644 index 0000000..ed1e925 --- /dev/null +++ b/etcd-arm/etc/confd/templates/shadowsocks.json.tmpl @@ -0,0 +1,16 @@ +{{ $base := "/services/shadowsocks" }} +{{ $name := index (ls $base) 2 }} +{{ with printf "%s/%s" $base $name | getv | json }} + +{ + "server": "{{ .server }}", + "server_port": {{ .server_port }}, + "local_address": "{{ .local_address }}", + "local_port": {{ .local_port }}, + "password": "{{ .password }}", + "method": "{{ .method }}", + "timeout": {{ .timeout }}, + "fast_open": {{ .fast_open }} +} + +{{ end }} diff --git a/etcd-arm/etc/systemd/system/confd.service b/etcd-arm/etc/systemd/system/confd.service new file mode 100644 index 0000000..3ef261c --- /dev/null +++ b/etcd-arm/etc/systemd/system/confd.service @@ -0,0 +1,9 @@ +[Unit] +Description=Confd Daemon +After=etcd.service + +[Service] +ExecStart=/usr/local/bin/confd --config-file /etc/confd/confd.toml + +[Install] +WantedBy=multi-user.target