How to pack Oracle database’s binaries in a RPM file
This article describes how to create a RPM file with oracle’s binaries in it, in order to make easier the process of database installation.
Prerequisites
Install the packages rpmdevtools and rpm-build, these packages contains command line like rpmdev-setuptree and rpmbuild that will help to create the RPM structure
#yum install rpmdevtools rpm-build
The oracle database software must be installed on the machine
Generate the RPM structure
Inside the oracle’s home directory execute the command:
#rpmdev-setuptree
This command will create the following directory structure:
|-- rpmbuild |-- BUILD |-- RPMS |-- SOURCES |-- SPECS `-- SRPMS
RPM Contents SOURCES
The directory SOURCES must have a tar file with all files desired to be added in the RPM file
#tar -cvf oracle11.tar /home/oracle/.bash_profile /u01/app/oracle/product/11.2.0/rhdb/*
Configuration SPEC file
The directory SPEC is where the spec file with the instructions to create our RPM must be placed
Create a file called oracle11G.spec with the content bellow:
Name: oracle
Version: 11
Release: 2%{?dist}
Summary: Oracle 11G R2
Group: redhat
License: GNU
URL: http://www.redhat.com
Source0: oracle11.tar
#BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
Requires: binutils >= 2, glibc >= 2, nss-softokn-freebl >= 3, compat-libstdc++ >= 33, glibc-common >= 2, glibc-devel >= 2, glibc-headers >= 2, elfutils-libelf, elfutils-libelf-devel, gcc >= 4, gcc-c++ >= 4, ksh, libaio, libaio-devel, libgcc >= 4, libstdc++ >= 4, libstdc++-devel >= 4, make >= 3.81, numactl-devel >= 2, sysstat >= 9 libfreebl3.so()(32bit), ld-linux.so.2()(32bit), libc.so()(32bit), libaio.so.1()(32bit), libaio.so()(32bit), libgcc_s.so.1()(32bit), libstdc++.so.6()(32bit), libstdc++.so.5()(32bit)
%description
Oracle 11G R2
%build
mkdir -p $RPM_BUILD_ROOT/home/oracle
cp /home/oracle/.bash_profile $RPM_BUILD_ROOT/home/oracle
mkdir -p $RPM_BUILD_ROOT/u01/app/oracle/product/11.2.0/rhdb/
cp -ra /u01/app/oracle/product/11.2.0/rhdb/* $RPM_BUILD_ROOT/u01/app/oracle/product/11.2.0/rhdb/
%pre
groupadd oinstall
groupadd dba
useradd -g oinstall -G dba oracle
echo redhat|passwd --stdin oracle
%files
/u01/*
/home/*
%post
chown -R oracle:oinstall /u01
chmod -R 775 /u01
%changelog
* Fri Sep 23 2011 Leandro Abite 1.0
- First version
Generating RPM file
The generation of the RPM file is made by the command rpmbuild passing the spec file as parameter
#rpmbuild -ba oracle11G.spec
if every thing is ok the rpm file should be created in the directory SRPMS
How to make the Apache redirect from http to https and vice versa automatically
There are some ways to do that, in this examples let’s use the module mod_rewrite.
Make sure that the module mod_rewrite is being loaded by your apache
We need tell apache the condiction to execute the redirect, edit the file $APACHE_HOME/conf/httpd.conf and add the following lines:
#Turn on the rewrite
RewriteEngine on
#Condiction and rule for redirect
RewriteCond %{REQUEST_URI} ^/(<YOUR URL>)
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
Sample:
Let’s suppose you need to redirect the URL http://youserver/login.php to https://youserver/login.php, our configuration would be the follwing:
RewriteCond %{REQUEST_URI} ^/(login\.php)
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
If there are a need to set up more than one URL, just copy and paste the 2 lines above and replace the name of the page.
Once the user request the url http://youserver/login.php he will remain in https even in pages that are not configured in httpd.conf, That happened because that configuration tell apache to get in https when the page login.php is requested, so we need tell Apache to get in http when some other page is requested, this is configured in the file $APACHE_HOME/conf.d/ssl.conf, do the same configuration done in file http.conf
Sample:
Let’s suppose that after the user pass througt the login he will get the home.php page, so add the following lines in the file $APACHE_HOME/conf.d/ssl.conf:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/(home\.php)
RewriteRule ^/(.*) http://%{SERVER_NAME}/$1 [R,L]
Don’t forget to restart the apache service
It’s done,
!!!
Converting Entity Objects to SelectItem Objects using reflection
This method is very useful for development JSP using JSF. This method converts a list of Entity Objects or any class that contains the items for a JSF ListBox to SelectItem Object. The class must have at least two methods:
- The id method that return de id of the Item
- The description method that return the description of the Item
public List<SelectItem> entityToSelectItem(List _items, String _idMethod, String _descMethod)throws Exception {
List<SelectItem> items = new ArrayList<SelectItem>();
Method idMethod = null;
Method descMethod = null;
for (int i = 0; i < _items.size(); i++) {
Object item = _items.get(i);
// On the first run, initialize reflection methods for object
if (idMethod == null) {
Class obj = item.getClass();
idMethod = obj.getMethod(_idMethod, new Class[]{});
descMethod = obj.getMethod(_descMethod, new Class[]{});
}
// invoke Methods
String id = (String) idMethod.invoke(item, new Object[]{});
String name = (String) descMethod.invoke(item, new Object[]{});
SelectItem selectItem = new SelectItem();
selectItem.setLabel(name);
selectItem.setValue(id.toString());
items.add(selectItem);
}
return items;
}
Compartmental Syndrome
My legs after operation
I had my legs operated due a compartmental syndrome!!! you should be asking yourself … what fuck does compartmental syndrome mean????
Compartment syndrome is very common in runners, footballers, usually in high level athletes like me!! LOL… our muscles are covered by a layer called faschia, compartment syndrome occurs when the muscle tries to swell up bigger than the faschia, hence a pressure is put on the muscle, therefore a terrible pain will be felt, in my case it occurred on anterior tibial muscle, this is the most common place to occurs it.
My surgery was yesterday, I was operated by Dr. Marcelo Padro from HCor in Sao Paulo – Brazil, the surgery took about 40 minutes, to release the pressure he just cut open the faschia, and poof, I got better!!! I’ll be ready to back to phisical activities within a month, I am looking forward to play a football match without felling any pain.
Running os commands from Oracle
I was looking for a way to execute os commands from Oracle, all solutions I found were very complex, had to create a C program or had to use the package dbms_scheduler to execute a job, besides to be complex these solutions, have to develop diferents codes for diferents operational systems… so I solved this problem using java without to use the package dbms_scheduler , the Java class executes the command in runtime, this solution works in Oracle 8,9,10 and 11 with all operation systems supported by Oracle. Basicly you need to follow 3 steps:
- Grant some java privileges to your Oracle database user.
- Compile java class on Oracle database.
- Create a Oracle function with the call to java class.
STEP 1 – GRANTS TO YOUR DATABASE USER
Logged as SYS execute the commands bellow:
SQL> EXEC dbms_java.grant_permission('<USERNAME>', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', ''); SQL> EXEC dbms_java.grant_permission('<USERNAME>', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', ''); SQL> EXEC dbms_java.grant_permission('<USERNAME>', 'SYS:java.io.FilePermission', '/bin/sh', 'execute'); Example: SQL> EXEC dbms_java.grant_permission('labite', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', ''); SQL> EXEC dbms_java.grant_permission('labite', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', ''); SQL> EXEC dbms_java.grant_permission('labite', 'SYS:java.io.FilePermission', '/bin/sh', 'execute');
STEP 2 – CREATE AND COMPILE JAVA CLASS
Logged with your database user execute the command bellow:
CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "OSCommand" AS
/*
Created by: Leandro Abite
email: leandroabite@yahoo.com.br
*/
import java.io.*;
public class OSCommand {
public static String executeCommand(String command) {
StringBuffer sb = new StringBuffer();
try {
String[] finalCommand;
if (System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) {
finalCommand = new String[4];
finalCommand[0] = "C:\\winnt\\system32\\cmd.exe";
finalCommand[1] = "/y";
finalCommand[2] = "/c";
finalCommand[3] = command;
} else { // Linux or Unix System
finalCommand = new String[3];
finalCommand[0] = "/bin/sh";
finalCommand[1] = "-c";
finalCommand[2] = command;
}
// Execute the command...
final Process pr = Runtime.getRuntime().exec(finalCommand);
// Capture output from STDOUT
BufferedReader br_in = null;
try {
br_in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String buff = null;
while ((buff = br_in.readLine()) != null) {
sb.append(buff);
sb.append("\n");
try {Thread.sleep(100); } catch(Exception e) {}
}
br_in.close();
} catch (IOException ioe) {
System.out.println("Error printing process output.");
ioe.printStackTrace();
} finally {
try {
br_in.close();
} catch (Exception ex) {}
}
// Capture output from STDERR
BufferedReader br_err = null;
try {
br_err = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
String buff = null;
while ((buff = br_err.readLine()) != null) {
sb.append("stderr:");
sb.append(buff);
sb.append("\n");
try {Thread.sleep(100); } catch(Exception e) {}
}
br_err.close();
} catch (IOException ioe) {
System.out.println("Error printing execution errors.");
ioe.printStackTrace();
} finally {
try {
br_err.close();
} catch (Exception ex) {}
}
}
catch (Exception ex) {
System.out.println(ex.getLocalizedMessage());
}
return sb.toString();
}
};
/
STEP 3 – CREATE FUNCTION TO CALL JAVA
CREATE OR REPLACE FUNCTION oscomm (p_command IN VARCHAR2) RETURN VARCHAR2 AS LANGUAGE JAVA NAME 'OSCommand.executeCommand (java.lang.String) return java.lang.String'; /
EXECUTION TEST
To execute the os command you have to pass the complete path of the command:
it is wrong!!!!! SQL> select oscomm('ls -ltr') from dual; OSCOMM('LS-LTR') -------------------------------------------------------------------------------- stderr:/bin/sh: ls: No such file or directory
it is right!!!!! SQL> select oscomm('/bin/ls -ltr') from dual; OSCOMM('/BIN/LS-LTR') -------------------------------------------------------------------------------- total 44 -rw-r--r-- 1 oracle oinstall 8385 Sep 11 1998 init.ora -rw-r--r-- 1 oracle oinstall 12920 May 3 2001 initdw.ora -rw-r----- 1 oracle oinstall 24 Nov 19 17:31 lkDB01 -rw-rw---- 1 oracle oinstall 1544 Nov 19 17:31 hc_db01.dat -rw-r----- 1 oracle oinstall 1536 Feb 10 17:08 orapwdb01 -rw-r----- 1 oracle oinstall 2560 Feb 18 12:42 spfiledb01.ora
