Blogs

Resolving df and du reporting different output

If df and du give different output of disk usage. Then, most probably it is due to "open file descriptors".

Run `lsof +L1` to get a listing of open files that have been unlinked or removed. Note the file size and kill or restart the respective service.

Reference: walkernews.net

HP Deskjet F2430 printing in Ubuntu-9.10

Although the printer HP Deskjet F2430 was automatically detected upon usb connection to my ubuntu-9.10 desktop, the 3.9.8 version of hplip that came via apt repository did not quite get printing to work.

I headed off to hplipopensource.com, downloaded and installed the latest driver (version 3.9.12 as of this writing) and got the all-in-one printer to work just following the install wizard.

I have yet to test the scanner... but that's going to be another update.

Extending ext3 partition

*** Make sure you have a back up prior to proceeding. ***

  1. Boot into rescue mode.
  2. Unmount partition if mounted and check disk:
    umount /dev/sda1
    e2fsck -vn /dev/sda1
  3. Delete /dev/sda1 partition and create a bigger one with fdisk:
    fdisk /dev/sda
  4. Recreate the partition /dev/sda1 with the starting point at the default location and the ending point at highest possible cylinder. (Note: if you are extending by merging two partitions, the data in the second partition is lost so make sure to backup data you need.)
  5. Run partprobe and resize2fs utility with no size arguments:
    partprobe /dev/sda
    resize2fs /dev/sda1
  6. Reboot and check everything in file-system is intact.

Shrinking ext3 partition

*** Make sure you have a back up prior to proceeding. ***

  1. Boot into rescue mode.
  2. Unmount partition if mounted and check disk:
    umount /dev/sda1
    e2fsck -vn /dev/sda1
  3. Remove journaling from ext3 partition and revert to ext2, as resize2fs does not work on ext3 partition. (Note: This step should not be necessary in recent kernels.)
    tune2fs -O ^has_journal /dev/sda1
  4. Force check the partition:
    e2fsck -vf /dev/sda1
  5. Resize the partition making sure that you don't shrink it lesser than the disk space currently used else you may lose data.
    resize2fs /dev/sda1 6000M
  6. Make a note of the blocks and block size. You can also run:
    dumpe2fs /dev/sda1
  7. Delete /dev/sda1 partition and create a smaller one with fdisk:
    fdisk /dev/sda
  8. Recreate the partition /dev/sda1 with the starting point at the default location and the ending point at number of blocks from the resize2fs output (1536000) multiplied by the size of a block (4K). So, the end point would be 1536000 * 4 = 6144000K.
  9. Run partprobe and resize2fs utility with no size arguments:
    partprobe /dev/sda
    resize2fs /dev/sda1

    Note: If resize2fs errors out, you may need to further increase the block size by a small percentage (3 to 5%).

  10. Run a disk check for the final time before restoring the journal.
    e2fsck -vn /dev/sda1
    tune2fs -j /dev/sda1
  11. Reboot and check everything in file-system is intact.

Exclamations in the body of phplist emails resolved

PHPlist using phpmailer, by default sets to send email with Content-Transfer-Encoding set to 8-bit. However, mail transport standards forbid lines longer than 998 characters and has to handle such non-compliant lines by breaking/folding them, or the next hop MTA (Mail Transfer Agent) might reject the message or truncate the lines.

The fix for the problem is to use "base64" or "quoted-printable" encoding, which will fold the lines in a way that can be undone by the recipient MUA (Mail User Agent).

If using phplist with phpmailer, the file to edit would be "admin/phpmailer/class.phpmailer.php", as below:

var $Encoding = "base64";

PostgreSQL role based password authentication

To manage/setup role based password authentication for postgresql database.

Modify "/var/lib/pgsql/data/pg_hba.conf" and include:

host    samerole         all         127.0.0.1/32         md5

Save the below script and run:

./db_setup.sh <DBNAME> <DBMAINUSER> <DBMAINUSERPASS> create

#!/bin/bash
# db_setup.sh

USAGE="Usage: $0 <DBNAME> <DBMAINUSER> <DBMAINUSERPASS> <create|drop>"
DBNAME=${1?"$USAGE"}
DBMAINUSER=${2?"$USAGE"}
DBMAINUSERPASS=${3?"$USAGE"}

# Create new database + main user
#
create_db_and_mainuser() {
psql -U postgres template1 -f - <<EOT

CREATE ROLE ${DBNAME} NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT NOLOGIN;
CREATE ROLE ${DBMAINUSER} NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT LOGIN ENCRYPTED PASSWORD '${DBMAINUSERPASS}';
GRANT ${DBNAME} TO ${DBMAINUSER};
CREATE DATABASE ${DBNAME} WITH OWNER=${DBMAINUSER};

EOT
}

# Remove database + main user
#
drop_db_and_mainuser() {
psql -U postgres template1 -f - <<EOT

-- TERMINATE CONNECTIONS OF ALL USERS CONNECTED TO <DBNAME>
DROP DATABASE ${DBNAME};
DROP ROLE ${DBMAINUSER};
DROP ROLE ${DBNAME};

EOT
}

