How to Extend Default User Token Expiration in a Devstack Environment

To extend the default token expiration, which is currently one hour, the file /etc/keystone/keystone.conf has to be modified. There is an expiration property in the file that is disabled by default and assumes a value of 3600, representing 3600 seconds or one hour. Simply enable the property and modify the value to anything that works for your Devstack environment (e.g., 86400 for one day). In other words, make the change from

# Amount of time a token should remain valid (in seconds). (integer value)
#expiration = 3600

to

# Amount of time a token should remain valid (in seconds). (integer value)
expiration = 86400

To make this change take effect Keystone has to be restarted. It appears that in the latest releases of Devstack Keystone is no longer runs under its own service, but rather under Apache (reference). So stopping/starting/restarting Keystone can be easily done via

sudo service apache2 stop/start/restart

Advertisements

Find and Copy Files While Preserving the Folder Structure in Linux

In Linux in order to find files following a pattern we use the “find” command:

find [parent folder] -name “[regular expression]”

In order to copy files found by this command we can pipe the output into the “xargs” command (source):

find [parent folder] -name “[regular expression]” | xargs cp -t [destination folder]

The “cp” command comes with a “–parents” switch where, if used, it would create the same folder structure in the target location:

cp [file(s) or folder(s)] [destination folder] –parents

By combining these features we can now use “find“, “xargs“, and “cp” commands together to have the files of interest be copied into a destination folder while preserving the folder structure:

find [parent folder] -name “[regular expression]” | xargs cp -t [destination folder] –parents

Rotating Tomcat’s Default catalina.out

I was looking for log rotation options for Tomcat’s default catalina.out (JULI package), and came across these two solutions:

  1. Piping the log to a log rotation utility: I tried this and it worked like a charm.
  2. Configuring logrotate to rotate the file: I have not tried this yet, but it sounds like a more generic way of rotating this log file.

Find Cluster Size of an NTFS Disk Drive

The following command returns this info (among other things):

fsutil fsinfo ntfsinfo [Drive Letter]:

For example:

fsutil fsinfo ntfsinfo c:

Another way of getting the cluster size is running “chkdsk” on the drive, but depending on the drive and content size “chkdsk” could take a while to run.

Reference

DB2 Tips

  • List of tables within a specific schema:
    SELECT NAME FROM SYSIBM.SYSTABLES WHERE CREATOR = ‘[schema]’ AND TYPE = ‘T’ ORDER BY NAME
  • List of columns in a particular database table:
    SELECT NAME FROM SYSIBM.SYSCOLUMNS WHERE TBCREATOR = ‘[schema]’ AND TBNAME = ‘[table]’ ORDER BY NAME
  • Database backup from DB2 command line:
    db2 backup database [db name] to [path to target folder]
  • Database restore from DB2 command line
    db2 restore database [db name in the backup] from [path to backup folder] [optional: into [another db name]]
    – into [another db name] is used if the database name needs to be different from the database name in the backup
  • Start and stop database engine from DB2 command line
    db2start
    db2stop [optional: force]
    – the optional parameter ‘force’ is used for stopping the database when there are applications still using the database, and the command ‘db2stop’ by itself would not work.
  • Get the current value of a sequence
    SELECT PREVVAL FOR [sequence name] FROM SYSIBM.SYSDUMMY1
  • Get the next value of a sequence
    SELECT NEXTVAL FOR [sequence name] FROM SYSIBM.SYSDUMMY1
    – causes the sequence number to increment as well
    SELECT PREVVAL FOR [sequence name] + 1 FROM SYSIBM.SYSDUMMY1
    – no increment, assuming the increment is 1, otherwise:
    SELECT VAL.VAL + INC.INC
    FROM (SELECT PREVVAL FOR [sequence name] AS VAL FROM SYSIBM.SYSDUMMY1) VAL,
                 (SELECT INCREMENT INC FROM SYSIBM.SYSSEQUENCES WHERE SEQNAME=’[sequence name]‘) INC

Export Microsoft SQL Database Data as Text

I know that some database clients already provide this functionality where you can export their data into text files or other textual formats, but in my case, the data resided on Microsoft SQL Server 2005 and the only GUI client available was SQL Server Management Studio Express, which misses this basic feature.

After some investigation I managed to use some scripts to extract the data from all tables within a specific database into text files. Two command line utilities helped me here; one sqlcmd and the other bcp. These tools should already exist in your installation folder if you have Microsoft SQL Server installed.

I’m going to explain here the steps. Let’s assume the database I’m trying to export is called “mydb”:

  1. Created a text file called “mydb.sql” that contains sqlcmd commands for extracting list of tables in “mydb” database. This file contains:

    use mydb;
    go
    select name from sysobjects;
    go

    The select statement above is like any other SQL select. So it can have a where clause to filter out tables in the “mydb” database.

  2. Created a batch file called “mydb-tables.bat” that calls the above query to extract the desired tables. Here’s what’s in this file:

    sqlcmd -i mydb.sql -o mydb.out

    This batch file when run stores the outcome of the query in step #1 in “mydb.out”.

  3. Copied the list of returned table names from “mydb.out” and used an online line-break remover tool (such as this) to convert the new lines into white spaces. The result should have this format:

    Table1 Table2 Table3 … Tablen

  4. Created another batch file called “mydb.bat” that extracts content of these tables one by one. Here’s the content of this file:

    FOR %%A IN (Table1 Table2 … Tablen) DO bcp mydb.dbo.%%A out .\mydb\%%A.txt -U <username> -P <password> -t \t -r \n -w >> mydb.log

    Note that:
    – Inside the brackets is the list of tables extracted in step #3;
    – out refers to where the output should be created;
    – It is assumed that you have a “mydb” folder inside the current directory that will hold the extracts after this script is called;
    <username> and <password> are valid credentials for accessing “mydb” database;
    -t \t indicates a tab character should separate columns in the result;
    -r \n indicates that a new line character should separate rows in the result; and
    -w indicates that data in the database is copied using unicode characters.

Resolve AIX error “Cannot open or remove a file containing a running program”

Situation: When trying to replace an IHS (IBM HTTP Server) module we were getting the following error, even though the web server had been stopped:

./mod_XXXXX.so: Cannot open or remove a file containing a running program.
Environment: IHS 6.1 / WebSphere 6.1 on AIX 6.1.
Solution: The issue was resolved by using the slibclean command. According to the manual,
The slibclean command unloads all object files with load and use counts of 0. It can also be used to remove object files that are no longer used from both the shared library region and in the shared library and kernel text regions by removing object files that are no longer required.
This file could be located in the /usr/sbin/ folder.