Home Random Sh17cast Forums

Using Monit to keep your services online

Tuesday, December 1, 2009

Thesh17′s been running on a linode VPS for a month or so now.   It works great until it gets railed, and apache dies.     Then a few hours later I notice the site’s down and login to restart it.    Originally I wrote a shell script that would just check if httpd was running.  If it wasn’t, it’d start it.   It’d also check the output of ‘free -m’ and if memory usage(not counting buffers) was greater than 90%, restart apache.

You’d think that’d be good, right?  Wrong.   I don’t know why, but occasionally things would get confused.  It’d see httpd running, but it wasn’t serving any pages on port 80.    service httpd status would show it was stopped, but the script didn’t check http connectivity or the actual pid file. I honestly didn’t troubleshoot this much, and just manually killed the processes/restarted httpd.

I decided to search for some scripts similar to mine(and better), but instead ended up landing on a utility called Monit.   It’s basically a service monitor you can run(locally or remotely) and depending on different conditions, it will restart the service and make sure it’s running.     This can be as simple as the pid in the pid file not existing, or more complex like the process has been using 90% of the cpu for the last 30 minutes.

As an example, here’s what my apache monit config looks like right now:

check process httpd with pidfile /var/run/httpd.pid
group apache
start program = "/sbin/service httpd start"
stop program = "/sbin/service httpd stop;pkill -9 httpd"
if failed host 127.0.0.1 port 80 protocol http then restart
if cpu is greater than 60% for 2 cycles then alert
if cpu > 80% for 5 cycles then restart
if children > 150 then restart
if loadavg(5min) greater than 10 for 8 cycles then alert
if memory > 90% for 2 cycles then restart
if 5 restarts within 5 cycles then timeout

Monit is pretty simple to install. It’s available in most distro’s repositories. On centos:

root@server:# yum install monit

On Gentoo:

root@server:# echo "=app-admin/monit-5.0.3" >> /etc/portage/package.keywords;
root@server:# emerge -av monit

I’m going to give Monit a try for a few weeks and see how it works out. I’ve been using nagios lately as well, but it seems kind of cumbersome to me and mainly one used for monitoring/reporting. Monit will actually restart a service if it detects a problem which *usually* is a good thing.

posted by johntash at 4:25 pm  

Installing MythTV from SVN on Ubuntu

Thursday, December 27, 2007

This is part one of a series about MythTV and using Ubuntu as a HTPC.  In this article we’ll explain the easiest (or hardest, to some people) step of the process of installing MythTV on Ubuntu Gutsy.

We’ll be installing MythTV using the svn source, which is the latest bleed-edge version of the source code.  There is a chance that the SVN version of MythTV may not be stable. Be Careful!

Lets start by downloading the source code:

  1. Install subversion
  2. sudo aptitude install subversion

  3. Checkout the mythv* trees
  4. cd ~
    mkdir src
    cd src
    svn co http://svn.mythtv.org/svn/trunk/mythtv
    svn co http://svn.mythtv.org/svn/trunk/mythplugins
    svn co http://svn.mythtv.org/svn/trunk/myththemes

Install the extra libraries and tools we need

sudo apt-get install checkinstall fakeroot debhelper libglut3-dev libxvmc-dev libmysqlclient15-dev libtiff4-dev libexif-dev libmad0-dev libid3tag0-dev libvorbis-dev libflac-dev libcdaudio-dev libcdparanoia0-dev fftw3-dev libfaad2-dev libsmpeg-dev libmp4v2-dev libtag1-dev
#we also need this header file for MythMusic
sudo wget http://faac.cvs.sourceforge.net/*checkout*/faac/faad2/common/mp4ff/mp4ff_int_types.h -P /usr/local/include

If you get any errors from the above two commands; leave a comment here and I’ll try to see if I’ve left something out.

Before we actually compile and install the svn version of MythTV; Remove the previous installation(if there is one)

aptitude remove ubuntu-mythtv-frontend mythtv-transcode-utils mythtv-common mythtv-frontend mythtv-themes mythtv-backend mythtv mythtv-frontend mythtv-database mythtv-backend-master


Change remove to purge if you want to delete the configuration files as well, not just upgrade.

Configure the Source

./configure --prefix=/usr
cd ../mythplugins
./configure --prefix=/usr
cd ../myththemes
./configure --prefix=/usr

