Life of a Geek Admin

The Daily adventures of a true geek administrator

Life of a Geek Admin - The Daily adventures of a true geek administrator

How To Securely Delete Files on Windows

When you delete a file on your Windows system is it really deleted? The answer is no, except if the file is on a SSD (Solid State Drive) which the file is deleted immediately. When you delete a file, it isn’t removed from the hard drive immediately. Instead, the computer marks the area as usable and it can be overwritten in the future. This means that your personal files may remain accessible, even after deleting them. For the files to be removed completely you will need to use a tool to securely delete them. With tools like Recuva  , Undelete Plus, PhotoRec (command line), PC File Inspector and others the files can be restored.

Complete OS / File Deletion

So say you want to completely erase the OS and files on your system as you are donating it or disposing of it. You can do this a few ways. One is using DBAN (Darik’s Boot and Nuke) which is a bootable CD that will overwrite the drive with nothing multiple times so there is nothing recoverable on the drive.

According to the site “DBAN is a self-contained boot disk that automatically deletes the contents of any hard disk that it can detect. This method can help prevent identity theft before recycling a computer. It is also a solution commonly used to remove viruses and spyware from Microsoft Windows installations. DBAN prevents all known techniques of hard disk forensic analysis. It does not provide users with a proof of erasure, such as an audit-ready erasure report.”  It is very effective and time consuming.

DBAN_Start

Once the drive has been completely wiped you can reinstall the Windows OS using the recovery disc provided by the manufacturer.

Secure File Deletion

Say we just want to make sure the files we deleted are truly gone and no chance of coming back. One such tool is CCleaner from Piriform. Download and install CCleaner and click on Tools link in the left Windows pane.  This will present a few new links in the main screen area. Click on Drive Wiper, select the drive to clean and click Wipe.

ccleaner

At this point your files have been securely deleted from the drive with no chance of recovery.

Another tool is Eraser from Heidi Computers. Eraser is also Freeware and runs on Windows. Download and install Eraser from here. Open the utility after installation and make the selection and let it run.

6388354-620-456

These are just a few of the applications available for securely deleting files from your Windows system and should be something to get you started. Look for future posts to cover some basic data recovery techniques!

Useful RPM and YUM Commands

RPM and YUM commands are used daily by RHEL/CentOS/Fedora Administrators and sometimes having a few more tricks up you sleeve for getting information from the command line are always handy to have.  Listed in this post are 14 useful commands for RPM and YUM.

1. Getting rpm to display architecture

This one is a pretty simple tip, and very useful especially for people using x86_64 systems. Just one line in ~/.rpmmacros will save all sorts of trouble later.

$ echo "%_query_all_fmt %%{name}-%%{version}-%%{release}.%%{arch}" >> ~/.rpmmacros

2. Query packages not from Redhat

Want to query all those packages installed from 3rd party repositories, not Redhat?

$ rpm -qa --qf '%{NAME} %{VENDOR}\n' | grep -v -i redhat

3. Reset File Permissions

Have you managed to completely mess up file permissions for a given package? Not a problem, because RPM has you covered.

$ rpm --setperms <packagename>

4. View the Changelog

Because Redhat and the upstream vendor have backported security patches, the version numbers can often be misleading when you look for CVE fixes. Checking the changelog of a package is a good way to see if the fix has been implemented. Once again, rpm comes to the rescue.

$ rpm -q --changelog <packagename>

5. Where’s the Documentation?

To quickly list documentation relating to a package, you can use the following two options:

$ rpm -qd <packagename>

This will show you the documentation contained in that rpm, or if you only have a filename you can do:

$ rpm -qdf /path/to/file

and rpm will show you the documentation in the package that owns the file.

6. Package Origin

Occasionally it’s nice to know where you got certain packages, or how many packages you have on your system from a particular repository or vendor. There are a couple of search options that you can use which are not in the rpm man pages to help you out here. While they’re not 100% perfect, they certainly help out. Most package repositories tag their packages with an identifier in the Release string. For example rpmforge uses rf as their identifier. You can use this to see what you have of theirs installed with

