Thursday, August 18, 2011

Use wildcard in the command find

To use a wildcard * in the find command needs a little more care.

Without quote or backslash \, such as
find . foo*bar -print
the shell will expand * before passing it into find command.  This results is a different, and most likely a narrower, search.

To avoid that, use
find . 'foo*bar' -print
or
find . foo\*bar -print

Tuesday, August 16, 2011

Add one more yum repository

Read yum.conf first.  Usually the path is /etc/yum.conf.
Understand where the cache and repository configuration file directory

The following examples use default locations

## add epel to the repo list
## see what is there before change
ls /var/cache/yum/*/*
cd yum.repos.d/
## copy contents from another configured host
sudo vi epel.repo
sudo yum clean all
## make sure it is empty
ls /var/cache/yum/*/*
sudo yum makecache
## see if the new repo epel is added
ls /var/cache/yum/*/*
## add GPG key for the new repo, also do copy-paste
sudo vi /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL

If you are not sure about the name of RPM-GPG key, run rpm to install the package.  Towards the end, rpm will complain about missing the GPG key and prompt the file name for you.

Find out it is a 32 or 64-bit Linux

Use the command
uname -m
If it shows x86_64, it is a 64-bit host.
If it shows i386 (or sometimes i686), it is a 32-bit machine

Plus, run the command
file /bin/ls
For 64-bit kernel, it should show
/bin/ls: ELF 64-bit LSB executable ....

Find installed packages on Linux hosts

To find installed packages on a Redhat/CentOS Linux, use
rpm -qa | less

Once the package name is found, use this command to find more details
rpm -qil {package-name}

To find installed packages on a Debian (also Ubuntu) Linux, use
dpkg --list

Once the package name is found, use this command to find more details
dpkg -p {package-name}

Tuesday, August 9, 2011

Find and delete into directories recursively

How to find a set of files or directories that are named the same?  For example, to delete all the '.svn' directories in the current working directory.

One easy way is
rm -rvf `find . -type d -name .svn`

The option [-v] prints out the files/directories found.  and rm -rf is the typical force deletion of a directory.

Another way to do it is
find . -name ".svn" -exec rm -rf {} \;

But this command prints out warning messages that sometimes confuse users.
find: ./.svn: No such file or directory
find: ./images/.svn: No such file or directory

The warning message means it found a .svn directory in the current directory and deleted as instructed ( -exec rm -rf ).  When the command find wanted to descend into .svn directory, it could not.

The trailing {} \; is required.  Pay attention to its format: there is a space between } and \.

Programmically create a Mule 3.x Inbound point to a Mule service

I use JMS inbound endpoint as an example.  Different types of inbound endpoints differ slightly.

1. Create an inbound point configurer of the target inbound type

public class JmsInboundConfigurer implements MuleContextAware
{
    ServiceCompositeMessageSource msgSource;
   
    public void setMuleContext(MuleContext context) {...}
    public MuleContext getMuleContext() {...}
    public void setService(Service svc) {...}
    public Service getService() {...}
    public void setConnector(Connector conner) {...}
    public Connector getConnector() {...}
}

In the mule-config.xml, add

<spring:bean id="my.configurer" class="com.acme.JmsInboundConfigurer" init-method="init">
    <spring:property name="service">
        <spring:ref bean="my.service"/>
    </spring:property>
    <spring:property name="connector">
        <spring:ref bean="activemq.connector"/>
    </spring:property> 
</spring:bean>

2. Statically configure an inbound point and read it back to match the configuration

<jms:activemq-connector name="activemq.connector" 
 brokerURL="tcp://localhost:61616"/>
<jms:endpoint name="jms.endpoint" queue="..."
 connector-ref="activemq.connector" exchange-pattern="request-response"/>

JmsInboundConfigurer.init() would make a good place to output all the information.

this.msgSource = 
(ServiceCompositeMessageSource)getService().getMessageSource();
logger.info(msgSource.toString());

Use msgSource.getEndpoint("jms.endpoint") or msgSource.getEndpoints() to read back end points to compare with the static configuration

3. Comment out the static configure and create it programmatically

The following code fragment creates and add a JMS inbound point to the service assigned

EndpointURIEndpointBuilder builder = new EndpointURIEndpointBuilder(uri, this.muleContext);
builder.setName("jms.endpoint");
builder.setConnector(this.connector);
builder.setExchangePattern("request-response");

// builder.setProperty("", xyz);  // if any
if (transaction needed) {
    MuleTransactionConfig txConf = new MuleTransactionConfig();
    txConf.setAction(ACTION_BEGIN_OR_JOIN);
    txConf.setMuleContext(muleContext);
    txConf.setTimeout(30000);
    JmsTransactionFactory factory = new JmsTransactionFactory();
    factory.setName("a-good-name");
    txConf.setFactory(factory);
    builder.setTransactionConfig(txConf);
}
builder.setInitialState(AbstractService.INITIAL_STATE_STARTED);
builder.setResponseTimeout(10000);
builder.setDeleteUnacceptedMessages(false);
builder.setDisableTransportTransformer(false);
builder.setEncoding("UTF-8");
InboundEndpoint inept = builder.buildInboundEndpoint();
muleContext.getRegistry().registerEndpoint(inept);
msgSource.addSource(inept);

The inbound endpoint should work at this point.

Wednesday, August 3, 2011

Find socket/port status on Linux

When debugging or monitoring a client-server application or any connected application, it is necessary to find out what is going on at socket level.

To start, use
netstat -an

To start with TCP connections, use
netstat -ant

Although the option -p should show process information (PID), it usually gives a "-" for that field. Remember to use ifconfig to find interfaces and IP addresses.

To begin this blog

I am a software engineer, and I code.

I use the Internet as a reference, language features, open-source software, best practices and quick suggestions on day-to-day issues. There are a lot of good articles, but they are easily buried under by other search engine optimized sites. I decided to log what I found and my thoughts on the fine points. This will definitely help myself, and hopefully will help other people.