Compiling the Source

Letting make run it’s course is the most time consuming part of the process, so if you have something else to do while it’s compiling. Go do it.

cd mythtv
make -j2
cd ../mythplugins
make -j2

Installation

Simply run checkinstall and answer a few questions

cd ~/src/mythtv; sudo checkinstall

When it promts you, simply enter Mythtv or whatever you want for the description. The package name should automatically be mythtv. By using checkinstall we are still using Ubuntu/debian’s package system to install Mythtv and everything will be a lot easier to uninstall or upgrade in the future.
IMPORTANT: Change the version field to something like 20071226 (todays date) so that we don’t get an error building the package.(see screenshot below)
Checkinstall version setting

If everything went well you should get something similiar to this:

**********************************************************************

Done. The new package has been installed and saved to

/home/bawls/src/mythtv/mythtv_999999-1_amd64.deb

You can remove it from your system anytime using:

dpkg -r mythtv

**********************************************************************

Do the same thing for mythplugins

cd ~/src/mythplugins
sudo checkinstall

Upgrading

Alright so now you want to upgrade to the latest and greatest again. Here’s how:

  1. Update the source
  2. cd ~
    cd src/mythtv
    svn update
    cd ../mythplugins
    svn update
    cd ../myththemes
    svn update

  3. Configure
  4. cd ~/src/mythtv
    ./configure --prefix=/usr
    cd ../mythplugins
    ./configure --prefix=/usr
    cd ../myththemes
    ./configure --prefix=/usr

  5. Install
  6. cd ~/src/mythtv; sudo checkinstall
    cd ~/src/mythplugins; sudo checkinstall
    cd ~/src/mythplugins; sudo checkinstall

    Only this time when you run checkinstall; increment the Release field. So if it’s 1 now, change it to 2. dpkg will upgrade it to this new package.

Conclusion / Possible Problems

If you already know how to configure and setup mythtv, you should be good to go on your own now (with the latest bleeding-edge features.)

Stay tuned for Part II in the series, but until then if you encounter any problems following this how-to guide; Please post a comment or send me an email with the issue you’re having.  We’ll get it resolved!

References:

[1]http://www.mythtv.org/wiki/index.php/Installing_MythTV_SVN_on_Ubuntu_Breezy
[2]https://help.ubuntu.com/community/MythTV_Gutsy_Backend_Frontend_Desktop
[3]http://www.mythtv.org/wiki/index.php/Ubuntu_Dapper_Installation#After_Installation

posted by johntash at 5:55 am  

Ubuntu: hellanzb for easy downloading from newsgroups

Saturday, December 1, 2007

Preface

This guide is written for Ubuntu or any debian-based distro of Linux; Mainly because I’m lazy and decided to use apt-get.
I’m also not going to explain newsgroups or .nzb files in general right now. I might write a follow-up for that later. I do however recommend the use of Giganews.

  • One: I get a small discount if you use my referral to sign up.
  • Two: It’s only $20 for the first month with unlimited download, 20 connections, and SSL.
  • Three: It’s the best usenet provider I’ve found so far and is able to max out my connection. Way faster than BitTorrent.


Update:   Astraweb is offering a special.    $11/mo for the life of your account.   I’ve been using them for several months with no complaints.    If you’re looking for the best deal, you may want to try Astraweb.

Hellanzb preview 1

What is HellaNZB?

Here’s a description straight from their website:

hellanzb is a Python application designed for *nix environments that retrieves nzb files and fully processes them. The goal being to make getting files from Usenet (e.g.: Giganews Newsgroups) as hands-free as possible. Once fully installed, all thats required is moving an nzb file to the queue directory. The rest; fetching, par-checking, un-raring, etc. is taken care of by hellanzb.