$ rpm -qa release="*rf*"

or if you want to see just how many packages you have installed built by Fred you could use

$ rpm -qa packager="Fred*"

This trick works for most categories visible in rpm -qi <packagename>.

Another approach is to use the keychecker package available in the EPEL repository, which lists rpm packages based on the GPG key they were signed with.

7. Extract just one File

If you need to extract just one file from an rpm without reinstalling the whole package, you can do this with rpm2cpio. For example, to extract just the config file from the logrotate rpm you would use the following statement:

$ rpm2cpio logrotate-1.0-1.i386.rpm |cpio -ivd etc/logrotate.conf

8. Query Package Install Order and Dates

Useful after an upgrade to find old packages that were not upgraded.

$ rpm -qa --last >~/RPMS_by_Install_Date

Review the end of the output file in “less” to find all RPMS older than the install date. Can also grep for specific packages and see when they were installed.

9. Query Available Packages from a Repo

Find all packages available from a specific repository, e.g. RPMfusion. This does not show the already installed packages from this repository.

$ yum --disablerepo "*" --enablerepo "rpmfusion" list available

10. Search yum repositories for a string

Find packages containing a string in package name or description.

$ yum search buildrpmtree | less

11. Using yum with a proxy server

To enable yum operations to use a proxy server you should first add the following parameter to /etc/yum.conf

$  proxy=http://yourproxy:8080/

where yourproxy is the name of the proxy server you want to access and 8080 is the proxy port. If the server requires authentication you can specify the login credentials like:

$ proxy=http://username:password@yourproxy:8080/

The rpm package manager makes use of the proxy environment variable. This can be set system wide in /etc/profile or user specific in ~/.bash_profile::

$ export http_proxy=http://yourproxy:8080/ export ftp_proxy=http://yourproxy:8080/

To use wget through a proxy server add the following lines to /etc/wgetrc

$ http_proxy = http://yourproxy:8080/  ftp_proxy = http://yourproxy:8080/

In both cases, login information can be set like in the example above.

12. Use yum to install a local package, automatically checking/satisfying dependencies

$ yum --nogpgcheck localinstall packagename.arch.rpm

13. Display priority scores for all repositories

You can list all repositories set up on your system by a yum repolist all. However, this does not show priority scores. Here’s a one liner for that. If no number is defined, the default is the lowest priority (99).

