Geek Lair

Ubuntu Lucid: Disable services from starting up during boot time

with one comment

I use MySql only occasionally on my Ubuntu Lucid Lynx (10.04) install. As such, I didn’t want the mysql server starting up automatically during boot process. There must be a better way of disabling a service, but this is what worked for me:

Ubuntu now uses Upstart to startup services during boot time. The config files for the services are in /etc/init and they all have filenames ending in .conf.

The config files have a “start on” section which will have events on which the service should start. Commenting out that section prevents the service from starting automatically.

If you want to disable a service, say mysql, edit its config file – /etc/init/mysql.conf.

Change this:

start on (net-device-up
    and local-filesystems
    and runlevel [2345])
stop on runlevel [016]

to this:

#start on (net-device-up
#    and local-filesystems
#    and runlevel [2345])
stop on runlevel [016]

Reboot.

To see the status of the Upstart jobs run this command:

initctl list

The output should look something like this:

alsa-mixer-save stop/waiting
avahi-daemon start/running, process 1061
mountall-net stop/waiting
nmbd stop/waiting
rc stop/waiting
rsyslog start/running, process 1046
.
.
mysql stop/waiting
.
.

Since the “start on” section was commented out in /etc/init/mysql.conf, the mysql job status will show up as “stop/waiting”

To start the mysql server manually, use the start command:

sudo start mysql

Now if you run the command initctl list, the mysql job will be in running status:

alsa-mixer-save stop/waiting
avahi-daemon start/running, process 1061
mountall-net stop/waiting
nmbd stop/waiting
rc stop/waiting
rsyslog start/running, process 1046
.
.
mysql start/running, process 9462
.
.

To stop the mysql server, use the stop command:

sudo stop mysql

Written by anonir

August 9, 2010 at 23:28

Posted in Linux, Ubuntu

Tagged with , , ,

Ubuntu Lucid: Disable boot splash

with 4 comments

When you boot into Ubuntu Lucid Lynx (10.04), you only get a splash screen. You can’t see the boot messages. To disable the splash and show the boot messages, you need to edit grub.

Note: If you had upgraded from an earlier Ubuntu version, you might still be having the older grub version. See this guide to upgrade to grub2.

Open /etc/default/grub for editing and remove “quiet splash” options from the GRUB_CMDLINE_LINUX_DEFAULT property.

For example, if your grub has this line:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"

Change it to this:

GRUB_CMDLINE_LINUX_DEFAULT=""

Then run this command to update grub2:

sudo update-grub

Written by anonir

August 8, 2010 at 12:26

Posted in Linux, Ubuntu

Tagged with , , ,

Ubuntu Karmic: 5.1 sound on external sound card

with one comment

Most laptops usually come with stereo audio output. I bought an external USB 5.1 channel sound card and was trying to get 5.1 sound out of it. By default in Ubuntu 9.10, pulseaudio is configured to output stereo. It doesn’t automatically switch to 5.1 if a sound card which supports it is connected. Here is how I got 5.1 audio output through my external sound card:

First edit /etc/pulse/daemon.conf and uncomment this line (delete the ; before the line):

default-sample-channels = 6

Restart. Now if your external sound card is plugged in, pulseaudio will enable 5.1 output on it. All you need to do is go to sound preferences (System -> Preferences -> Sound) and select 5.1 profile for the external sound card in the Hardware tab:

5.1 profile in sound preferences

5.1 profile in sound preferences

and select the external sound card as default output device:

Default output device

Default output device

If your external sound card was not connected while Ubuntu starts, pulseaudio defaults to stereo as the integrated sound card in the laptop is stereo. Now if you connect the sound card, 5.1 options are not available. Only stereo is available:

stereo profile in sound preferences

stereo profile in sound preferences

You have to restart pulseaudio for it to enable 5.1 output. Kill pulseaudio with this command:

pulseaudio -k

In my Ubuntu installation, when I kill pulseaudio, it starts again automatically. If it doesn’t do so, start pulseaudio with this command:

pulseaudio -D

Once pulseaudio restarts, it should have enabled 5.1 output.

Written by anonir

February 17, 2010 at 21:51

Posted in Ubuntu

Tagged with , , ,

JSF – Richfaces Ajax Modal Dialog

with 3 comments

Creating a Richfaces Modal dialog is simple enough as explained in the Richfaces reference document. But I wanted an ajax modal dialog which will be shown on click of a link. Here is how to go about it:

My requirement is, I have a user page with an “Update Profile” link. On clicking the link, a modal dialog should popup which has a form for updating the profile.

In the user page I have a form, since a4j:commandLink element should be in a form:

