Linux
New CVGM.net Server Upgrade Almost Ready!
0This is the new Dell PowerEdge 2950 server that will be used on the CVGM.net website. It’s packing a nice dual quad-core 3.16Ghz CPU, 16gb of ram, and VMWare to make management and repairs easier and better. The current server only has 2GB of ram, and a very ancient quad-core 2.1Ghz cpu (one of the first Xeon quad core CPU’s released). We are still adding some bits to it, saving up our spare change and buying them as we can.
In the next few weeks, this bad boy will be shipped off to the datacenter and installed in it’s rack, so the site can receive a much-needed upgrade.
If you want to check out CVGM and listen to some great oldskool computer game music, check out http://www.cvgm.net Thanks!
Running a Django / mod_wsgi project on DirectAdmin Server
0Recently I purchased a new Dedicated server box running Ubuntu 8.10 / DirectAdmin and needed to transfer a bunch of my stuff to it. One of the sites I needed to trandsfer was CVGM ( http://www.cvgm.net ) which is powered by Django / Python / Mod_WSGI. I couldn’t find many instructions on the net on how to complete the task easily, so after I figured out how to do it, I wanted to post my results here so that other people who need the same kind of help can find the post and maybe use it 🙂
The DirectAdmin default setup uses a customized version of Apache in order to work, and as a result, it’s not as simple to work with/customize as a regular install of apache. To give you an example, if you would apt-get a module (such as mod_wsgi) that relies on apache2 as a dependency, it thinks apache2 isn’t even installed, so be careful! The global config file for the DirectAdmin apache is /etc/httpd/conf/httpd.conf and I should point out that right now, you should not edit anything in this file whatsoever!!
First, we need to install the Apache module for Mod WSGI. I copied a version of the file from a copy of 8.10 Server I installed on a VM to make sure it matched the same system requirements (Python 2.5) however you can always build one, or obtain one from somewhere on the net. Once I built the file with my sodapdf editor, I copied it to /usr/lib/apache/mod_wsgi.so on the dedicated box.
There are two ways that you can proceed to activate the module, and i’ll explain both ways. The 1st way is probbably more beneficial if you plan on running multiple WSGI applications, whereas the second is better if you just plan on running a single site and you don’t want to initialize it for every thread your apache creates.
Enabling As Global Module
This is the simplest method of enabling the module. Open the following file for editing:
vim /etc/httpd/conf/extra/httpd-phpmodules.conf
There should already be a line in there for PHP, so we only need to add the following line underneath it:
LoadModule wsgi_module /usr/lib/apache/mod_wsgi.so
Save and Exit the file, if you restart the httpd instances within DirectAdmin, they will all have access to mod_wsgi features.
Setting up a VirtualHost to run a WSGI Application
I’d like to point out here that we are manually editing/changing the automated VirtualHost information generated from within DirectAdmin, so DirectAdmin might change it all back again if you go to edit anything through the admin panels. Remember, when it works, back it up in case that does happen!
The VirtualHost lists are defined in a user’s httpd.conf file, so to edit the list for your site, run the following command:
vim /usr/local/directadmin/data/users/[UserName]/httpd.conf (Replacing UserName with the user account name set up under your site)
Modify the top portion of your Vhost file to look like the following, with your own WSGI settings of course:
# Frontpage requires these parameters in every httpd.conf file or else # it won't work. ServerRoot /etc/httpd WSGIDaemonProcess ProcessName threads=25 WSGIProcessGroup ProcessName <VirtualHost *:80> ...
Inside the VirtualHost container, you will add your actual WSGI code as such:
# Load the WSGI adapter just for this VirtualHost, if you choose not to enable it # Globally. Do not add this line if you added the module globally!! LoadModule wsgi_module /usr/lib/apache/mod_wsgi.so # Set up Aliases to Django admin, and our own static files Alias /media/ /usr/share/python-support/python-django/django/contrib/admin/media/ (path might vary on your setup) Alias /static/ /path/to/static/ <Directory /usr/share/python-support/python-django/django/contrib/admin/media> (path might vary on your setup) Order deny,allow Allow from all </Directory> # Direct root to our WSGI script file WSGIScriptAlias / /path/to/file.wsgi <Directory /path/to> Order deny,allow Allow from all </Directory> <Directory /path/to/static> Order deny,allow Allow from all </Directory>
Save the changes to your VirtualHost. I would like to point out here, that for CVGM I chose to comment out completely the same VirtualHost entry for SSL (port 443). My site has no use for SSL, and duplicating this code in the 2nd VirtualHost (which is what would happen if edit the Custom HTTPD for this domain in DirectAdmin) will cause an error for already having being called once.
The WSGI file for your project is created in pretty much the standard way:
import os, sys sys.path.append('/path/to') sys.path.append('/path/to/ExtraPath') os.environ['DJANGO_SETTINGS_MODULE'] = 'ProcessName.settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler()
Save it, double check the paths to the files and then restart httpd in DirectAdmin. If all goes well, the site should fire right up! If you start getting 503/500 errors, check the error.log file in the DirectAdmin viewer for a detailed description of what is happening. If there are no errors in the log, it’s not WSGI causing the problem, it’s something else in your code.
Common Error With Mod_WSGI and DirectAdmin
Depending on which version of DirectAdmin you are using, you may run into a massive slap-in-the-face 503 error regarding misconfiguration, and the error log will tell you something like: “No such file or directory: mod_wsgi (pid=7295): Unable to connect to WSGI daemon process”.
If you do run into this problem, you can try one of two things in the virtual host file. Here is a quote directly from Graham Dumpleton on the WSGI homepage explaining the problem and the solution ( http://code.google.com/p/modwsgi/wiki/ConfigurationIssues#Location_Of_UNIX_Sockets ) :
“To resolve the problem, the WSGISocketPrefix directive should be defined to point at an alternate location. The value may be a location relative to the Apache root directory, or an absolute path.
On systems which restrict access to the standard Apache runtime directory, they normally provide an alternate directory for placing sockets and lock files used by Apache modules. This directory is usually called ‘run’ and to make use of this directory the WSGISocketPrefix directive would be set as follows:
WSGISocketPrefix run/wsgi
Although this may be present, do be aware that some Linux distributions, notably RedHat, also locks down the permissions of this directory as well so not readable to processes running as a non root user. In this situation you will be forced to use the operating system level ‘/var/run’ directory rather than the HTTP specific directory.
WSGISocketPrefix /var/run/wsgi
Note, do not put the sockets in the system temporary working directory. That is, do not go making the prefix ‘/tmp/wsgi’. The directory should be one that is only writable by ‘root’ user, or if not starting Apache as ‘root’, the user that Apache is started as. ”
So, you would change the top of the VirtualHost to read something along the lines of:
WSGISocketPrefix /var/run/wsgi WSGIDaemonProcess ProcessName threads=25 WSGIProcessGroup ProcessName
After restarting Httpd in DirectAdmin, it should clear up the problem!
This was a post I had originally made a long time ago (November 2009), so I have edited/replaced it here for completeness, as I get a lot email requests about it. I don’t use this setup any longer, and use a dedicated box for CVGM which solved a lot of other issues that I was having at the time, and of course the dedicated box is running a much newer Ubuntu distribution. Thanks!
Dennis Ritchie, father of Unix and C, Has Passed Away
0Dennis Ritchie, creator of the C programming language and co-creator of the Unix operating system, has died aged at the age of 70.
Thank-you for giving us a superior language, and being a pioneer in the age of computing. Rest in peace!
/* for Dennis Ritchie */ #include <stdio.h> main()Â { printf("Goodbye World"); }
ZD Net Article:Â http://www.zdnet.com/news/dennis-ritchie-father-of-unix-and-c-dies/6314570
Wiki entry on C:Â http://en.wikipedia.org/wiki/C_%28programming_language%29Â
Toshiba L675D And Kubuntu 10.10 Maverick/Lucid No-Boot – SOLVED!
0I picked up a new laptop last week (L675D-S7015) to replace my failing HP laptop, and one of the first things that I wanted to be able to do on it was install Linux. On the old machine, when it was set to dual boot the Windows part would randomly reboot during startup, which was terribly annoying. So, on this machine I was very frustrated when I went to boot my 10.10 Kubuntu Live CD, and was just presented with a blinking cursor seconds after pushing the Start Kubuntu option from the disk menu!!
After a bit of playing and thinking about the problem, I remembered an issue I had a long time ago on a different Toshiba with ACPI. I did some googling and all I could find on the subject was people trying the ‘nomodeset’ and ‘forcevesa’ modes, which didn’t work in this particular case. I was able to remedy the issue by pushing F6 on the CD menu and select ‘acpi=off’ and then booting. Fired right up!
Once Kubuntu is installed, and you reboot for the first time, you will again experience the same problem. To fix this, we need to make a slight tweak to the Grub boot options. When the Grub menu appears showing your choice of OS, highlight the Linux kernel and push ‘e’ to edit it. If your linux doesn’t show the grub menu, you can hold shift during the beginning of the boot to show it. Scroll down to the part that says ‘quiet splash’ and add ‘acpi=off’ to the end of the string. Push Ctrl+X to boot it. You should find now that you can boot to the linux desktop.
Now we can get it to work, we need to make these changes permanent. Once booted, go to a terminal window and type ‘sudo vi /etc/default/grub’ and just like before, find the GRUB_CMDLINE_LINUX_DEFAULT and add acpi=off to the end, it should then read ‘quiet splash acpi=off’. Save the changes, exit the editor and you MUST run update-grub in order to make them permanent. It re-generates the grub configuration file, and makes the changes permanent.
After this is done, you can reboot to test it, but it should work without you needing to do anything else! You can proceed to install updates and new kernels, and the option will automatically be applied when the kernel is upgraded!
If like me you boot to more than one OS, while you are editing the grub config file you can change which OS is booted by default. Looking at GRUB_DEFAULT which is 0 by default, and will boot the topmost option. Set it to 3, it will boot the 3rd OS in the list. Set it to whichever OS you want to boot if it isnt the default, and dont forget to update-grub! You can also change the GRUB_TIMEOUT value from 10 seconds to anything you please.
I took some crude pictures using my phone of the process. Hope this helps someone else who has been frustrated with this process!
Dual-Booting Kubuntu Alongside Windows 7 Without Wubi – Properly!
0The hard drive took a major dump in my laptop this weekend, left it backing up some stuff while I went to go see Tron, and when I got home it sounded like a DJ was scratching some kind of new rap tune. Needless to say, the drive was on its way out, but luckily I have been able to recover almost all of my data so far 🙂
After installing a replacement hard drive, I thought it was about time that I put a dedicated linux partition on this system as I have been using Kubuntu to do some Android development (installed via Wubi). While Wubi is nice for messing around, it isn’t the most stable system to be using and I have had a couple of disasters in the past with it messing up my virtual partitions. Wubi also has some known bugs, where after installing inside Windows, you’ll get a message about no root filesystem being defined and that you should fix it in the partition manager. Nice, if you can actually get there to do it!
So, I installed Windows 7, left 40gb of free space intentionally for Kubuntu. After the process of doing all the software installs and updates etc. for Windows I thought that I had better take a shot at installing the Linux side of things. Boy, what a mess 🙂 Firstly, there is something about the partition layout in Windows 7 that GPartEd just cannot see them (even using the GPartEd Live CD, or any LiveCD including Kubuntu). It thinks my hard drive is completely unpartitioned. Not what I was expecting, as I was hoping I could just throw some linux partitions into the free space, and then install. Very confusing 🙂 Adding any changes at this point would erase my new Windows 7 partition instantly.
I remember something a friend told me years ago about partitioning, that he had once used Linux to do the partitioning of his drives for some wierd XP install, as the Windows tools at the time were quite shit, so I figured that to get this to work the way I want it, I should probbably attempt something similar. I didnt really have much to lose (besides sitting through a few hundred megs of Windows Updates) so I went ahead and prepared the partition in GPartEd.
An important thing to remember here is the partition table. You must go into the Partition Table section and create a new ms-dos partition table, otherwise if you don’t it may try and use GPT by default (which won’t work with Windows 7). If you try to install Windows 7 without this partition type change, it will pop up a Warning message when you try to select the partition, and clicking Details will tell you that it cannot install on a GPT partition. So, after this step (which will completely zap your entire drive) I proceeded to create an NTFS partition, leaving 40gb free space for Linux later on. After applying the partition changes, booting the Windows 7 installer and installing windows by selecting the NTFS partition I just created, I was then able to reboot with a KUbuntu LiveCD and work with the free space on the drive correctly! It will even mount the Windows partition (just remember to hit Yes on the option to Unmount it duringi the Kubuntu install). Even grub works well and offers Windows 7 as an option in the boot menu.
When installing Linux with manual partitions, remember to add a swap partition at least 2x the size of the available ram in the machine, and the rest can then be an ext4 partition (that mounts to /) and thats the minimal that Kubuntu will need in order to boot correctly. Grub takes care of the rest of the issues with booting and selection etc. as most of Grub resides in the liunux part.
I am sure that several people have had problems trying to get the dual booting to work correctly, so I hope that this helps at least one human being out there who has struggled with this as long as I have.
Converting Databases To UTF8 Format From Latin1
1I have been putting off the inevitable the last couple of weeks, which was the task of converting the database for CVGM.net to UTF8 from the default collation of latin1-swedish-ci. I am not the best when it comes to administering MySQL via command script, and phpMyAdmin didnt do the job properly of conversion for me. After a bit of googling, I found a bash script at islandlinux that was able to help me out considerably:
#!/bin/bash DATABASE=$1 if [ ! "$DATABASE" ]; then echo "Please specify a database" exit fi BACKUPDIR="/root/tmp/mysql_backups/" if [ ! -d "$BACKUPDIR" ]; then mkdir -p "$BACKUPDIR" fi BACKUP="$BACKUPDIR""$DATABASE.sql" mysqldump --add-drop-table --extended-insert "$DATABASE" > "$BACKUP" TABLES=`mysql --batch --execute 'SHOW TABLES' "$DATABASE" | grep -v "^Tables_in"` for TABLE in $TABLES; do echo 'ALTER TABLE `'"$TABLE"'` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;'; # uncomment the following line to process the commands #mysql --execute 'ALTER TABLE `'"$TABLE"'` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;' "$DATABASE" done
This script converted the database tables and everything under it to the correct format. It also backs up the databases first in case something decides to take a crap on you. The problem I had with phpMyAdmin was even though I changed the collation to utf8_general_ci it didn’t do it recursively into the tables and the fields underneath it.
Thanks for the script guys 🙂 You saved me even more work!
Automatically Restarting Apache2 Via Cronjob If It Crashes
0I have been having an issue with my trac server that causes random apache2 crashes, and as of late I haven’t been able to figure out exactly what is causing them, seems the server just seems to automagically turn off at random intervals.
This is a script I put together to test if any of the apache2 executables are currently running:
#!/bin/sh run=`ps ax | grep /usr/sbin/apache2 | grep -v grep | cut -c1-5 | paste -s -` if [ "$run" ]; then echo "Apache2 is running" else /etc/init.d/httpd start fi
The script checks to see if they are, and if it can’t find any running tasks it will attempt to restart apache2. Install this to a crontab every couple of minutes, and it should cause Apache to auto-restart in the event of a crash. Works well on the trac server anyways 🙂
Recent Comments