$ sed -n -e "/^\[/h; /priority *=/{ G; s/\n/ /; s/ity=/ity = /; p }" /etc/yum.repos.d/*.repo | sort -k3n

14. Show all installed GPG keys

Shows all GPG keys along with the corresponding repo information.

 rpm -q gpg-pubkey --qf '%{name}-%{version}-%{release} --> %{summary}\n'

 

Hope this has added a few more ticks up your sleeve as it has mine!

How install Apache 2.4 PHP 5.4.16 and MariaDB 5.5.31 on Windows 7

As a followup to my post on How install Apache 2.4 PHP 5.4 and MySQL 5.5.21 on Windows 7, I decided to install the latest Apache 2.4 / PHP 5.4.16 and MariaDB 5.5 with PhPMyAdmin. The difference is using MariaDB and PHP 5.4.16.

Apache 2.4 Install

First download Apache 2.4.4 from http://www.apachelounge.com/download/ (httpd-2.4.4-win32-ssl_0.9.8.zip) Apache 2.4.4-win32-ssl_0.9.8.zip.

Extract the zip and copy it to the root of C:\. This will be C:\Apache24 when it is all done.

PHP 5.4.16

Download PHP 5.4.16 VC9 x86 Thread Safe from http://windows.php.net/download/ . Extract and rename folder to php and move to C:\.

PHP 5.4.10 and newer configuration

Edit Apache’s config file, c:\Apache24\conf\httpd.conf and add the following lines to the bottom of the file.

LoadModule php5_module "c:/php/php5apache2_4.dll"
AddHandler application/x-httpd-php .php
# configure the path to php.ini
PHPIniDir "C:/php"

While we are at it we can add index.php to Apache’s list just incase we want to have a starting page as php.

Find Directory index and add index.php

DirectoryIndex index.html index.php

Next we need to input a value  for ServerName variable. You will have to un-comment it. Save the changes to the config file. Next move to the Register Apache Service step.

Register Apache Service

Now let’s register Apache as a service. Open a command prompt and type.

c:\apache24\bin\httpd -k install

Note: If you receive and error that MSVRC100.dll is missing you will need to download and install Visual C++ 2010 x86 Runtime. You can retrieve that from http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=5555.

If do not want Apache starting automatically at start-up/reboot:

GUI Way

  • START | RUN
  • Type in services.msc, hit Enter or click OK
  • Locate Apache2 service and double-click (or right-click for Properties)
  • Find the caption Startup type: (in the middle of the dialog box), use the pull-down and select Manual
  • Click OK

Command line

C:\> sc config Apache2.4 start= demand

Add

c:\Apache24; c:\Apache24\bin

to PATH in Environment variables. PATH ENVIRONMENT (System Properties | Advanced | Environment Variables | System variables | Path).
Example:
;c:\php;c:\apache24;c:\apache24\bin;

Now lets check Apache settings by issuing the command, c:\Apache24\bin\httpd -S

PHP Edits

Now we have to do a few edits to the php.ini file to tell it to load support for mysql and the location for the extensions. Since there is not a already set php.ini file we need to rename one of the two examples to php.ini.

Rename c:\php\php.ini-development to php.ini

Now let’s edit php.ini
Uncomment extension directory.

; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
extension_dir = "ext"

Uncomment mysql modules
extension=php_mysql.dll
extension=php_mysqli.dll
extension=php_mbstring.dll

Save the changes and open a command prompt. Check to make sure it shows loaded modules.

C:\> php -m

So now we have Apache running and configured to use php. Lets create a file called info.php, save it and see if Apache parses the info correctly to display the results.

Open Notepad or your favorite Windows editor and type and save the following.

 <?php
phpinfo();
?>

Open your browser and type, localhost/info.php for the location and you should receive alot of information about PHP.

MariaDB
Download and install mariadb-5.5.31-winx64.msi. Change installation directory to C:\MariaDB 5.5 instead of Program files as there could be permissions issues. Once the installation is completed you can let the configuration wizard run and setup the database server. The defaults will work just fine, but remember what you set the password to for root.

PHPMyAdmin
PHPMyAdmin is a very nice tool to use for administering your MySQL installation.
Download and install phpmyadmin-3.5.8.1-english.zip.
Extract the file and move to c:\apache24\htdocs. Rename directory to phpmyadmin.
Create a config directory under phpmyadmin. Open a browser and type localhost/phpmyadmin/setup/index.php to complete the installation.

At this point you should have a working Apache / PHP / MariaDB installation running and ready for you to start developing !!!

How to install Apache 2.4 PostgreSQL 9.2.4 and PHP 5.4 on Windows 7

In following along with previous posts and installing Apache stack on Windows systems I thought I might cover installing Apache 2.4, PostgreSQL 9 and PHP 5.4 on a Windows system. In this case a Windows 7 Professional 64 bit installation.

Apache 2.4 Install

First download Apache 2.4.4 from http://www.apachelounge.com/download/ (httpd-2.4.4-win32-ssl_0.9.8.zip) Apache 2.4.4-win32-ssl_0.9.8.zip.

Extract the zip and copy it to the root of C:\. This will be C:\Apache24 when it is all done.

PHP 5.4.16

Download PHP 5.4.16 VC9 x86 Thread Safe from http://windows.php.net/download/ . Extract and rename folder to php and move to C:\.

PHP 5.4.10 and newer configuration

Edit Apache’s config file, c:\Apache24\conf\httpd.conf and add the following lines to the bottom of the file.

LoadModule php5_module "c:/php/php5apache2_4.dll"
AddHandler application/x-httpd-php .php
# configure the path to php.ini
PHPIniDir "C:/php"

While we are at it we can add index.php to Apache’s list just incase we want to have a starting page as php.

Find Directory index and add index.php

DirectoryIndex index.html index.php

Next we need to input a value  for ServerName variable. You will have to un-comment it. Save the changes to the config file. Next move to the Register Apache Service step.

Register Apache Service

Now let’s register Apache as a service. Open a command prompt and type.

c:\apache24\bin\httpd.exe -k install

Note: If you receive and error that MSVRC100.dll is missing you will need to download and install Visual C++ 2010 x86 Runtime. You can retrieve that from http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=5555.

If do not want Apache starting automatically at start-up/reboot:

GUI Way

  • START | RUN
  • Type in services.msc, hit Enter or click OK
  • Locate Apache2 service and double-click (or right-click for Properties)
  • Find the caption Startup type: (in the middle of the dialog box), use the pull-down and select Manual
  • Click OK

Command line

C:\> sc config Apache2.4 start= demand

Add

c:\Apache24; c:\Apache24\bin

to PATH in Environment variables. PATH ENVIRONMENT (System Properties | Advanced | Environment Variables | System variables | Path).
Example:
;c:\php;c:\apache24;c:\apache24\bin;

Now lets check Apache settings by issuing the command, c:\Apache24\bin\httpd -S

PHP Edits

Now we have to do a few edits to the php.ini file to tell it to load support for PostgreSQL and the location for the extensions. Since there is not a already set php.ini file we need to rename one of the two examples to php.ini.

Rename c:\php\php.ini-development to php.ini

Now let’s edit php.ini
Uncomment extension directory, if it doesn’t exist you will need to create it.

; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
extension_dir = "ext"

Uncomment PostgreSQL modules
extension=php_pgsql.dll

Save the changes and open a command prompt. Check to make sure it shows loaded modules.

C:\> php -m

So now we have Apache running and configured to use php. Lets create a file called info.php, save it and see if Apache parses the info correctly to display the results.

Open Notepad or your favorite Windows editor and type and save the following.

 <?php
phpinfo();
?>

Open your browser and type, localhost/info.php for the location and you should receive alot of information about PHP.

PostgreSQL

Download PostgreSQL 9.2.4 x86-64from EnterpriseDB site http://www.enterprisedb.com/products-services-training/pgdownload#windows. Select x86-32 if you are running a 32 bit version of Windows.

Start the installation of PostgreSQL. The installation will prompt for a location. Change the location to C:\PostgreSQL\9.2 and click next.

postgres1

The next prompt will be for the data directory. It will inherit what you set before which is good, click next.

postgres2

Set the root password for the database. Make sure to take note of the password. Click Next.

postgres3

Click next to accept the default port of 5432

postgres4

Next you will be prompted for the default locale. Click next to accept it.

postgres5

Click next to start the installation.

postgres6

Once the installation is completed you will be asked if you want to allow Stack Builder to download and install tools, this is your choice. Click Finish when completed.

postgres7

At this point PostgreSQL will start and you can verify by opening pgAdmin II and connect to it.

postgres8

Now you have a running system with PostgreSQL as your database, Apache 2.4 and PHP 5.4 on a Windows 7 system.

 

How To Install Bluefish 2.2.4 on Fedora 18

Bluefish is a great Web Development IDE for Linux / Windows and Mac OSX. Having the latest and greatest on Fedora 18 is always a plus and sadly in the repositories it is at 2.2.3 and not 2.2.4, but great news we can take care of that in short order.

If you have installed Fedora’s supplied Bluefish you will need to uninstall it.

$ sudo rpm -e bluefish bluefish-shared-data

Now let’s download the lateste and install it. First download 2.2.4 from http://www.bennewitz.com/bluefish/stable/binaries/Fedora18/.

and now the really difficult part, open a terminal and type.

$ sudo rpm -ivh bluefish-2.2.4-3.fc18.x86_64.rpm

and that’s all there is to it. You can start it using the link in the menu or from a prompt.

bluefish1

Using the Raspberry Pi as a NAS

Here we have another great use for the Raspberry Pi as a NAS server for your LAN. In this post we’ll be using a Thermaltake BlacX USB SATA attached to the Pi with a 1 TB drive with ntfs shared to the Windows and MAC systems for access.
Install ntfs support

$ sudo apt-get install ntfs-3g

Create the mount directory and mount it

$ sudo mkdir /media/ext

Mount as ntfs as user id pi

$sudo mount -t auto /dev/sda1 /media/ext

Create a share directory

$ sudo mkdir /media/ext/share

Install Samba support

 $ sudo apt-get install samba samba-common-bin

Edit Samba config and create the share drive

$ sudo nano /etc/samba/smb.conf

Remove the # symbol from the security = user line (by highlighting it with the cursor and pressing delete) to enable username/password verification for the Samba shares.

Next, we’re going to add an entirely new section to the configuration file. Scroll all the way down to the very bottom of the file and enter the following text:

[Backup]
 comment = Backup Folder
 path = /media/ext/share
 valid users = @users
 force group = users
 browsable = yes
 create mask = 0660
 directory mask = 0771
 read only = no

Press CTRL+X to exit, press Y when asked if you want to keep changes and overwrite the existing configuration file. When back at the command prompt enter the following command to restart the Samba daemons:

$ sudo /etc/init.d/samba restart

At this point we need to add in a user that can access the Pi’s samba shares. We’re going to make an account with the username backups and the password backups4ever. You can make your username and password whatever you wish. To do so type the following commands:

$ sudo useradd backups -m -G users
$ sudo passwd backups

You’ll be prompted to type in the password twice to confirm. After confirming the password, it’s time to add “backups” as a legitimate Samba user. Enter the following command:

$ sudo smbpasswd -a backups

Edit fstab and add the entry for the mount.

$ sudo nano /etc/fstab

This will open up the file systems table in nano so we can add a few quick entries. Within the nano editor add the following lines:

/dev/sda1 /media/ext auto noatime 0 0

This will install the auto usb mounting system.

$ sudo apt-get install autofs

However we need to set up a config file to allow the automounting of the usb disk.

 $ sudo vi /etc/auto.master

At the end of the file is the following
+auto.master
You need to add the following below the +auto.master entry

 +auto.master
 /media/ /etc/auto.ext-usb --timeout=10,defaults,user,exec,uid=1000

That’s all you need and can now access the share from any system in your LAN.

How to Install Tiny Tiny RSS on Fedora 18

If you are an avid reader of RSS feeds then you are aware of Google Reader and Google’s decision to remove the service, leaving users scrambling for a replacement. One such solution is a standalone system so you do not have to rely on a service that may go away. With Linux there are many open sourced options available. One such option is Tiny Tiny RSS which runs using the standard LAMP stack on your distribution.

Install some dependencies.

 $ sudo yum install php-theseer-fDOMDocument php-mbstring php-mysql msql-server httpd php perl-DBD-MySQL

UntarTiny Tiny RSS into /var/www/html

$ tar zxfv Tiny-Tiny-RSS-1.7.9.tar.gz
 $ sudo mv Tiny-Tiny-RSS-1.7.9 /var/www/html/tt-rss
 $ cd /var/www/html
 $ sudo chown -R root:root tt-rss/
 $ cd tt-rss/
 $ sudo chmod -R 777 cache/images
 $ sudo chmod -R 777 cache/upload
 $ sudo chmod -R 777 cache/export
 $ sudo chmod -R 777 cache/js
 $ sudo chmod -R 777 feed-icons
 $ sudo chmod -R 777 lock

Login to MySQL and create user and database fo the app to use.

$ mysql -u root -p
 mysql> CREATE DATABASE `ttrss` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
 mysql> CREATE USER 'ttrss'@'localhost' IDENTIFIED BY 'ttRss1';
 mysql> CREATE USER 'ttrss'@'%' IDENTIFIED BY 'ttRss1';
 mysql> GRANT ALL ON `ttrss` . * TO 'ttrss'@'localhost';
 mysql> GRANT ALL ON `ttrss` . * TO 'ttrss'@'%';
 mysql> exit

 

Open browser and go to http://localhost/tt-rss/install

Enter in credentials for MySQL db

After finishing with the installer, open your Tiny Tiny RSS installation at http://localhost/tt-rss/ and login with default credentials (username: admin, password: password)

Now you are ready to customize Tiny Tiny RSS!

How To Use A Raspberry Pi as a Web Server

The Raspberry Pi is a wonderful little device. A powerful compact computer that is quiet and low power consumption makes it nice for many tasks. One such for me is a web server with PHP and MySQL. In this post that’s exactly what we are shooting for, a web server.

First let’s make sure we are up to date.

 $ sudo apt-get update

Install Apache and PHP

 $ sudo apt-get install apache2 php5 libapache2-mod-php5

Now lets install MySQL to complete the LAMP server.

$ sudo apt-get install mysql-server mysql-client php5-mysql

During the installation we will be prompted for the MySQL root password.

raspweb1

The install will prompt for verification of the new password.
raspweb2
Test MySQL on the system. At the command prompt type:

$ mysql -u root -p

and follow with the show databases; command.
raspweb3
Test Apache by opening a web browser and navigating to the Raspberry Pi’s address and you should receive the It Works! Page.
raspweb4
To check the PHP installation create a file called info.php in the /var/www directory with the contents.

cd /var/www
sudo vi info.php

Paste the following code.

<?php

phpinfo();

?>

raspweb10
Open a browser and  navigating to the Raspberry Pi’s address/info.php (ex: http://192.168.1.15/info.php) and you should receive an output like below.
raspweb5
Now we will need to set rights so the pi user can upload and change files so we need to grant rights to pi user change the ownership of /var/www or the user account you want to use. Or you can create a sub-directory under /var/www and grant access to other id’s.

$ sudo chown -R pi /var/www

If any other Apache or PHP configuration edits are needed the files are located at /etc/apache2/apache2.conf and /etc/php5/apache2/php.ini.

PHPMyAdmin Installation
What easier way to administer a MySQL database than PHPMyAdmin.

$ sudo apt-get install phpmyadmin

First you will be prompted for the web server to use, select apache and slect OK.
Configure Apache to work with PhpMyAdmin
raspweb6
Next prompt will ask for configuration of dbconfig-common can be performed. Answer Yes.
raspweb7
Final prompts have to deal with it and password of the MySQL admin account to allow it to create dbconfig-common database and password to connect to MySQL with.
raspweb8

raspweb9
We need to alter the Apache configuration in order to access PhpMyAdmin. To do this, enter the following command to alter the configuration:

$ sudo nano /etc/apache2/apache2.conf

Navigate to the bottom of the file and add the following new line to the file:

Include /etc/phpmyadmin/apache.conf

Save the file and restart Apache2. To restart Apache, enter the following command:

$ sudo /etc/init.d/apache2 restart

VSFTP Installation
Now we can install VSFTPD to allow for FTP uploading of code to the pi.

$ sudo apt-get install vsftpd

The configuration file for vsftp can be found /etc/vsftpd.conf to make changes as needed.

There you have it. I working Web Server running on the Raspberry Pi!

Install Tomcat 7 and Java 1.7 on CentOS 6 RHEL 6

In this post we will cover how to install the Apache Tomcat 7 and jre 1.7 on CentOS 6 and RHEL 6. This process doesn’t use the rpm’s from the Redhat repositories, but uses the latest tar balls from Apache and Oracle. We will also be using service accounts to control Tomcat and its processes.

Download latest Tomcat from http://tomcat.apache.org/download-70.cgi. Version 7.0.40 is the curent version at the time of this post.
Download the latest Java 1.7 jdk from http://www.oracle.com/technetwork/java/javase/downloads/index.html, click on the JDK download buton. You will want jdk-7u21-linux-x64.tar.gz tarball.
Copy the downloaded tarballs to /tmp directory on your server.

Change directory to /opt or the directory of your choice on the server. I am using /opt for this post to contain Java and Tomcat.

$ cd /opt

Make the tomcat directory and change to it.

$ mkdir tomcat
$ cd tomcat

This step is optional to create individual instances by name for tomcat. Doing this allows you to run multiple instances of tomcat on a server. For this example tomcat-inst1 is what we will be using.

$ mkdir tomcat-inst1
$ cd tomcat-inst1

untar Tomcat in the instance you will be running.

$ tar -xvzf /tmp/apache-tomcat-7.0.40.tar.gz

Create a symlink called tomcat-current. This will allow you to untar newer versions of Tomcat and juwst update the symlink.

$ ln -sf apache-tomcat-7.0.40 tomcat-current

Create tomcat service account and set the UID to 520

$ useradd -u 520 -c “Tomcat Service Account” -d /opt/tomcat -m -s /bin/bash tomcat

 

Change ownership of the tomcat directory to the tomcat user.

$ cd /opt
$ chown -R tomcat:tomcat tomcat

Create an init.d script to start the Tomcat instance at reboot. There is not one available when using Apache supplied tarball install. Copy the below code and save as tomcat-inst1 in /etc/init.d directory, modify the instance name variable.

#!/bin/bash
#
# Startup script for the Tomcat 7.0 Servlet/JSP Container
#
# chkconfig: 345 98 02
# description: Tomcat is the servlet container that is used in the
#              official Reference Implementation for the Java Servlet
#              and JavaServer Pages technologies.

# Source function library.
. /etc/rc.d/init.d/functions

INSTANCE=tomcat-inst1
export INSTANCE
CATALINA_HOME=/app/tomcat/${INSTANCE}/tomcat-current

# Source configuration.
[ -f /etc/sysconfig/${INSTANCE} ] && . /etc/sysconfig/${INSTANCE}

RETVAL=0


start() {
    if [ -f /var/run/${INSTANCE}_restart ]
        then
        /bin/rm /var/run/${INSTANCE}_restart
    fi
    echo -n $"Starting $prog: "

    if [ ! -f /var/lock/subsys/${INSTANCE} ]; then
        
            su - tomcat -c "INST_NAME=${INSTANCE} $CATALINA_HOME/bin/startup.sh"
        

        if [ $RETVAL = 0 ]; then
            success $"$prog startup"
            touch /var/lock/subsys/${INSTANCE}
        else
            failure $"$prog startup"
        fi
    fi

    echo
    return $RETVAL
}

stop() {
    /bin/touch /var/run/${INSTANCE}_restart
    echo -n $"Stopping $prog: "

    if [ -f /var/lock/subsys/${INSTANCE} ]; then
        su - tomcat -c "$CATALINA_HOME/bin/shutdown.sh -force"

        if [ $RETVAL = 0 ]; then
            success $"$prog shutdown"
            rm -f /var/lock/subsys/${INSTANCE}
        else
            failure $"$prog shutdown"
        fi
    fi

    echo
    return $RETVAL
}

stopforce() {
    /bin/touch /var/run/${INSTANCE}_restart
    echo -n $"Forcefully Stopping $prog: "

    if [ -f /var/lock/subsys/${INSTANCE} ]; then
        su - tomcat -c "$CATALINA_HOME/bin/shutdown.sh -force"

        if [ $RETVAL = 0 ]; then
            success $"$prog shutdown"
            rm -f /var/lock/subsys/${INSTANCE}
        else
            failure $"$prog shutdown"
        fi
    fi

    echo
    return $RETVAL
}

status() {
    local base=${1##*/}
    if [ -f /var/lock/subsys/${base} ]; then
        echo $"${base} is running..."
        return 0
    else
        echo $"${base} is stopped."
        return 3
    fi
}

