Archive

Posts Tagged ‘linux’

Ubuntu 9.04 !!!

Ubuntu: For Desktops, Servers, Netbooks and in the cloud

Ubuntu 9.04 is Coming Soon! On April 23rd, 2009, the newest member of the Ubuntu family will be released and made available for download.

For specific details, check out Ubuntu 9.04

The Ubuntu 9.04 pre-release version is available for download and testing.

Categories: linux, whats hot Tags: , , ,

SVN or Subversion Repository – How would you set it up?

February 26, 2009 Gaurav Sohoni 1 comment

It has been a long time since I posted my last blog post. So here I am ‘populating’ my post with some information that could be of some worth to me and others in need. So without much delay, let me put down the ad hoc article on setting up svn repository. It also talks about creating a structured hierarchy for code management and also gives information on adding projects to SVN repository.

To create svn repository svnadmin command line tool is used.

$ svnadmin /home/gaurav/new_repo

To add directories to the new repository …


$ svn mkdir file:///home/gaurav/new_repo/main_project


$ svn mkdir file:///home/gaurav/new_repo/main_project/branches


$ svn mkdir file:///home/gaurav/new_repo/main_project/tags


$ svn mkdir file:///home/gaurav/new_repo/main_project/trunk


When directories are added, it asks for the commit comments.

Once the repository structure is ready, import the code like this:


$ svn import /home/gaurav/my_new_app/ file:///home/gaurav/new_repo/main_project/trunk

Following command runs svn server @ port 4444 for localhost

-r is for the repository and should be passed the repository path

$ svnserve -d -r /home/gaurav/repository/ --listen-port 4444 --listen-host localhost

Once svn server starts as a daemon, checkout can be done as:

$ svn co svn://localhost:4444/momsworld/trunk mw_0718

—————————————————————————————

Add users to your server

In order to authenticate our intended users, some changes are required to be made. Inside the new repo (c:\svn-repo or /home/gaurav svn-repo), there is a directory called conf. There you will find svnserve.conf.

You need to enable these lines in the file:

[general]
anon-access = read
auth-access = write
password-db = passwd

All other comments can be left untouched. For easy readability, I have only put the required section above.

With this setting, anyone would be able to read the files but only an authenticated user would be able to checkin. Also password-db tells server that a file named ‘passwd’ would be storing usernames and passwords.

Let’s create that file now. It should also be in the conf directory and look like this:

[users]
david = secret

Similarly many users could be added in the format NAME = PASSWORD. There are many other advanced ways to add password protection to Subversion but this one is the easiest I suppose. Subversion has good integration with Apache’s web server authentication so that could be utilized as well.

Linux cron tasks

Cron task is used to automate tasks in Unix/Linux. It is something that you need to trigger commands / scripts @ specific interval of time. It is sort of task scheduler that windows has. But it is much more customizable and is command line based. So lets see how can we add cron tasks.

Lets say we have a shell script that displays nothing but todayz date. It is named date_today.sh and for some reason you want to run it every day @ 00.00 hrs.

The first thing you should know about cron task is the format in which you specify the time for automating your tasks. There are five fields to set the time.

* * * * * <command to execute>

You need to set the five stars as per your requirement. These 5 *s are five fields for

1. minute (0-59)
2. hour (0-23)
3. day (1-31)
4. month (1-12)
5. day of week (0-6, 6 being Sunday)
6. command to execute

So now to execute our date_today.sh file, we need to add the cron task to the system. To do that issue this command:

$ crontab -e

Depending on your login, your cron tasks will differ. So once you are presented with your editor to edit the file, enter the following line:

0 * * * * /home/user_name/date_today.sh

This will make sure that your shell script runs everyday @ midnight. If you want to run it every 5 minutes, use this instead:

*/5 * * * * /home/user_name/date_today.sh

or

0 1 29 1 1 /home/user_name/date_today.sh

will help you setup the execution on 1.00 AM, 29th January, Monday. You could also use this for same result….

0 1 29 jan mon /home/user_name/date_today.sh

Once you have entered the time, exit and wait for it to be executed. :D

Cron tasks can be used for several purposes like backing up data, deleting logfiles / temporary files, copying data etc. So unless you have a lot of time to spend in front of your computer for the right moment to trigger commands on your own, I think you shud be using cron tasks. :D

Categories: linux Tags: ,

Log rotation in Linux

This thing bugged me a lot. In general all applications create logs and depending on how much information is passed on to the log file, log file might end up taking gigs of space (as it happened in my case). So I searched for a solution and got one. It is ‘logrotate’. Using logrotate on linux lets you configure the rotation of log files. It can create new log files, remove old ones after compressing them. This can be done on daily or monthly basis or you can even customize it as per your need.

Lets say you have a log file @ this location:

/usr/local/log/file_to_rotate.log

You can rotate this file using a simple configuration file which should look like this:

# Your logs:
/usr/local/log/file_to_rotate.log {
daily
missingok
rotate 14
compress
delaycompress
notifempty
copytruncate
}


This will compress the log file and max 14 compressed, rolled over files will be created (one per day so total 14 in 2 weeks). After that older rolled over files will be deleted. So at a given time, only 14 rolled over files would exist on the file system. You might be required to restart the server in some cases. Auto restart can be done with the following addition in the above written configuration script:

/usr/local/log/file_to_rotate.log {
daily
missingok
rotate 14
compress
delaycompress
notifempty
copytruncate
postrotate
/etc/init.d/myserver restart
endscript
}

postrotate…endscript block lets you specify things you need to do after rotating the log. With this script in place @ this location:

/user/conf_folder/rotation.conf

Lets add this in cron tasks. You need to do this for adding a new cron job:

$ crontab -e

Add the following code in the file:

00 00 * * * /usr/sbin/logrotate -s /home/user/config/logrotate.status /user/conf_folder/rotation.conf

Cron will take care of executing logrotate @ midnight everyday. Out of the three arguements, first one is the place where logrotate resides, second one following -s arguement is the one where logrotate will be keeping its status file and the last one is the configuration file you made in the first step.

Categories: linux Tags: , , ,