RU-FI-OOOOOH!

Sohail Mirza, standing in for Peter.

Posts Tagged ‘Ubuntu

Helpful Hints: Create an APT proxy in 3 easy steps using apt-cacher-ng

Pre-requisites

This Helpful Hints tutorial will require a number of basic and intermediate skills.  In order to complete this tutorial you should be comfortable doing the following:

If you’re not certain how to perform some of these actions, you may find tutorials for them readily available online.

Why an APT proxy?

If you’re like me, you might have a number of Ubuntu machines at home.  If this is the case, you know it can be a pain to quickly update them all since the same updates need to be downloaded to each computer.  If there are a lot of updates to be downloaded, this can take a while on a slower Internet connection.

If this sounds like your situation, then you can speed things up by setting up an APT proxy on your network at home. APT is the tool your Ubuntu system uses to retrieve updates and manage the installation of programs. An APT proxy will basically allow you to designate one of the machines on your network as the update server — the one machine where all the others will get their system updates from.  The idea is that the proxy will only have to download updates once, and these are then distributed to all the other Ubuntu machines on the network.

To accomplish this we can very easily setup apt-cacher-ng, a proxy tool readily available from the Ubuntu repositories.  I did play around with apt-proxy first, but found that less straightforward to use.

Taking it step-by-step

So here are the three easy steps, assuming all the computers involved are running Ubuntu (the computers can be running any version of Ubuntu, even differing versions):

  1. On the machine which will be running the APT proxy, install apt-cacher-ng. Just click the link in the last sentence, or type the following into a terminal window:

    sudo apt-get install apt-cacher-ng

  2. Now that your proxy is ready to go — yup, it was that simple — we need to instruct all the computers in your home or office to go to that proxy computer for APT updates, and not to the public update sites on the Internet. This is fairly straightforward to do as well.

    As the super-user, you’ll need to edit (or create, if it doesn’t exist) the file at /etc/apt/apt.conf.d/02proxy, and add the following to the first line in that file:

    Acquire::http { Proxy "http://ProxyComputerIPAddress:3142"; };

    In this line you’ll need to replace “ProxyComputerIPAddress” with the proxy computer’s address on your network. It’s address may look similar to an IP address like 192.168.1.100.

    You’ll need to perform this step on every computer, including the one running the APT proxy. On the computer running the proxy you can use the IP address 127.0.0.1, which is just a way for the computer to refer to itself; every computer can refer itself with the this IP address.

  3. Now that every computer will be going through the proxy, things should magically just work! At this point you can launch the Update Manager, and check to see if there are pending updates.

Wrapping up…

That’s it folks, it’s that easy to setup an APT proxy. The result is that all Ubuntu updates should be cloned to your proxy server once, and that will now be the source of updates for all the computers on your network.

Post to the comments and let us know how it works for you.

Written by Sohail Mirza

August 20, 2011 at 12:46 am

MySQL: “Access denied for user ‘debian-sys-maint’@’localhost'”

For all you Ubuntu/MySQL developers out there, have you ever seen the following?

    neo@thematrix:~$ sudo /etc/init.d/mysql restart
    * Stopping MySQL database server mysqld [fail]
    * Starting MySQL database server mysqld [ OK ]
    /usr/bin/mysqladmin: connect to server at 'localhost' failed
    error: 'Access denied for user 'debian-sys-maint'@'localhost' (using password: YES)'

So, what is this “debian-sys-maint” user?  Well, this MySQL user is created for the Ubuntu to be able to start/stop the database and to carry out other maintenance operations.

Sounds well enough, but then why do I keep running into the “access denied” problem for this user?  Well, the issue is that with each update to MySQL, the user’s password in the database is overwritten.  Ubuntu seems to go to the file /etc/mysql/debian.cnf in order to find this user’s password, but obviously the password is out of sync after the update has been applied.

As a result of this behaviour, I’ll run into the “access denied” problem every so often.  Thankfully, the solution to this issue is fairly simple.

First, list the contents of the /etc/mysql/debian.cnf file:

    neo@thematrix:~$ sudo cat /etc/mysql/debian.cnf