getpid() {
        tomcatpid=`ps auwwwx | grep -v grep |grep -i /${INSTANCE}/ | awk '{print $2}'`
        echo "The PID for ${INSTANCE} is ${tomcatpid}."
        echo
}

threaddump() {
        getpid
        kill -3 ${tomcatpid}
        echo "Thread dump has been sent to where stdout is logged."
        echo
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  stopforce)
        stopforce
        ;;
  status)
        status ${INSTANCE}
        ;;
  restart|reload)
        stopforce
        start
        ;;
  condrestart)
        if [ -f /var/lock/subsys/${INSTANCE} ] ; then
                stop
                start
        fi
        ;;
  getpid)
        getpid
        ;;
  threaddump)
        threaddump
        ;;
  *)
        echo $"Usage: $prog {start|stop|stopforce|restart|condrestart|reload|status|getpid|threaddump}"
        exit 1
esac

exit $RETVAL

Make the following changes
# Source function library.
. /etc/rc.d/init.d/functions

INSTANCE=tomcat-inst1
export INSTANCE
CATALINA_HOME=/app/tomcat/${INSTANCE}/tomcat-current

Set init script to run at startup.

$ chkconfig --levels 345 tomcat-inst1 on

Setup Java jdk 1.7

$ cd /opt
$ mkdir java
$ cd java

