    [pubdns]
     (join "." (rest (re-find #"ec2\-(\d+)-(\d+)-(\d+)-(\d+).*" pubdns))))
 
-(defn update-pubdns [spec endpoint instance-id]
+(defn update-ip [spec endpoint instance-id]
   "updates public dns in the machine persisted data"
   (when (s/system-exists? (spec :system-id))
     (let [ec2-host (pub-dns endpoint instance-id)]
-      (s/partial-system (spec :system-id) {:machine {:ssh-host ec2-host :ip (pubdns-to-ip ec2-host)}}))))
+      (s/partial-system (spec :system-id) 
+        {:machine {:ip (pubdns-to-ip ec2-host)}}))))
 
 (defn set-hostname [spec endpoint instance-id user]
-  "Uses a generic method of setting hostname in Linux, not that in ec2 both Centos and Ubuntu use sudo!"
+  "Uses a generic method of setting hostname in Linux (see http://www.debianadmin.com/manpages/sysctlmanpage.txt)
+   Note that in ec2 both Centos and Ubuntu use sudo!"
   (let [{:keys [hostname domain]} (spec :machine) 
         remote {:host (pub-dns endpoint instance-id) :user user}]
     (execute (<< "echo kernel.hostname=~{hostname} | sudo tee -a /etc/sysctl.conf") remote )
     (execute (<< "echo kernel.domainname=\"~{hostname}.~{domain}\" | sudo tee -a /etc/sysctl.conf") remote )
     (execute (<< "echo 127.0.1.1 ~{hostname}.~{domain} ~{hostname} | sudo tee -a /etc/hosts") remote )
+    (execute (<< "echo ~{hostname} | sudo tee /etc/hostname") remote )
     (execute "sudo sysctl -e -p" remote) 
     (with-ctx ec2/create-tags [(instance-desc endpoint instance-id :id)] {:Name hostname})
     ))

  (stop [this]
    (with-instance-id 
       (debug "stopping" instance-id)
       (with-ctx ec2/stop-instances instance-id) 
       (wait-for-status this "stopped" [5 :minute])))


      (with-instance-id 
         (instance-desc endpoint instance-id :state :name)) 
      (catch [:type ::aws:missing-id] e 
        (debug "No AWS instance id, most chances this instance hasn't been created yet") false))))

(def defaults {:aws {:min-count 1 :max-count 1}})