The contents of the file should look something like the following:

    # Automatically generated for Debian scripts. DO NOT TOUCH!
    [client]
    host     = localhost
    user     = debian-sys-maint
    password = n4aSHUP04s1J32X5
    socket   = /var/run/mysqld/mysqld.sock
    [mysql_upgrade]
    user     = debian-sys-maint
    password = n4aSHUP04s1J32X5
    socket   = /var/run/mysqld/mysqld.sock
    basedir  = /usr

See that password?  That’s what we’re looking for!

Next, we want to issue a command to MySQL that tells it to grant the debian-sys-maint user all necessary privileges using the new password.

Login to your mysql server using your root account and the root password you had originally set:

    neo@thematrix:~$ mysql -u root -p <password>

Issue the GRANT command now to grant those permissions:

    mysql> GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY 'n4aSHUP04s1J32X5';

Voila!  If you restart MySQL, you’ll find that you should no longer be getting the “access denied” error message.

    neo@thematrix:~$ sudo /etc/init.d/mysql restart
    * Stopping MySQL database server mysqld [ OK ]
    * Starting MySQL database server mysqld [ OK ]
    * Checking for corrupt, not cleanly closed and upgrade needing tables.

Bear in mind, because we just switched the password, and the change hasn’t been affected yet, you may need to kill the MySQL server processes in order to get MySQL to shut down at all.

Written by Sohail Mirza

January 16, 2009 at 6:51 pm

Posted in Development, Ubuntu

Tagged with , , ,

dpkg problems relating to ‘cups’ in Ubuntu

Firefox 3.0.5, Mozilla’s latest security fix for the venerable browser has recently been released.  Tonight it was pushed out to Ubuntu 8.10 users, and so I promptly updated my Ubuntu installation.  Noticing that there were other updates as well, I applied them all.

Unfortunately, dpkg wasn’t able to complete the update of all selected packages.  I wanted to review the problem, so from the command-line I brought up aptitude via:

sudo aptitude

Aptitude was nice enough to let me know that I needed to run the following command to correct the problem:

sudo dpkg --configure -a

… unfortunately it didn’t work:

