Friday, July 19, 2013

Going Carless

Who needs a car anyway? My neighborhood is ranked as "very walkable" with a walkability score of 75. Meaning most of the errands that I should need to run can be accomplished on foot. There shouldn't be much reason for needing a car.

So when my lease expired, I turned in my Jetta and started my journey as a person without a car.

Why? You might ask yourself. Several reasons:

  • I don't feel like I really need a car. I don't do that much driving and most of the driving I do can be serviced by other options. 
  • Cars are expensive, especially if you don't use it often. Who needs that expense? I have better things to spend my money on. Well that is the theory anyway. 
  • Maybe i can reduce my carbon footprint this way. 
There are other reasons, you may be able to think of, but those are the main ones for me.

How? You also might be asking. I plan to try to use these replacements, in this order.:

  • Walk
  • Bike
  • Bus
  • Carshare
    • Car2Go
    • Lyft
    • Sidecar
  • Motorcycle
I'm certainly not without options here. These are basically in order of cost, then how long it would take me. This is kind of an ideal preference, but lately it has been more like this: 
  • Motorcycle
  • Carshare
    • Lyft
    • Sidecar
    • Car2Go
  • Bus
It has been a week or so, a week of no rain (easier to ride) and not a lot going on, maybe my opinion will change as time goes on? I'll try to keep this blog updated regarding my progress.

Play audio output to multiple devices via pulse audio, or more pulse audio woes.

I've since moved past Ubuntu 12.04 to 13.04 and have run into more troubles with pulseaudio. This is unrelated to my previous issues.

Admittedly this is a fairly fringe case that most people would not run into but that seems to be my experience with Linux in general. Usually a quick google search fixes me up, but this one was a bit trickier.

I have a media center setup with xbmc on a full desktop install of Ubuntu 13.04. It works great, I use the desktop for various things that xbmc has yet to integrate with  or doesn't yet have a great experience with. (e.g. Google Play Music, songza, youtube), and use xbmc to play my movie and TV content.

From my media center to my PC since I'm often playing high quality content I tend to prefer using HDMI to connect the two. It is easy and provides a very high level of quality. Unfortunately for me (and apparently for most modern receivers) my receiver will only output analog audio to my speakers on my patio (Zone 2) and HDMI is a digital signal. And thanks to the copyright issues with converting a digital HDMI signal (hard to copy) to an analog signal (easy to copy) the capability to convert to analog is stripped out of the HDMI connections.

So what this means practically is I have to connect an analog cable from my media center to my receiver as well as the digital HDMI connection. This gives me the best of both worlds, the reciever basically selects the highest quality signal that it can deliver. The trick is that I have to broadcast the signal to more than one device, which is not something pulse audio is setup to do out of the box in Ubuntu 13.04.

What is the fix? I did some googling and found a suggestion to use the paprefs package to control the Pulse Audio Preferences. Unfortunately for me this didn't work, despite an indication that it should from the information in paprefs. Essentially you enable simultaneous output and pulse audio is supposed to broadcast the signal to all your output devices. It never output to my analog out.

Back to google and I found this info: https://wiki.archlinux.org/index.php/PulseAudio/Examples#Simultaneous_HDMI_and_Analog_Output

Relevant sections copy/pasted below.
<snip>

Simultaneous HDMI and Analog Output

