Asterisk, and other worldly endeavours.

A blog by Leif Madsen

Archive for the ‘Being Productive’ Category

Configuring powerline to show working Git branch

So the documentation for Powerline kind of sucks. I followed this pretty good article on getting started with it. First thing I noticed however is that the if statement on the article doesn’t work if you don’t have powerline installed (which kind of defeats the purpose of having the if statement there at all).

# if powerline is installed, then use it
command -v powerline-daemon &>/dev/null
if [ $? -eq 0 ]; then
powerline-daemon -q
POWERLINE_BASH_CONTINUATION=1
POWERLINE_BASH_SELECT=1
. /usr/share/powerline/bash/powerline.sh
fi

Next up is the configuration. I primarily use my bash prompt as a way to indicate which branch I’m working in within a Git repository. You need to point at the default_leftonly theme which is pretty easy to find when you web search for it. The issue is everything seems to just point you at the powerline docs, which aren’t the most clear.

First, start by creating a local configuration directory that will override the configuration for powerline for your user.

$ mkdir -p ~/.config/powerline

Then the next thing is to copy over the config.json from the main powerline configuration directory where you can find the available color schemes and other shell, i3, vim, etc themes.

(Again, the documentation kind of sucks on where the root of these configurations live…)

On my Fedora 22 system they live in /etc/xdg/powerline/. I then copy the config.json from that directory to ~/.config/powerline

To get the Git branch stuff going, I modified the configuration file in the following way:

--- /etc/xdg/powerline/config.json 2015-02-18 18:56:51.000000000 -0500
+++ /home/lmadsen/.config/powerline/config.json 2015-09-09 17:11:43.937522571 -0400
@@ -18,7 +18,7 @@
},
"shell": {
"colorscheme": "default",
- "theme": "default",
+ "theme": "default_leftonly",
"local_themes": {
"continuation": "continuation",
"select": "select"

To make it active you can run powerline-config --reload. If you have any errors in your configuration (I actually ran into this when playing with the colorscheme setting and used “solorized” instead of “solarized”), you can check it with powerline-lint.

Advertisements

Written by Leif Madsen

2015/09/09 at 4:20 pm

Assign unique hostname to dhcp client with dnsmasq

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

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’

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!

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

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

MindMeister: Online mind mapping

Russell Bryant just sent me a link to a neat site that allows you to do online collaborative mind mapping: MindMeister. If you’re not aware of what mind mapping software does, it is a method to quickly and easily allow you to brainstorm ideas without getting in the way too much. It works by starting from a central node and breaking out in lines from there where you start with an idea or thought, then break that thought down further with additional lines from that node.

While working on the next edition of the Asterisk book, we spent a significant amount of time using FreeMind to brainstorm ideas of what we wanted in the book, then develop a detailed outline to the book which included the chapters, and what each of those chapters would contain. This way we can reference the mindmap while working on the book, and later review all our thoughts to make sure we covered all our original ideas. We continue to refine the mindmap on an almost daily basis while we come up with additional ideas and layout tweaks while working on particular chapters.

The website allows you to import mindmaps from FreeMind into the site, which is a valuable tool for those who have existing mindmaps. Check it out and tell me what you think!

Written by Leif Madsen

2010/08/10 at 9:03 am