<h:form id="inboxForm">
	<div id="topBar">
    	<a4j:keepAlive beanName="userBean" ajaxOnly="true"/>
		<a4j:commandLink oncomplete="#{rich:component('editPanel')}.show()" 
			reRender="editPanel" value="#{msgs.updateProfile}">
			<f:setPropertyActionListener value="#{inbox.userLogin}" 
			target="#{userBean.currentUser}"/>
		</a4j:commandLink>
    	<h:commandLink action="#{login.logout}" value="#{msgs.logout}"/>
	</div>
</h:form>

userBean has a request scope and that is why I have an a4j:keepAlive element so that the bean is kept alive during the ajax call.

The a4j:commandLink has a f:setPropertyActionListener element which will set a the currentUser object on userBean. After the ajax request has been made, the editPanel, which is the modal dialog, will be re-rendered. The oncomplete attribute has a JavaScript call to show the modal dialog (by default, it will be hidden).

Here is my modal panel:

<a4j:outputPanel layout="none">
	<rich:modalPanel id="editPanel" width="530"  height="320"
		rendered="#{not empty userBean.currentUser}">
		<f:facet name="header">
            <h:outputText value="#{msgs.updateProfile}" />            
        </f:facet>
        <f:facet name="controls">
            <h:panelGroup>
                <h:graphicImage value="/css/images/close.png"
                    styleClass="hidelink" id="hidelink1" />
                <rich:componentControl for="editPanel" attachTo="hidelink1"
                    operation="hide" event="onclick"/>
            </h:panelGroup>
        </f:facet>
		
		<a4j:include viewId="/profile.jsp"/>
	</rich:modalPanel>
</a4j:outputPanel>

Since the modal panel should be rendered on an ajax call, I have it enclosed in a a4j:outputPanel tag. The layout="none" means that no html tag will be rendered. If no layout is specified, a span tag will be rendered. If layout="block", a div will be rendered.

The rich:modalPanel has a rendered="#{not empty userBean.currentUser}" attribute. It means that the modal panel will be rendered only when userBean.currentUser is not null.

The modal panel has a header facet which has a title and a close icon. The form is included with an a4j:include tag. Here is the profile.jsp:

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%@taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@taglib uri="http://richfaces.org/rich" prefix="rich"%>
<h:form id="profileForm">
<div id="profileContainer">
<a4j:outputPanel ajaxRendered="true">
	<div class="messages">
		<h:messages globalOnly="true"/>
	</div>
	<fieldset>			
	    <ul>
		<li>
		    <h:outputLabel value="#{msgs.firstName}" for="fname"/>
		    <div class="innerList">
			<ul>
			    <li>
				<h:inputText id="fname" 
				value="#{userBean.currentUser.userDetails.firstName}"
				maxlength="30">
				    <f:validateLength maximum="30"/>
				</h:inputText>
			    </li>
			    <li id="fnameErr" class="hidden">
				<h:message for="fname" errorClass="error" />
			    </li>
			</ul>
		    </div>				    
		</li>
		<li>
		    <h:outputLabel value="#{msgs.lastName}" for="lname"/>
		    <div class="innerList">
			<ul>
			    <li>
				<h:inputText id="lname" 
				value="#{userBean.currentUser.userDetails.lastName}"
				maxlength="30">
				    <f:validateLength maximum="30"/>
				</h:inputText>
			    </li>
			    <li id="lnameErr" class="hidden">
				<h:message for="lname" errorClass="error" />
			    </li>
			</ul>
		    </div>					
		</li>
		<li>
		    <h:outputLabel value="#{msgs.enterNewPassword}" for="pwd">
		    </h:outputLabel>
		    <div class="innerList">
			<ul>
			    <li>
				<h:inputSecret
				    id="pwd" value="#{userBean.password}" maxlength="15" redisplay="true"
				    requiredMessage="#{msgs.enterPasswordReq}">
				<f:validateLength minimum="6" maximum="15"/>
				</h:inputSecret>
			    </li>
			    <li><h:message for="pwd" errorClass="error" /></li>
			    <li id="pwdErr" class="hidden">
				<span class="error"><h:outputText value="#{msgs.enterPasswordReq}"/></span>
			    </li>
			    <li><h:outputText value="#{msgs.minPwdLenth}"/></li>
			</ul>				    
		    </div>
		</li>
		<li>
		    <h:outputLabel value="#{msgs.reenterNewPassword}" for="repwd">
		    </h:outputLabel>
		    <div class="innerList">
			<ul>
			    <li>
				<h:inputSecret
				    id="repwd" value="#{userBean.repassword}" maxlength="15" redisplay="true"
				    requiredMessage="#{msgs.reenterPasswordReq}">
					<f:validateLength maximum="15"/>
				</h:inputSecret>
			    </li>
			    <li><h:message for="repwd" errorClass="error" /></li>
			    <li id="repwdErr" class="hidden">
				<span class="error"><h:outputText value="#{msgs.reenterPasswordReq}"/></span>						
			    </li>
			</ul>				    
		    </div>				    
		</li>
		<li>
		    <h:outputLabel value="#{msgs.emailAddr}" for="email">
			<span class="redText">*</span>
		    </h:outputLabel>
		    <div class="innerList">
			<ul>
			    <li>
				<h:inputText 
				    id="email" value="#{userBean.currentUser.userDetails.emailId}" maxlength="40"
				    requiredMessage="#{msgs.emailAddrReq}" required="true">
				    <f:validateLength maximum="40"/>
				</h:inputText>
			    </li>
			    <li><h:message for="email" errorClass="error" /></li>
			    <li id="emailErr" class="hidden">
				<span class="error"><h:outputText value="#{msgs.emailAddrReq}"/></span>						
			    </li>
			</ul>
		    </div>				    					
		</li>				
	    </ul>
		<div class="spacerDiv"></div>
	    <ul class="hor_li">
			<li><a4j:commandButton id="profUpdate" value="#{msgs['btn.update']}" 
				action="#{userBean.updateProfile}"/></li>
			<li><a4j:commandButton id="profCancel" value="#{msgs['btn.cancel']}" 
				oncomplete="#{rich:component('editPanel')}.hide();"/></li>
		</ul>
	</fieldset>