PulseAudio allows for simultaneous output to multiple sources. In this example, some applications are configured to use HDMI while others are configured to use analog. Multiple applications are able to receive audio at the same time.
$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: Intel [HDA Intel], device 0: ALC889A Analog [ALC889A Analog]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
card 0: Intel [HDA Intel], device 1: ALC889A Digital [ALC889A Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: Intel [HDA Intel], device 3: HDMI 0 [HDMI 0]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
The key to a configuration like this is to understand that whatever is selected in pavucontrol under Configuration>Internal AUdio is the default device. Load pavucontrol>Configuration and select HDMI as the profile.
Add the following to /etc/pulse/default.pa to setup the analog as a secondary source:
### Load analog device
load-module module-alsa-sink device=hw:0,0
load-module module-combine-sink sink_name=combined
set-default-sink combined
Restart PulseAudio, run pavucontrol and select the "Output Devices" tab. Three settings should be displayed:
  1. Internal Audio Digital Stereo (HDMI)
  2. Internal Audio
  3. Simultaneous output to Internal Audio Digital Stereo (HDMI), Internal Audio
Now start a program that will use pulseaudio such as mplayer, vlc, mpd, etc. and switch to the "Playback" tab. A pulldown should be available for the running program to select one of the three sources.
</snip>
This did work! YAY, now I'm able to listen to audio on my patio without much trouble. Rad!

Tuesday, March 19, 2013

Pulseaudio woes

I have an ASRock 890FX Delux4 motherboard that I was having a damned of a time getting the audio to work on in Ubuntu 12.10.

The solution turned out to be that pulseaudio didn't have the device selected as the output, but that was completely not discoverable via the UI.

I had to install an extra program to tell pulse to use an output channel other then what it was using by default.

sudo apt-get install pavucontrol

 This was the ticket I needed, selected the correct output for sound and viola! magic.

Percona/MariaDB libmysqlclient18 dependency snafu

Sometimes the efficiencies of the apt tools in Ubuntu amaze me. There I was running along happily with MariaDB and decided to do a sudo apt-get dist-upgrade, the command has never failed me in the past, so I was confident that Ubuntu would figure out the "correct" thing to do and I blindly confirmed the recommendation without reading what apt was going to do. BAM! A few seconds later MariaDB is successfully uninstalled *blink* what? No problem a simple reinstall should fix that, easy peasy. Well you see the thing is that now there is this dependency problem with libmysqlclient18 and Ubuntu can't figure out how to resolve that so... no db for you!.



I guess what happens is the MariaDB (and Percona too I found out) repositories package a different version of the libmysqlclient18 in thier repective repositories. Sometimes Oracle (The owner of MySQL) releases a newer version of libmysqlclient18 without much notice. Apt thinks the new version is the hot ticket to install and installs it, but the DB in question still need the old version of the package, since it isn't installed anymore they are removed.

There are a few solutions.

  1. Don't do a dist-upgrade, instead do an upgrade... this should prevent the upgrade that removes maria/percona. 
  2. Create a preference file for your repository of choice that tells Ubuntu that, use the version of packages from the DB repository, not your own standard repsitory. 
I struggled to find any great documentation on how to create the preference file to pin the db packages so they come from the repository, so here is the shortcut version.

The big help for me was this post that details how to install percona on Ubuntu 12.10. http://ubuntuforums.org/showthread.php?t=2116360

You need to create a file in /etc/apt/preferences.d/yourFileName.pref

This is what I put in mine:
Package: *
Pin: release o=Percona Development Team
Pin-Priority: 1001

This tells apt to give preference to any package that is contained in the Percona repo. You can replace the * with a specific package, which will only impact that one package. You can also have different levels of preferences by adjusting the Pin-Priority attribute for more preference (higher number) or less preference (lower number).

In order to find the info for the o= switch. I pointed my browser to the address that is listed in /etc/apt/sources.list for that repo, then navigate to the conf/distributions file. The entry you are looking for is the Origin line, that is what you put on the Pin: release o=<put the info from the distributions file, origin line>

For Percona this is the file: http://repo.percona.com/apt/conf/distributions
For MariaDB this is the file(i use the OSU OSL repo, so adjust for yourself): http://ftp.osuosl.org/pub/mariadb/repo/5.5/ubuntu/conf/distributions

Once I did this and apt-get update I was able to install just like normal.

Saturday, March 2, 2013

Percona database won't start

I just finished a long hair pulling session trying to get Percona 5.5 installed on Ubuntu 12.10. What was happening is I would install from the percona repositories and everything would seem to go fine. I would attempt to move the data and log files away from the default location so that I could serve them from my ZFS pool and when I would put in the change into the my.cnf file the database would no longer come back up. It seemed like it was still starting, as I was seeing process running, but just one when I should have seen 12 or so.

This case was particularly frustrating because the my.cnf file I was using was generated by the Percona Configuration Wizard (https://tools.percona.com/wizard). The Configuration Wizard is a really great tool that takes some input from you about your server and intended use and outputs a config file for Percona. I assumed the configs generated from here would just work, but they don't.

What I figured out in the end is the /etc/init.d/mysql script uses the /etc/mysql/debian.cnf file settings to check if the mysqld server is up or not by pinging on the socket located at /var/run/mysqld/mysqld.sock the config file puts the socket by default into your data directory (on my zfs pool).

Two possible solutions, one verified, one should work in theory:

  1. Change the config generated from the wizzard to put the socket at the location that debian.cnf expects it. (/var/run/mysqld/mysqld.sock). This is what I ended up doing and it worked very well. 
  2. create a symbolic link between where you socket is, and where the startup script thinks it should be. e.g. sudo ln -s /path/to/your/actual/file/mysqld.sock /var/run/mysqld . This should work in theory and the reason I didn't do it this way is I'm not sure if there is special syntax for creating a symlink to a socket, or if there were any special considerations for reboot scenarios. 

Wednesday, February 27, 2013

View DNSMasq Leases

Use this command to view the current DHCP leases handed out by DNSMasq:

 cat /var/lib/misc/dnsmasq.leases  

SSH and remote administration. Not just for the command line.

Having the ability to remotely access a network is a great benefit for someone who does remote maintenance or troubleshooting. My tool of choice for this is SSH because:
  • Fairly Secure
  • Less hassel then a full VPN 
  • Installed by default on most Linux installations. 
  • Very flexible. 
SSH stands for Secure SHell and that is exactly what you get with the basic invocation of SSH:

 ssh plecebo@my.example.com   

The first time you execute this command your SSH client will ask you if you want to accept the certificate of the machine you are connecting to. Usually this is a fairly safe practice, but for those who strive for excellent security practices it is usually best to not accept this certificate but obtain it through some verifiable means (physically copy from the remote server and add it on your local machine). That being said I usually accept the certificate.

Once this command executes you will have a terminal open on the remote machine. This is exactly like the terminal you had open on your local machine.

Sometimes working in the terminal can be a real pain in the ass. Especially if there are good alternatives such as a web interface. You may want to connect to a remote network and use and application (web browser) as if you were sitting on site. SSH can help with that using Dynamic Port Forwarding.

 ssh plecebo@my.example.com -D 1234 -N  

This creates a Dynamic forward (SOCKS Proxy) from your computer to the remote computer on port 1234. The -N option keeps sneaky stuff from being executed on the remote machine. It is not required but recommended.

Now configure your application to use the proxy (localhost:1234) and all proxy traffic goes through to the remote computer and appears to come from that network. Most browsers have proxy settings you can configure. Here is a screen shot of Firefox configured for the above proxy.


What if you want to use an application to connect to a private resource on the remote network? For example you want to Remote Desktop into a windows XP machine on the remote network. SSH has you covered.

 ssh plecebo@my.example.com -L3388:192.168.1.100:3389 

This creates a tunnel through the remote computer to the resource behind the firewall. After you execute this command you simply use the address 127.0.0.1:3388 in your application and you will be connected to the resource on the remote network at 192.168.1.100:3389 (3389 is the remote desktop port).




There are also many Remote desktop clients that will connect via SSH for you. I like to use Remmina (http://remmina.sourceforge.net/) since it comes installed by default in Ubuntu and it suits my needs very well.