# Main
case "$4" in
  create)
    create_db_and_mainuser
    ;;
  drop)
    drop_db_and_mainuser
    ;;
  *)
    echo $USAGE
    exit 1
    ;;
esac

exit 0

You should now be able to connect using:

psql -U <DBMAINUSER> -d <DBNAME>  -h 127.0.0.1

Relay email via SMTP provider using sendmail

The below is specific to CentOS-5.4 and may work similarly with other distros.

  • Additional packages required if not installed already:

    sendmail-cf
    m4
    make
    cyrus-sasl-plain

  • Edit ”/etc/mail/sendmail.mc”:
    define(`SMART_HOST', `{smtprelay.domain.tld}')dnl
    FEATURE(`authinfo',`hash -o /etc/mail/authinfo.db')dnl
  • Create file ”/etc/mail/authinfo” with below contents and chmod 640:
    AuthInfo:smtprelay.domain.tld "U:{username}" "P:{password}" "M:PLAIN"
  • Update the sendmail conf and db hashes:
    cd /etc/mail
    make
  • Restart sendmail for the new configs to pick up.
  • Now mails sent to localhost is relayed via your SMTP provider.

drweb antivirus update cron output

A cron is run every 30 minutes to check on virus database updates via /etc/cron.d/drweb-update, which cause a slew of emails addressed to drweb and filling up mail queue, since drweb does not have a maildir.

To resolve, direct the output to /dev/null or to a log file instead... if you need to keep a watch on the updates.

Edit /etc/cron.d/drweb-update redirecting the output to a log file:

*/30 * * * * drweb /opt/drweb/update.pl >>/tmp/drweb_update.log

If you still want to deliver the output, this can be done by directing drweb mail to root via "/var/drweb/.qmail" or "/var/qmail/alias/.qmail-drweb" with "&root".

Optimize PostgreSQL Database Size

Recently, I noticed that the postgresql database partition had been filled up. The general advice is to export data, drop and recreate database and import the data back in, since this would save a lot of time and also reduce the database size comparatively.

Reference: optimize postgresql database size.

Not too sure, if I wanted to go the dump and restore route, so decided to vacuum and reindex instead.

To my surprise, I did regain about 70% of space running the full vacuum and reindexing the database.

  • Full vacuum reduced the database size from 8GB to 4GB.
    vacuumdb -afzv | tee /tmp/vacuumdb.log
  • Reindex then reduced further to 2.5GB.
    reindexdb -a | tee /tmp/reindexdb.log
  • Total of 5.5GB space reduced with a full vacuum and reindex of the database.
  • Check the vacuumdb.log for database optimization notices.
  • It is also advised to reindex prior to vacuuming to further save on vacuum time.

#2002 - The server is not responding

PhpMyAdmin Error:

#2002 - The server is not responding (or the local MySQL server's socket is not correctly configured)

There are various reasons for this error. Several things to check are:

  1. Edit config.inc.php file, and specify '127.0.0.1' (instead of any other value like 'localhost) for the $cfg['Servers'][$i]['host'] setting as follows:

    $cfg['Servers'][$i]['host'] = '127.0.0.1';

  2. Check my.cnf file for the following entries:

    [mysqld]
    socket=/tmp/mysql.sock
    old-passwords

    [client]
    socket=/tmp/mysql.sock

    Only add the 'old-passwords' mentioned above if you are using an older version of PHP (PHP4).

  3. Make sure that you do not have any older versions of MySQL installed that are conflicting.
  4. Edit config.inc.php file, and specify the MySQL socket location (as seen in the above [mysqld] socket setting):

    For example, if your MySQL socket is /tmp/mysql.sock, find the line in config.inc.php that has the $cfg['Servers'][$i]['socket'] setting and change it to:

    $cfg['Servers'][$i]['socket'] = '/tmp/mysql.sock';

  5. Set the connection mode to socket by changing $cfg['Servers'][$i]['connect_type'] to:
    $cfg['Servers'][$i]['connect_type'] = 'socket';

    If there is no such setting, simply add in the above line and re-try.

  6. Add this entry to php.ini file (again changing the '/tmp/mysql.sock' to your actual socket location) and restart Apache:

    mysql.default_socket = "/tmp/mysql.sock"

  7. Edit the config.inc.php using the phpmyadmin /setup configuration page:

    In the setup screen, select the end-of-line character to be '\r' if you have a Macintosh, or '\n' for a Linux machine.

  8. Disable SELinux if you are using it, and re-try. If it works, SELinux is the issue.
  9. Run the following at your mysql prompt (using the standard mysql client):
    mysql> SELECT USER,HOST FROM mysql.user;

    Next, identify the user your are using for phpMyAdmin, and then run:

    mysql> SHOW GRANTS FOR 'user'@'host';

    Ensure that this userid has appropriate access rights.

Syndicate content
Comment