</a4j:outputPanel>						
</div>
</h:form>

The profile form has two a4j:commandButton elements. One for submitting the form data and the other for closing the modal dialog. The form submission is through ajax and any validation errors are shown after the server responds to the ajax call.

Written by anonir

February 13, 2010 at 14:57

Posted in JEE, Web

Tagged with , ,

mplayer plugin for Firefox in Ubuntu Karmic

with one comment

By default, Firefox in Ubuntu uses totem to play video files. If you want to use mplayer instead, do this:

1. Uninstall the totem plugin:

sudo apt-get remove totem-mozilla

2. My Ubuntu installation also had a gecko mediaplayer plugin. Remove it:

sudo apt-get remove gecko-mediaplayer

3. Install mplayer plugin:

sudo apt-get install mozilla-mplayer

Now enjoy mplayer on your Firefox.

Written by anonir

February 5, 2010 at 20:20

Posted in Ubuntu

Tagged with , ,

Gnome Do startup problem

with 3 comments

If you have added Gnome-do to Startup Applications, sometimes after you login in Ubuntu and launch Gnome-do application selector, it doesn’t work. The issue seems to be that Gnome-do depends on some other program which needs to start first before Gnome-do starts. The issue can be fixed by wrapping the gnome-do command in a shell script which adds some delay¬† and adding that script to Startup Applications instead of gnome-do:


!/bin/bash

sleep 10
gnome-do

Save it to your $HOME/bin folder and add it to Startup Applications

Add gnome-do wrapper to startup

Written by anonir

February 5, 2010 at 00:58

Posted in Ubuntu

Tagged with ,

Linux From Scratch – Troubleshooting

with 3 comments

I’m using Cross Compiled LFS Guide, as my host system is 64 bit (Ubuntu 9.10).

Some of the package links given in the guide are dead. Search in Google with the package name.

Below, I have listed section numbers from the guide.

5.5.1. Installation of Linux-Headers

While doing a make:

make ARCH=x86_64 headers_check

I got this error:

CHK include/linux/version.h
HOSTCC scripts/unifdef
scripts/unifdef.c:209: error: conflicting types for 'getline'
/usr/include/stdio.h:651: note: previous declaration of 'getline' was here
make[1]: *** [scripts/unifdef] Error 1
make: *** [headers_install] Error 2

The issue is, there is a function with the name “getline” in stdio.h and unidef.c too has a function with the same name and that was causing a conflict. I had to edit scripts/unifdef.c and replace “getline” with “parseline“. (You can replace “getline” with any other name as long as it doesn’t conflict with existing function names)

5.7.1. Installation of Cross Binutils

While building cross binutils I got these errors:

(Before trying the solution for Error 1, try the solution for Error 2. It may fix Error 1 as well.)

Error 1

../../binutils-2.18/binutils/cxxfilt.c:66: error: format not a string literal and no format arguments
../../binutils-2.18/binutils/cxxfilt.c:71: error: format not a string literal and no format arguments

Edit binutils-2.18/binutils/cxxfilt.c and specify “%s” in printf:

line 66:
- printf (mangled_name);
+ printf ("%s",mangled_name);

