Showing posts with label approach. Show all posts
Showing posts with label approach. Show all posts

Wednesday, April 19, 2017

Posted by beni in , , , , , , , , , , , | April 19, 2017

A better approach to install Liferay on Tomcat using Ubuntus provided package


When you install Tomcat using apt-get on Ubuntu, its root folder will be in /var/lib/tomcat7

Inside of it, there will be some folders and symbolic links

work -> ../../cache/tomcat7
logs -> ../../log/tomcat7
conf -> /etc/tomcat7
shared
server
common
temp
webapps

Folders bin and lib will be in /usr/share/tomcat7

Following the install process described in Installing Liferay on Tomcat 7 you will see, in the first sentence:

Liferay Home is one folder above Tomcat�s install location.
If you start Liferay without changing anything, just like the tutorial says, Liferay will create its folders in the Liferay Home, which is, by default, /var/lib/.

Having application data folders inside /var/lib is not a good idea, just like Dave Kliczbor commented on the comments section on that page.

In order to "fix" that behaviour, create the file /var/lib/tomcat7/webapps/ROOT/WEB-INF/classes/portal-ext.properties and add the line

liferay.home=/var/lib/tomcat7
Create the folders /var/lib/tomcat7/data and /var/lib/tomcat7/deploy and make them writeable for the user tomcat7 running

sudo chown -R tomcat7:tomcat7 /var/lib/tomcat7/data
sudo chown -R tomcat7:tomcat7 /var/lib/tomcat7/deploy


Thats enough to have your Liferay server ready to run.

Tuesday, April 18, 2017

Posted by beni in , , , , , , , , , , | April 18, 2017

A different approach to change MySQL root password in Ubuntu Server


The other day I was having a problem with the MySQL server on my Ubuntu machine. After connecting to mysql server in php, I could not select a database. The error was: Access denied for user @localhost to database foo. I did specify the user being root, but it keept saying I dont have permissions with the user (anonymous). Reinstalling mysql didnt do the job. So, lets delete the user .

1. Stop the MySQL Server:

sudo /etc/init.d/mysql stop

or
sudo service mysql stop

2. Start the mysqld:
sudo mysqld --skip-grant-tables &

Press CTRL+C (^C) to be able to enter the new command.
3. Login to mysql server:
sudo mysql -u root mysql

4. Delete the user :
If you enter the following command:
SELECT USER(),CURRENT_USER();

you will see that the users are different, one being and the other root.
Delete the anonymous user:
DELETE FROM mysql.user WHERE user = ;

Update root password (optional, if you know it):
UPDATE user SET Password=PASSWORD(1234) WHERE User=root;

5. Stop mysql server instance:
ps aux | grep mysql

On the second column, you will find the PID (process id) of mysql server. Kill it:
kill 20233

6. Start the usual mysql server:
sudo service mysql start


Resources: ubuntu.flowconsult.at

Sunday, April 2, 2017

Posted by beni in , , , , , , , , , , , , | April 02, 2017

A general approach to command line switches and their default values in Perl


In the UNIX world youll rarely find a program which doesnt support a few or many arguments (or command line parameters) which influence the execution of the program.

When Perl programs require arguments (one of the simplest cases: an input filename) one could investigate the ARGV hash (an approach which works well in easy cases) or one could turn to one of the Perl modules, in particular if the arguments are command line switches.

In this article I will discuss a few types of command line switches and the possible logic behind.

What is a command line switch?

Just to recap: a command line switch is traditionally denoted as a hyphen followed by a letter optionally followed by a value e.g.  -d or  -d 25 . Note the space between the switch and its value. Some programs require this space whereas other require the value to be attached to the switch like -d25 and still others allow both. Some programs allow switches to be concatenated like  -ltr instead of  -l -t -r . Others allow switches to be more than one letter. Some programs allow a switch to appear multiple times like -v in awk.
Further complexities exist: one switch might override others. Some switches exclude each other mutually.
All these cases would need to be handled properly.

On top of that (I think it was) the GNU world introduced double hyphen switches with (usually) string switches e.g.  --verbose .

In the remainder of this article I will only use the simple case of single letter switches with or without argument. I will be using Getopt::Std, one of the core Perl modules and its function getopts. Its basic usage is  getopts(ab:,%opts); for two switches  -a and  -b foo.

Various types of command line switches with or without default values

The typical distinction between command line switches is whether they are boolean (switched on or off) or carry an additional argument. Then there is the question: if a command line switch is absent should there be a default value used in the program?

The following table explains the differences and shows a few examples.

switchExampleDefaultNotes
 -a 
...falseA boolean switch by its very nature has a default value true or false which should be the opposite of what the switch intends to trigger.
 -d $HOME/tmp 
output directory/tmpCertain things in the program require a default value e.g. the program needs to know where to store its output files. Its left to the programmer to decide which of the default values can be overruled by command line switches.
 -u joe,sandy 
user listcurrent userSome command line switches can take more complex arguments, in this case a comma separated list of users. Its absence should be covered by a reasonable default value e.g. the current user.
 -p 1507 
process idall processesSome switches do specify a setting which acts as a filter or a kind of a restriction but its absence does not imply a default value but is somewhat vague.
In the user list example before another default behaviour could have been all users instead of current user.

Rather than defining a list of variables to set the defaults like

 $OUTDIR = "/tmp"; $USERS = $ENV{USER}; ... 
and later somehow associate these variables with the switches a (in my view) cleaner approach is to
  • define the defaults in a hash (the keys are the switches)
  • create a new hash (again with switches for keys) and set them to either the defaults or values supplied by the command line
    The following Perl program handles the cases above.
  • boolean switches and unspecified defaults are set to undef, all others are set to their reasonable default values.
  • the  ... ? ... : ... operator is used to set the actual variables
    (Getopt::Std sets boolean switches to 1 which represents true, the opposite (and default) could be anything that evaluates to false in an if(...) clause, I chose undef rather than 0).

     #!/usr/bin/perl use strict; use Getopt::Std; # to process command line arguments # Define the defaults in a hash my %defaults; $defaults{"a"} = undef; $defaults{"d"} = "/tmp"; $defaults{"u"} = $ENV{USER}; $defaults{"p"} = undef; # Retrieve the command line switches into a hash # making sure which ones are boolean and which require an argument with : my %opts; getopts(ad:u:p:,%opts); # Put either the default values or the command line switch arguments into a hash my %vars; foreach my $key (keys %defaults) { $vars{$key} = exists $opts{$key} ? $opts{$key} : $defaults{$key} ; } # Test output: see what is contained in vars foreach my $key (keys %vars) { print $key," ",$vars{$key}," "; } print " "; # Check decision tree for boolean and unspecified switches print "a is set " if( $vars{"a"} ); print "p: all processes " unless( $vars{"p"} ); 

    If run without any command line switches:

     u andreas p a d /tmp p: all processes 

    With -a and -u

     ... -a -u joe,sandy u joe,sandy p a 1 d /tmp a is set p: all processes 

    With -p and -d

     ... -d $HOME/tmp -p 1507 u andreas p 1507 a d /export/home/andreas/tmp 

    With this general approach one hash vars contains all the information and its contents can be used directly later in the program (like -d output directory) or used in a decision process defined vs. undefined.

    Of course there are more issues like the ones mentioned above (e.g. conflicting switches) or validity of values (e.g. does the output directory exist and is writable) but they need to be resolved somewhere else in the code.

  • Search