Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Monday, November 19, 2012

Perl script to remove stale PID file

Here's a script for removing a stale PID file. It is my first real world perl script. This also happens to be my first blog this year, following the renaming of this blog from locait.blogspot.com. I had to create this script when apacheds refused to start due to a stale PID file.

#!/usr/bin/perl
# perl script to remove state pid file
# adapted from example at http://search.cpan.org/~cwest/File-Pid-1.01/lib/File/Pid.pm
# it expects the pid file as the sole argument

use File::Pid;
  if ($#ARGV < 0) {
        die "Expects the path to the pid file but received $#ARGV args";
}
  my $pidfile = File::Pid->new({
    file => "$ARGV[0]",
  });

  if (! $pidfile->running ) {
      $pidfile->remove;
  }

Thursday, September 29, 2011

Mounting a webdav url with davfs2

I found a very useful article online and my points of departure from the author's directions are summarised as a comment on the article and also quoted below.
Many thanks for the helpful information.
I placed the secrets file in ~/.davfs2/secrets and added an entry to /etc/fstab and it worked well.
Being on a 64bit system, I needed to install the 32 bit version of libneon27 for davfs2 to work.

Monday, September 12, 2011

Screen Capture/Recording with ffmpeg

My attempt to record a video tutorial was failing with the error 'x11grab AVParameters don't have video size and/or rate. Use -s and -r'. This was in response to typing in the following command as based on an example in the ffmpeg man page.

ffmpeg -f x11grab -s 1280x1024 -i :0.0 -r 25 -sameq /tmp/test.mpg

After several failed tries, I determined that the error could be coming from the -r option. I moved it to immediately after the -s option so that both -s and -r options followed the x11grab specification. This time, it worked great. The final command is shown below.

ffmpeg -f x11grab -r 25 -s 1280x1024 -i :0.0 -sameq /tmp/test.mpg

Monday, November 15, 2010

Using yum behind a proxy

I was recently attempting to install a software on centos 5 and ran into an error with the yum install command as shown below:
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=5&arch=x86_64&repo=os error was [Errno 4] IOError: <urlopen error (111, 'Connection refused')>


Setting the http_proxy did not help matters. I found documentation on forums that suggested adding the line proxy_http=http://proxy:port in /etc/yum.conf. That still did not help. I finally came across a post on centos forums that suggested that the setting to be made in /etc/yum.conf is actually proxy=... and not http_proxy=...

Monday, July 12, 2010

Getting Started with Amanda

Having initially considered Bacula, I chose amanda for use in backup due to it's better organized documentation. Being a newbie, I selected the quick start getting started tutorial as the first step through the online documents.

In that process, I consulted the bsd authentication howto for more information on authentication. I also found the vtape howto very helpful since I did not have a physical tape device. Having gone followed the tutorial and branching into the howtos at the relevant sections, I was able to do a successful test run.

Using another article in the howtos collection, I made further changes to the configuration to allow for dumps to be split across multiple tapes (vtapes in my case). It was then time to follow another howto to duplicate that configuration to the production environment where the virtual tapes needed to be configured for use on a non-Linux partition.

Friday, March 19, 2010

Password-less SSH Login

A google search will turn up several good step by step procedures to accomplish this. I realized after a few futile attempts that the file that is mentioned as authorized_keys in many places should actually be authorized_keys2 as described here.

I think the difference in file naming may have occurred due to changes in the OpenSSH tool set and a review of the change logs may be needed to confirm at what version the change was introduced.

Monday, March 15, 2010

Resizing an LVM /usr partition in OpenSUSE 11.1

The yast2 tool makes resizing lvm partitions a very straightforward matter. The only requirement is to unmount the partition being resized. To achieve an unmount of /usr one has to boot to single user mode since there are many process which have open files on that partition. Running lsof /usr | wc -l as root on one instance turned up 2588 files!

It turns out that after running umount /usr successfully in single user mode, yast2 disk fails since there are some files that yast2 needs in the unmounted /usr partition. This left me only with the option of using the console tools. Below is the sequence of commands that I run to add 5G to my /usr partition.

modprobe dm_mod
lvextend -L +5G /dev/mapper/system-usr
shutdown -r 0
resize2fs /dev/mapper/system-usr


The first command to load the device mapper kernel module was necessary since the module was not loaded automatically in my case. I was only able to resize the file system after a reboot because I could not figure out a way to mount the partition in single user mode but I believe it should be possible.

Monday, March 8, 2010

Generating a Tomcat PID file on the fly

I needed to use jsvc to stop tomcat processes, something that required a PID file containing the Process ID of the tomcat being stopped. My first alternative was to use jsvc to start Tomcat and specify the PID file to generate. Looking at the myriad of command line options that jsvc needed, I decided to stick to the provided startup.sh.

This left me with the option of generating the PID file after Tomcat had been started normally. For this, I used the lsof command of which I found an excellent reference. This is the command I used:

lsof -t -l -a -i TCP:$1 -a -c java > $tmp_file && /usr/local/bin/jsvc -stop -pidfile $tmp_file org.apache.catalina.startup.Bootstrap

The line above consists of two commands, one where lsof writes Tomcats PID into a file and the other where jsvc uses that file to shutdown Tomcat. Here is a break down of the options to lsof.

-t output the PID only
-l show ports that are in listening mode
-a and (this enables a boolean relation to be constructed between options)
-i TCP:$1 show a process with an open TCP port held in the shell input variable
-a and
-c java show processes with the name java