line 71:
- printf (result);
+ printf ("%s",result);

Error 2

cc1: warnings being treated as errors
../../binutils-2.18/gas/read.c: In function 'do_s_func':
../../binutils-2.18/gas/read.c:5631: error: ignoring return value of 'asprintf', declared with attribute warn_unused_result
../../binutils-2.18/gas/read.c:5638: error: ignoring return value of 'asprintf', declared with attribute warn_unused_result

The problem is the compiler is treating all warnings as errors as -Werror flag is set. I have no idea where that flag was getting set. But in binutils-2.18/configure file, I saw this condition:

case ${enable_werror} in
yes) stage2_werror_flag="--enable-werror-always" ;;
*) stage2_werror_flag="" ;;
esac

and passed the flag --enable-werror=no to the configure script:

AR=ar AS=as ../binutils-2.18/configure --prefix=/cross-tools \
--host=${CLFS_HOST} --target=${CLFS_TARGET} --with-lib-path=/tools/lib \
--disable-nls --enable-shared --enable-64-bit-bfd --disable-multilib --enable-werror=no

That did the trick.

Written by anonir

February 5, 2010 at 00:39

Posted in Linux

Tagged with ,

Effective Computer Usage

leave a comment »

These are some of the things which I do to speed up the work I do with computers.

Learn Shortcuts

Shortcuts can be your biggest time saver. Instead of dragging the mouse to a menu, selecting an option which opens another window and then finally choosing an action, if that action has a shortcut associated with it, you can do it much faster with the keyboard. Well designed applications provide shortcuts as a way to “power use” them. The GUI serves a new user, but seasoned users can use shortcuts to speed up the way they use the application.

Spend some time learning the shortcuts of applications you use regularly. It is not easy, but it pays back splendidly. You will look like a rock star riffing on his guitar, if you master keyboard shortcuts.

Screen Real Estate

If you are working on a physical desk, do you keep only what you are using at the moment (say a book)? Or do you keep other items on it so that you can switch between using them without much effort?

Your computer display also works the same way as a physical desk (does the term desktop sound familiar?). If your screen resolution allows multiple windows to be viewed at the same time without sacrificing functionality, use it. Don’t maximize windows and keep switching between them.

A good example is your browser. Most websites today are designed for 1024×768 resolution. If you display has a resolution larger than that, why maximize the browser and eat up valuable screen real estate, when you can keep your browser at 1024×768 and use the remaining space for your IM or email client? That way you can keep an eye on who is online and the emails you get while browsing. No need to waste time with switching between windows.

Also, if you are a heavy mouse user, not maximizing windows offers huge time savings. Other windows can be positioned so that some part is always visible and to switch to another window, you just need to click on the visible portion of that window instead of searching for it in the taskbar.

Always Customize

Most applications can be configured to do things faster, but present a simple but inefficient interface by default so as to not scare new users. Once you get comfortable using an application, see if you can do things faster by customizing it.

For example, in some corporate environments ,Windows XP is configured to use Windows 98 style Start menu instead of the new one which shows the most frequently used applications. You can also add application shortcuts to the new Start menu. Using the old one to select a frequently used application will take at least 3 clicks, whereas in the new Start menu it can require only 2 clicks.

If you are going to frequently launch an application, put it somewhere easily accessible instead of hunting through menus to open it. Define a keyboard shortcut if your OS allows it.

Written by anonir

January 8, 2010 at 23:34

Posted in General Tech

Tagged with ,

Extracting a substring from a starting point using awk

leave a comment »

If you have a string like this (this is how versions look in Clearcase):

/root_path/stream/version_name/78

and want to extract the string 78 (i.e, the version no.), you can do it this way:

echo "/root_path/stream/version_name/78" | awk '{where = match($0,"\/[^\/]*$"); print substr($0,where+1)}'

We get the position of the last occurrence of “/” and use substr to extract the string after that position till end of string.

Written by anonir

December 29, 2009 at 19:07

Posted in Linux

Tagged with

Bash script to compile and run a C program in one step

with 3 comments

Here is a simple script to compile and run a C program:

#!/bin/bash
# Script to compile and execute a c program in one step.

# Get file name without the .c extension
file_name=$(echo $1|sed 's/\(.*\)\.c/\1/')

# Compile the program with -o option to specify the name of the binary
gcc -o $file_name.out $1

# If there were no compilation errors, run the program
if [[ $? -eq 0 ]]; then
        ./$file_name.out
fi

The same could be done for C++ programs as well. Just replace the .c in the sed expression with .cpp and replace gcc with g++

Written by anonir

October 26, 2009 at 18:21

Posted in bash, Linux