Asterisk, and other worldly endeavours.

A blog by Leif Madsen

Archive for the ‘Being Productive’ Category

Assign unique hostname to dhcp client with dnsmasq

with 2 comments

Today I’ve been getting our lab environment setup with vagrant to auto-provision our lab servers with chef server in order to allow the development team to quickly and easily turn up and tear down web application servers.

Because when the server gets spun up with vagrant, it registers itself as a new node to the chef server using its hostname. Since using localhost for every node pretty much makes the chef server useless for more than 1 virtual machine at a time, I needed to figure out how to get dnsmasq to assign a unique hostname based on the IP address being provided by dnsmasq to the dhcp client.

I had seen a similar thing done with Amazon EC2 instances that when they turn up, they gets a hostname that looks similar to the private IP address it has been assigned. For example, if the private IP address assigned to the server was 192.168.12.14 it would get a hostname like ip-192-168-12-14. I wanted to do a similar thing with our server.

After a little bit of Googling and reading the dnsmasq configuration file, it donned on me how simple this really was. You simply need to define the hostnames that the dnsmasq server could assign to a server, list those in the /etc/hosts file on the dnsmasq server, and then define the hostname you wanted to provide to the server. I didn’t want to use the MAC address of the servers (a la dhcp-host option) since the MAC address will be dynamic each time I spin up a virtual machine.

So in my dnsmasq.conf file I might have something defined like

dhcp-range=90.100.1.120,90.100.1.124,24h

 

So in my /etc/hosts file I’d just place the following to assign those unique hostnames:

90.100.1.120    ip-90-100-1-120
90.100.1.121    ip-90-100-1-121
90.100.1.122    ip-90-100-1-122
90.100.1.123    ip-90-100-1-123
90.100.1.124    ip-90-100-1-124

Written by Leif Madsen

2012/07/23 at 2:14 pm

Relaying SMTP via Gmail (or Google Apps) Using Postfix

with 3 comments

Today I had the need to start relaying mail through my Google Apps account since Super-Evil-Bastard-ITSPRogers blocks sending email (it’s probably a good thing, however it’s quite annoying when running some services from home).

Found this article while Googling, and it worked great first try. I like when things are this easy.

http://www.zulius.com/how-to/set-up-postfix-with-a-remote-smtp-relay-host/

Written by Leif Madsen

2011/11/22 at 5:17 pm

Return just PID of script with ‘ps’ and ‘awk’

with 4 comments

Today I ran into an issue where I am running a python script that I needed to get the process ID (PID) of, but that the process was being output with a space between ‘python’ and the actual script name (in this case, jiraircbot.py).

I’m sure it’s totally overkill and there is a much easier way I didn’t find to do this, but after some scouring of The Google, I found something that works! (The purpose of this was to kill off a rogue script process each night so I could restart it.)

Here is what the output looks like with just ps aux | grep python

# ps aux | grep python
root      1120  0.0  0.2  50176  4380 ?        Sl   Aug04  24:52 /usr/bin/python /usr/bin/fail2ban-server -b -s /var/run/fail2ban/fail2ban.sock
root     18182  2.2  1.5  35328 32148 pts/0    S    08:21   0:11 python jiraircbot.py
root     18219  0.0  0.0   3328   804 pts/0    S+   08:29   0:00 grep python

A little bit more data than I wanted, plus of course ‘grep python’ is always going to be returned if I just use grep straight up. Putting many pieces together from a few websites, this is what I came up with to just return the PID of the jiraircbot.py script:

ps -eo pid,command | grep "jiraircbot.py" | grep -v grep | awk '{print $1}'

What I’m doing, is controlling what is returned, so in this case have ps just return the pid and command fields. Run that through grep to just get the script I wanted, pipe that back through grep to remove the line including grep python and then pipe that through awk to just return the first field (which would be the pid of the process I wanted).

All in all, a nice hack :)

Written by Leif Madsen

2011/09/15 at 7:34 am

Posted in Being Productive, Programming

Tagged with , , , , ,

Asterisk: The Definitive Guide, First Draft Complete!

with 7 comments

Today we marked the finishing of Asterisk: The Definitive Guide (3rd Edition) by sending the first draft off to the O’Reilly production team. We finished nearly on schedule (within a few days, which is remarkable considering we added 150 more pages than originally intentioned) and have our favourite copy editor Rachel Head (formerly Wheeler) who did the first edition of Asterisk: The Future of Telephony who we emphatically enjoyed working with. We’re looking forward to it again.

With the draft done now, and the copy sent off to production to do their magic, I’m not quite sure what I’m going to do with my mornings! Perhaps I’ll start blogging about some dialplan stuff, or coming up with some sort of project to build. We’ll see! Any suggestions about things to document on my blog are of course welcome.

Don’t stop posting your comments and suggestions to the OFPS site though! (http://ofps.oreilly.com) When the O’Reilly production team is done with the book in a few weeks, we’re going to have time to do additional modifications and editing, so your comments will get addressed then. It’s looking like the estimated shipping date of books for March is realistic at this point.

Thanks for all the support the community has shown us this far. This is going to be by far the best book on Asterisk to date.

Written by Leif Madsen

2011/01/11 at 8:30 pm

Interesting article about *not* tracking holidays at Netflix

with 3 comments

The following is an interesting article about not tracking workers time spent at work, or on vacation, but rather tracking their productivity. As a consultant who doesn’t have a fixed set of hours in the day that I work, I tend to judge my productivity by the number of hours I get to bill each week (i.e. how productive was I working for customers, rather than playing Flight Simulator :) ).

I haven’t tracked actual holidays for years now (since I started consulting full time out of school in 2003), and I’m not sure I ever had a job long enough prior to school that I received any sorts of benefits of holidays. Perhaps it’s just natural for me because of that, but this article reminds me of two things:

1) I should actually take some holidays when I need to recharge, and not feel like I *need* to be on-call 24/7/365

2) That other companies are really starting a paradigm shift about how they treat their employees work hours

It seems companies are starting to get it, and not bother with tracking the employees hours at work, which isn’t a very good indication of the amount of work they are getting done. A better method is likely to work in sprints and to allocate a certain number of tasks with priorities and estimated number of hours associated with each of those tasks. At the end of each sprint you determine what was good, what was bad, and what things didn’t get done (certain issues taking longer than expected, other issues going faster than expected, other issues with higher priority coming up, etc).

By tracking the productivity, the company isn’t at risk of everyone taking a salary and then screwing off for several months at a time. The accountability for productivity can keep that in check. The methods used for tracking productivity though are probably the most important part of implementing a non-policy on holidays such as this.

http://www.telegraph.co.uk/finance/newsbysector/mediatechnologyandtelecoms/7945719/Netflix-lets-its-staff-take-as-much-holiday-as-they-want-whenever-they-want-and-it-works.html

Written by Leif Madsen

2010/08/25 at 3:07 pm

Follow

Get every new post delivered to your Inbox.

Join 1,600 other followers