Untar the tarball

$ tar -xzvf /tmp/jdk-7u21-linux-x64.tar.gz

Create the symlink

$ ln -sf jdk1.7.0_21 current

Create setenv.sh in /opt/tomcat/tomcat-inst1/tomcat-current/bin/ . In this exaple there is a ENV_LEVEL which you can omit the two lines or use them. This is for maintaining different developement levels set to correct environment (DEV, INT, CERT, PROD) if you want to use them.

#Java Home for this Tomcat Instance
JAVA_HOME=/app/java/current

#Set Java Options (Memory minimum/maximum?
JAVA_OPTS="-server -Xms1024m -Xmx1024m"

#Modify umask so that group has r+w
umask 02
CATALINA_PID=${CATALINA_HOME}/bin/catalina.pid

ENV_LEVEL=DEV
export ENV_LEVEL

$ chmod 755 setenv.sh
$ chown tomcat:tomcat setenv.sh

Modify tomcat-users.xml to set password and roles access.

$ cd /opt/tomcat/tomcat-inst1/tomcat-current/conf

Make a backup of the current file.

$ mv tomcat-users.xml tomcat-users.xml.orig

Create a new file with the following contents and set the passwords to your liking.

$ vi tomcat_users.xml

<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
  <role rolename="manager-gui"/>
  <role rolename="tomcat"/>
  <role rolename="admin"/>
  <user username="manager" password="tommgr" roles="manager-gui,admin"/>
  <user username="tomcat" password="tomcat" roles="tomcat"/>
</tomcat-users>

chmod 600 tomcat-users.xml
chown tomcat:tomcat tomcat-users.xml

Now we can start Tomcat up and should be working.

How to Fix Flash Player Crashing on Firefox 20

After a recent upgrade of Firefox to 20.01 Adobe Flash player starting crashing on sites. After Googling around I found that most were saying to upgrade or downgrade Flash. Tried them all with no change until I ran across a suggestion to install the debug version of Flash which did the trick.

Download the Windows Flash Player 11.7 Plugin content debugger (for Netscape-compatible browsers) (EXE, 17.21MB) and install and that’s it!

Switch to our mobile site