Coder Social home page Coder Social logo

hostr's Introduction

hostr

Dynamic hostname lookup and supplement to /etc/hosts

"Oh no, x service is down, I gotta ssh into elrond. What's elrond's IP address again?"

You have a bunch of machines in the cloud. They come and go so often (livestock, not pets) so you don't bother putting their IPs in /etc/hosts. If only there was a way for your dev machine to automatically know the address to your VMs in the cloud, and connect to them quickly without you needing the IP address. Oh no way, this project does just that? Killer sick, dude.

Video intro (runtime 9 minutes) https://www.youtube.com/watch?v=TW5rQE1_55A

Example usage

$ ssh core@$(hostr elrond)

$ ssh user@$(hostr my-vps2)

or

$ ssh core@`hostr my-vps3`

hostr uses the power of bash* command substitution. You can use hostr anywhere that uses bash*:

$ echo "hey pete, if you need to log into the vps named mega-vps, it's IP address is $(hostr mega-vps)" > email.txt

Installation

Summary

  • install node.js
  • clone this repo
  • npm install
  • set VULTR_API_KEY in [repo root]/config.json
  • create shell alias for hostr
  • use hostr

Detail

hostr is written in javascript, so node.js is a dependency. Get node here: http://nodejs.org/download/

Once you have node installed, clone hostr from github onto your computer. I like putting it in a directory, ~/scripts.

$ mkdir ~/scripts
$ cd ~/scripts
$ git clone https://github.com/insanity54/hostr
$ cd hostr

Now we need to satisfy some of hostr's javascript dependencies

$ npm install

K, now we need to give hostr some information sources. These sources are your VPS/VM hosting services. hostr queries these sources using their api, and finds the IP address of the host you specify using it's human readable lable. Right now, vultr is the only suported source. We tell hostr about our vultr account by editing the hostr config file, ~/scripts/hostr/config.json

{
    "VULTR_API_KEY": "enter your vultr api key here (get it from https://my.vultr.com/settings/) (optional)".
    "DO_CLIENT_ID": "enter your digital ocean client id here (get it from https://cloud.digitalocean.com/api_access) (optional)",
    "DO_API_KEY": "enter your digital ocean api key here (get it from https://cloud.digitalocean.com/api_access) (optional)"
}

Gr8, now we need to make the hostr command available to bash*. We do this by adding an alias to the end of our ~/.bash_aliases file. For other shell aliases, check their docs. Our ~/.bash_aliases file needs this line:

alias hostr='~/scripts/hostr/hostr.js'

But we can automate adding that with the following command:

$ echo -e "\nalias hostr='~/scripts/hostr/hostr.js'" >> ~/.bash_aliases

Finally, we need to source the ~/.bashrc file so bash knows about the updated ~/.bash_aliases file. (As an alternative, you can restart your terminal.)

$ source ~/.bashrc

That's it! hostr is ready to use. Try it out!

$ echo "$(hostr my-vps-name)"

Advanced use

Cloud prefixes

You can make hostr look at only one cloud provider for the host's address using a prefix. As of v0.0.1, you have the options do_ for digitalocean, and vultr_ for vultr.

force hostr to get elrond from digitalocean

$ ssh user@$(hostr do_elrond)

force hostr to get elrond from vultr

$ ssh user@$(hostr vultr_elrond)

Troubleshooting

hostr saves a log file to [repo root]/log.txt. To save disk space, this file only logs the results of the last command that was run.

Contributing

I don't know if this project is helpful to anyone other than myself, but if it is, cool! Feel free to open issues, suggest features, submit pull requests or just fork and make your own super cool version.

Author

I'm Chris Grimmett. I do videos on youtube, develop software, and wish I were a cyborg. For more info about me, check my website https://grimtech.net/about

If you have used and enjoy this code base, I'd love to hear from you!

Say Thanks!

Foot notes

* also sh, ksh, and whatever the cool kids use these days

hostr's People

Contributors

insanity54 avatar dependabot[bot] avatar

Stargazers

 avatar Kevin Ridgway avatar  avatar Jacob Martinez-Troxel avatar

Watchers

 avatar James Cloos avatar Jacob Martinez-Troxel avatar

Forkers

bedri

hostr's Issues

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper App’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

nconf

chris@zed-zed:~/Documents/futureporn$ et root@$(hostr my-cool-server)
node:internal/modules/cjs/loader:988
  throw err;
  ^

Error: Cannot find module 'nconf'
Require stack:
- /home/chris/.local/bin/hostr
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:985:15)
    at Function.Module._load (node:internal/modules/cjs/loader:833:27)
    at Module.require (node:internal/modules/cjs/loader:1057:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/home/chris/.local/bin/hostr:4:13)
    at Module._compile (node:internal/modules/cjs/loader:1155:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
    at Module.load (node:internal/modules/cjs/loader:1033:32)
    at Function.Module._load (node:internal/modules/cjs/loader:868:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/home/chris/.local/bin/hostr' ]
}
invalid error

Aborted (core dumped)

doesnt work on mac

getting this error:

SyntaxError: Unexpected end of input
    at Object.parse (native)
    at IncomingMessage.<anonymous> (/Users/chrisgrimmett/scripts/hostr/hostr:189:28)
    at IncomingMessage.emit (events.js:107:17)
    at IncomingMessage.Readable.read (_stream_readable.js:373:10)
    at flow (_stream_readable.js:750:26)
    at resume_ (_stream_readable.js:730:3)
    at _stream_readable.js:717:7
    at process._tickCallback (node.js:355:11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.