{"action":"created","issue":{"url":"https://api.github.com/repos/hashicorp/consul/issues/1048","labels_url":"https://api.github.com/repos/hashicorp/consul/issues/1048/labels{/name}","comments_url":"https://api.github.com/repos/hashicorp/consul/issues/1048/comments","events_url":"https://api.github.com/repos/hashicorp/consul/issues/1048/events","html_url":"https://github.com/hashicorp/consul/issues/1048","id":89595562,"number":1048,"title":"Dynamic tags applied like health checks.","user":{"login":"fidian","id":428348,"avatar_url":"https://avatars.githubusercontent.com/u/428348?v=3","gravatar_id":"","url":"https://api.github.com/users/fidian","html_url":"https://github.com/fidian","followers_url":"https://api.github.com/users/fidian/followers","following_url":"https://api.github.com/users/fidian/following{/other_user}","gists_url":"https://api.github.com/users/fidian/gists{/gist_id}","starred_url":"https://api.github.com/users/fidian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fidian/subscriptions","organizations_url":"https://api.github.com/users/fidian/orgs","repos_url":"https://api.github.com/users/fidian/repos","events_url":"https://api.github.com/users/fidian/events{/privacy}","received_events_url":"https://api.github.com/users/fidian/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/hashicorp/consul/labels/thinking","name":"thinking","color":"eb6420"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-06-19T15:43:13Z","updated_at":"2015-06-23T15:05:21Z","closed_at":null,"body":"In issue #867 I suggested an idea to make tags that depend on the result of scripts, just like health checks.\r\n\r\nI run mongo in the cloud with multiple machines all spun up from the same image.  On boot they will query for mongodb.service.consul and join the cluster.  That all works flawlessly.  In being a good Ops person I have a cron job that will kill random machines in my infrastructure at random times.  It will eventually hit the mongodb master, the system will hiccup and a slave will be promoted automatically.  Life is fantastic.\r\n\r\nIn comes Legacy Software that must connect directly to the master mongodb instance.  I would like to have master.mongodb.service.consul resolve to the one IP of the master in the cluster.\r\n\r\nCurrent solution (runs via cron on all machines):\r\n1. Get my service definition through API\r\n2. Check the status of the cluster.  This determines if we should or should not have a tag.\r\n3. Determine if the service definition's tag list needs to be updated.\r\n4. If an update is required, POST data back to the API.\r\n\r\nIdeal solution:\r\n1. Set up my service definition with dynamic tags.\r\n2. Write a script that returns the status of the cluster, with an exit code of 0 meaning to apply the tag.\r\n3. Let consul update itself automatically.\r\n\r\nSample JSON (one static tag, one dynamic tag):\r\n\r\n    {\r\n        \"service\": {\r\n            \"name\": \"mongodb\",\r\n            \"tags\": [\r\n                \"fault-tolerant\",\r\n                {\r\n                    \"name\": \"master\",\r\n                    \"script\": \"/usr/local/bin/mongo-is-master.sh\",\r\n                    \"interval\": \"10s\"\r\n                }\r\n            ],\r\n            \"address\": \"127.0.0.1\",\r\n            \"port\": 8000,\r\n            \"checks\": [\r\n                {\r\n                    \"script\": \"/usr/local/bin/mongo-health-check.sh\",\r\n                    \"interval\": \"10s\"\r\n                }\r\n            ]\r\n        }\r\n    }\r\n\r\nThis sort of solution could apply to issue #155 and #867, and possibly other.\r\n"},"comment":{"url":"https://api.github.com/repos/hashicorp/consul/issues/comments/114536913","html_url":"https://github.com/hashicorp/consul/issues/1048#issuecomment-114536913","issue_url":"https://api.github.com/repos/hashicorp/consul/issues/1048","id":114536913,"user":{"login":"fidian","id":428348,"avatar_url":"https://avatars.githubusercontent.com/u/428348?v=3","gravatar_id":"","url":"https://api.github.com/users/fidian","html_url":"https://github.com/fidian","followers_url":"https://api.github.com/users/fidian/followers","following_url":"https://api.github.com/users/fidian/following{/other_user}","gists_url":"https://api.github.com/users/fidian/gists{/gist_id}","starred_url":"https://api.github.com/users/fidian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fidian/subscriptions","organizations_url":"https://api.github.com/users/fidian/orgs","repos_url":"https://api.github.com/users/fidian/repos","events_url":"https://api.github.com/users/fidian/events{/privacy}","received_events_url":"https://api.github.com/users/fidian/received_events","type":"User","site_admin":false},"created_at":"2015-06-23T15:05:21Z","updated_at":"2015-06-23T15:05:21Z","body":"@Kosta-Github asked how I manage to auto cluster my mongo instances.\r\n\r\n1.  Consul is hooked up through dnsmasq.\r\n2.  Consul is started before mongo.\r\n3.  The health check fails unless mongo reports success and mongo is part of a cluster.  This second part is vital - the health check fails until mongo is in a cluster.\r\n4.  The init script for mongo queries DNS for other members in the cluster.  This will only report mongo instances that are already in a replica set.\r\n    * If IPs are found, become a slave and connect to the IP that we found.\r\n    * With no IPs, configure as a master and enable the replica set, which then makes the health check pass.\r\n\r\nThe only snag is that I must start one instance of mongo initially so it will bootstrap the replica set.  Once it is running I am able to add and remove instances to my replica set."}}