Installation of HellaNZB

  1. Open a terminal or connect to your server using SSH.
  2. Use apt-get to install the prereqs :
    sudo apt-get install rar unrar par2 python-dev python-twisted python-pyopenssl wget tar screen
  3. Download hellanzb and extract it. (Check the website to get the latest version)
    cd ~ ;
    wget http://www.hellanzb.com/distfiles/hellanzb-0.13.tar.gz ;
    tar xvf hellanzb*tar.gz ;
    cd hellanzb-0.13
  4. Install it (requires root access)
    sudo python setup.py install
  5. Copy the configuration file
    sudo cp /usr/etc/hellanzb.conf.sample /usr/etc/hellanzb.conf
  6. Edit the configuration file (replace vim with editor of choice)
    sudo vim /usr/etc/hellanzb.conf

    1. Make sure you configure the server information in the .conf file.  It’s pretty self explanatory and gives examples.
    2. If you’re planning to use SSL; make sure you enable the SSL option and change the port from 119 to 443.
    3. Set the PREFIX dir to something like /home/username/ or /mnt/storage/hellanzb/
  7. That’s it.  You can download a .nzb file and put it in PREFIX_DIR/nzb/daemon.queue/ and if hellanzb is running, it will automatically start processing the .nzb file and then download its contents.   Start hellanzb like this:
    hellanzb.py
  8. Once it finishes downloading a file.  It’ll check to make sure it’s all there and repair it using PAR if it needs to, then unrar it and copy the extracted content to PREFIX_DIR/usenet. It’ll also delete the .rar and .par files once it’s done with them.

Make Hellanzb startup on boot as an init script

I found this init.d script on the ubuntu forums that basically starts hellanzb in a screen session at boot.

  1. Download my slightly modified init.d script
    wget http://www.thesh17.com/wp/wp-content/uploads/2007/12/hellanzb ;
  2. Copy and chmod the script
    sudo cp hellanzb /etc/init.d/hellanzb
    sudo chmod +x /etc/init.d/hellanzb
  3. Set it to run on boot
    sudo update-rc.d hellanzb defaults
  4. Edit the init.d script to run hellanzb as your user(IMPORTANT)
    sudo vim /etc/init.d/hellanzb

    1. Change HELLAUSER=yourusernametorunhellanzbas to reflect your username.
  5. Start hellanzb to see if it all worked
    sudo /etc/init.d/hellanzb start

Alternate Method to start on boot

If you get any errors. Just add this line inside /etc/rc.local and change $HELLAUSER to whatever your username is.

su -c '/usr/bin/screen -S hellanzb -d -m /usr/bin/python /usr/bin/hellanzb > /dev/null 2> /dev/null' $HELLAUSER

Now then.  You should be all set.  Just use SFTP or one of the web interfaces to hellanzb and download .nzb files into the queue folder.

posted by johntash at 6:49 pm  

Gaim == Pidgin

Tuesday, April 10, 2007

I stumbled on this today. Apparently the multi-service and multi-platform im client Gaim changed it’s name to Pidgin a few days ago. They’ve been having legal troubles with AOL since they patented AIM.

It’s still the same program, but now the developers are going to start releasing real versions and not just beta versions. Their new web page is http://www.pidgin.im/

“After a long, and unfortunately secret debate (as we could not say why we were looking at a name change, we ended up just doing this ourselves), we settled on the name “Pidgin” for gaim itself, “libpurple” for libgaim (which, as of 2.0.0 beta6, exists), and “Finch” for gaim-text.”

Source: http://www.pidgin.im/ or http://gaim.sf.net

[tags]gaim,instant messaging,aim,aol,legal,software,freeware,stumbleupon,im,pidgin,linux,windows,opensource,open-source,open source[/tags]

posted by johntash at 12:39 am  

Update Your Software Automatically (On Windows)

Wednesday, April 4, 2007

Update:  FileHippo now includes an installer for their update checker program and the filesize is ~150kb.    Direct link to stand alone version is still available:  http://filehippo.com/updatechecker/UpdateChecker.exe

Part of the post that wordpress screwed me out of, was this software updater I saw at Google Operating System from FileHippo.

It’s kind of like `emerge -nupDv world` or `apt-get upgrade` but for windows, where there is no central repository for software. You download the 108kb exe 154kb exe with installer from filehippo and it’ll automatically scan your harddrive for software you have installed, send it to filehippo and then output a page similar to below showing you what software is out-dated with links where you should download the updated version.

filehippoupdatechecker

This is only going to work with software that FileHippo knows about and can find, but it’s still pretty useful if you like keeping your system up to date.

The next best thing I know of for windows is Google’s Google Pack.

posted by johntash at 3:26 pm  

8 queries. 0.379 seconds.
Copyright © 2007-2010 http://www.thesh17.com