$ sudo dpkg --configure -a
dpkg: ../../src/packages.c:221: process_queue: Assertion `dependtry <= 4' failed.
Aborted

I decided to go back into aptitude to see if any packages would be selected there for installation due to a failure to install previously.  Sure enough, when I pressed ‘g’ to process all actions, it attempted to install cups, cups-bsd, and cups-client, but failed:

dpkg: error processing cups (--configure):
package cups is not ready for configuration
cannot configure (current status `triggers-awaited')
dpkg: error processing cups-client (--configure):
package cups-client is not ready for configuration
cannot configure (current status `triggers-awaited')
dpkg: ../../src/packages.c:221: process_queue: Assertion `dependtry <= 4' failed.
E: Sub-process /usr/bin/dpkg exited unexpectedly
A package failed to install.  Trying to recover:
dpkg: ../../src/packages.c:221: process_queue: Assertion `dependtry <= 4' failed.
Aborted

These were the packages that had failed to install successfully earlier.

What could I do to get around this?  Aptitude wasn’t able to handle it for me, and nor could dpkg process the configuration of these packages.  After some futzing around, I even tried downgrading the packages in aptitude, but the same dpkg errors came up:

Preconfiguring packages ...
Selecting previously deselected package cups.
(Reading database ... 148514 files and directories currently installed.)
Preparing to replace cups 1.3.9-2ubuntu4 (using .../cups_1.3.9-2_amd64.deb) ...
* Stopping Common Unix Printing System: cupsd [ OK ]
Unpacking replacement cups ...
Selecting previously deselected package cups-bsd.
Preparing to replace cups-bsd 1.3.9-2ubuntu4 (using .../cups-bsd_1.3.9-2_amd64.deb) ...
Unpacking replacement cups-bsd ...
Selecting previously deselected package cups-client.
Preparing to replace cups-client 1.3.9-2ubuntu4 (using .../cups-client_1.3.9-2_amd64.deb) ...
Unpacking replacement cups-client ...
Processing triggers for doc-base ...
Processing 1 changed doc-base file(s)...
Registering documents with scrollkeeper...
Processing triggers for man-db ...
Processing triggers for ufw ...
ERROR: Couldn't stat '/etc/default/ufw'
dpkg: subprocess post-installation script returned error exit status 1
E: Sub-process /usr/bin/dpkg returned an error code (2)
A package failed to install. Trying to recover:
Setting up cups-client (1.3.9-2) ...

Setting up ufw (0.23.2) ...

Setting up cups (1.3.9-2) ...

Installing new version of config file /etc/apparmor.d/usr.sbin.cupsd ...
Reloading AppArmor profiles : done.
* Starting Common Unix Printing System: cupsd [ OK ]

dpkg: ../../src/packages.c:221: process_queue: Assertion `dependtry <= 4' failed.
Aborted
Press return to continue.

But wait, what’s that error?

Processing triggers for ufw ...
ERROR: Couldn't stat '/etc/default/ufw'
dpkg: subprocess post-installation script returned error exit status 1
E: Sub-process /usr/bin/dpkg returned an error code (2)

A-hah!  It looked like the cups installation needed to process some triggers for the package ufw, and this failed.  ufw is Uncomplicated FireWall package for Ubuntu, but it’s a package I’m not using.

So, maybe if I were to uninstall ufw, the cups packages would successfully install?

sudo aptitude purge ufw

If you want to keep the ufw configuration files, you can try this instead:

sudo aptitude remove ufw

Removing ufw may display some cups errors, but ufw should still successfully uninstall.

At this point, the resolution that aptitude first suggested worked as well:

sudo dpkg --configure -a

And now to install the latest version of cups instead of the downgraded versions I attempted to install.

Preconfiguring packages ...
(Reading database ... 148481 files and directories currently installed.)
Preparing to replace cups 1.3.9-2 (using .../cups_1.3.9-2ubuntu4_amd64.deb) ...
* Stopping Common Unix Printing System: cupsd                                                                                                                                                                                        [ OK ]
Unpacking replacement cups ...
Preparing to replace cups-bsd 1.3.9-2 (using .../cups-bsd_1.3.9-2ubuntu4_amd64.deb) ...
Unpacking replacement cups-bsd ...
Preparing to replace cups-client 1.3.9-2 (using .../cups-client_1.3.9-2ubuntu4_amd64.deb) ...
Unpacking replacement cups-client ...
Processing triggers for doc-base ...
Processing 1 changed doc-base file(s)...
Registering documents with scrollkeeper...
Processing triggers for man-db ...
Setting up cups (1.3.9-2ubuntu4) ...
Installing new version of config file /etc/apparmor.d/usr.sbin.cupsd ...
Reloading AppArmor profiles : done.
* Starting Common Unix Printing System: cupsd                                                                                                                                                                                        [ OK ]

Setting up cups-client (1.3.9-2ubuntu4) ...

Setting up cups-bsd (1.3.9-2ubuntu4) ...

Press return to continue.

Presto! It worked!

At this point I reinstalled ufw and all was as it should be.

Along the way I was also able to find a cool way of listing packages on one’s system that are not completely installed.  From a command line terminal, you can enter the following:

sudo dpkg -l | grep -v ^ii

The first portion of this command, sudo dpkg -l, will list all the packages on your system. The second portion, grep -v ^ii, says, ‘search through that list of packages for any line that does not start with “ii“‘. The letters “ii” at the beginning of a line of the package listing indicates the package is successfully installed.

Quite an eventful application of system updates! I love Ubuntu for its simplicity, and the fact that upgrades and installations are usually hassle-free. But, even when there’s a problem, the power inherent in Linux allows you to quickly and effectively resolve the issue.

NB: Sorry about the poor formatting of this post, WordPress is simply not co-operating.

Written by Sohail Mirza

December 18, 2008 at 1:10 am

Posted in Software, Ubuntu

Tagged with , , , , ,

Shiny, new failure

As we come upon another new year, I thought I should dust off the cobwebs on this blog.  While I’m at it, why not a new blog design as well?  I’ve been in the mood for something a little more open, a little more minimalistic.

Though I celebrate neither Christmas or the New Year, this season has always had an air of change about it.  Of course, part of it has to do with the carpet-bombing of Christmas shopping advertisement, but beyond that, there are a number of birthdays in the month of December of close family members.

Historically, I’ve been horrible about birthdays close family and friends.  I never remember the birthdays and when I do, I haven’t made much of an effort to get a really thoughtful gift.  This year though, I’ve got to change that.

A good friend of mine had his birthday in October, so for his birthday I organized a golf outing with a few mutual friends of ours.  We all really had a tremendous blast.

Now, my sister’s birthday is coming up in early December, so I’m thinking, I have to do something really special for her.  What speaks of brotherly love better than a brand new laptop?

I’ve always hated laptops for a number of reasons.  As someone who has always built his own machines from scratch and relies on the interchangeability of standardized parts, laptops really annoy me.  They’re expensive, costly to maintain, come with Windows Vista, and can’t run games at 1920 x 1200.  That said, I know my sister would really like one to browse the Internet in any room of the house and get her office work done remotely.

Yesterday I took a trip to Future Shop here in Canada and settled on a Toshiba L300 (PSLB8C-04P01X) featuring an Intel T5800 Core 2 Duo:

The Toshiba L300 at Future Shop

The Toshiba L300 at Future Shop

The fact that I was able to find a Toshiba with decent specs and a decent price tag as well went a ways toward making me feel better.  I have an impression that Toshiba laptops are built more solidly than other brands.

As well, I have to admit that my hate quickly fades with new technology, laptop or not.

Except when the experience of using it is awful.  As was the case with the Toshiba L300.

For starters, from the moment I turned on the laptop to the moment I could actually use Windows, 1 hour and 45 minutes had elapsed.  The laptop rebooted approximately 5 times during this process, 2 of which happened at points where Windows had become momentarily usable, making you think it was ready for use.  Uber Fail #1. What was the laptop doing in all that time?  Completing the Vista installation, and ensuring I’d be encumbered by software offers that I didn’t want.  Fail #2. What would it take to get a clean Vista installation on the laptop?  An act of God given that laptop manufacturers no longer include the O/S on disc.  Fail #3. Forget Vista, what about XP?  Not supported (no drivers).  Fail #4. Fine, the hell with XP.  What about Vista drivers so I can re-install in case I get a copy of Vista at a later date?  No dice.  The laptop is a model built exclusively for Future Shop, so there are no drivers available online at all, let alone any other support materials for the model on the Toshiba website.  Fail #5!

"Get lost!  We don't have any of your precious drivers here!"

"Get lost! We don't have any of your precious drivers here!"

By the end of Fail #1 I had already had enough, let alone the other 4 points of frustration.  Imagine I had given the laptop to my sister without having opened it.  She would’ve been furious at having to wait so long for the system to become usable.

The other point of extreme frustration that deserves mention is the fact that laptop manufacturers do not include a clean Vista disc with laptops anymore.  They’ve instead gotten into the habit of including a recovery partition on the hard drive.  This is to ensure that:  1)  You have to spend your own time and money to burn a recovery disc that has an O/S on it, and 2)  You’ll never, ever be rid of their annoying software offers since they’ve been backed up onto the recovery disc as well.

Needless to say, the whole experience was an epic failure, and the laptop was promptly returned today.  If there’s one thing to be said about Future Shop, it’s that they took back the laptop without any hassles.  I was slightly taken aback by that!

I have a decent amount of respect for Microsoft as a company, and Windows XP as an operating system.  Even XP took time to mature, but it was never as horrible as Vista.  None of the problems I’ve described here are Vista problems per se (not to say Vista itself didn’t annoy me), but they have to be judged as part of the Microsoft/Vista experience.  This experience is so horrific that one has no choice but to conclude that OS X, Ubuntu, and even Windows XP are an excellent respite.  I’m just sad to say I had to give up on Vista.

By comparison, the simplicity of OS X is a thing to marvel, and the malleability of Linux is empowering.  Neither can be said about Vista or the Microsoft experience.  Instead, I was held powerless and left to marvel at the absurdity of it all.

"You know you want me.  I actually work."

"You know you want me. I actually work."

Based on this experience I’ve decied that if I’m to get my sister a new laptop, it will almost certainly be a sparkling MacBook.  It comes at a premium, but the hassle-free experience is worth it.

Written by Sohail Mirza

November 24, 2008 at 11:32 pm