LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-12-2010, 12:19 AM   #1
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Rep: Reputation: 36
Setting a variable in unix


Hi ,

Whenever i want to start tomcat server I need to go to <tomcatdir>\bin
and execute startup.sh file.

How would i make this happen whenever i start my machine?

Also want to know How would i set the variable at startup.
for example
I want to set JAVA_HOME and JRE_HOME whenever the machine is started.
 
Old 05-12-2010, 12:26 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,256

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
Distro information might help?

But basically, startup files usually go in /etc/init.d or /etc/rc.* and variables for individual users are set in the appropriate rc file for your shell, like .bashrc
 
Old 05-12-2010, 12:30 AM   #3
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

You're actually asking two different questions:
Quote:
Q1: How do I start tomcat as a service?

A: You might be able to simply go into your distro's GUI "Control Panel" (for example, YaST2 for SuSE Linux), select "Services", and enable Tomcat for runlevels "3" and "5"
Quote:
Q2: How do I set a global variable automatically?

A: Again, the "best" way depends on your exact distro.
But a common method is to edit /etc/profile:
Code:
sudo vi /etc/profile
  export JAVA_HOME=/usr/foo/jdk_whatever
  export JRE_HOME=/usr/foo/bar
 
Old 05-12-2010, 12:33 AM   #4
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by grail View Post
Distro information might help?

But basically, startup files usually go in /etc/init.d or /etc/rc.* and variables for individual users are set in the appropriate rc file for your shell, like .bashrc
Distribution Details

Code:
LSB Version:    :core-3.1-ia32:core-3.1-noarch:graphics-3.1-ia32:graphics-3.1-noarch
Distributor ID: EnterpriseEnterpriseServer
Description:    Enterprise Linux Enterprise Linux Server release 5.2 (Carthage)
Release:        5.2
Codename:       Carthage
I have .bashrc file in following locations which one should i edit?
What should i write into those files

Code:
[root@TOMCATSERVER ~]# find / -name .bashrc
/etc/skel/.bashrc
/home/oracle/.bashrc
/root/.bashrc
 
Old 05-12-2010, 12:39 AM   #5
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 36
Quote:
You're actually asking two different questions:

Q1: How do I start tomcat as a service?

A: You might be able to simply go into your distro's GUI "Control Panel" (for example, YaST2 for SuSE Linux), select "Services", and enable Tomcat for runlevels "3" and "5"
There is no such service named as Tomcat.
For running tomcat i go to <tomcatdir>/bin
and run startup.sh


Quote:
Q2: How do I set a global variable automatically?

A: Again, the "best" way depends on your exact distro.
But a common method is to edit /etc/profile:
Code:

sudo vi /etc/profile
export JAVA_HOME=/usr/foo/jdk_whatever
export JRE_HOME=/usr/foo/bar
Just a small question here What is the difference between vi /etc/profile and sudo vi /etc/profile ?
 
Old 05-12-2010, 12:59 AM   #6
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 36
I have put the files in /root/.bashrc file

But from the observation i came to know that you need to login once into your server to get it executed.

This is not what i intend to do .
My goal is to start this service as soon as the machine is started not till someone logs into the system.
 
Old 05-12-2010, 01:06 AM   #7
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Debian, OS X
Posts: 1,298

Rep: Reputation: 102Reputation: 102
Lightbulb

Quote:
Originally Posted by pinga123 View Post
I have put the files in /root/.bashrc file

But from the observation i came to know that you need to login once into your server to get it executed.

This is not what i intend to do .
My goal is to start this service as soon as the machine is started not till someone logs into the system.
You can append the lines in /etc/profile too.
 
Old 05-12-2010, 01:26 AM   #8
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 36
From some other forum i came across following process.
Quote:
Put the script in /etc/rc3.d directory and rename it as startup scripts already there in the directort

Say S99_startup.sh .when the machine will boot it will execute the script.
Can u please explain what is the difference in putting the file in /etc/rc3.d directory and putting a command in /etc/profile?
 
Old 05-12-2010, 02:29 AM   #9
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi, again -

Cool - this helps enormously! Thank you:
Quote:
Description: Enterprise Linux Enterprise Linux Server release 5.2 (Carthage)
Grail is absolutely correct (grail and I happened to be typing at the same time ):
Quote:
But basically, startup files usually go in /etc/init.d or /etc/rc.* and variables for individual users are set in the appropriate rc file for your shell, like .bashrc (or /etc/profile)
This is wrong:
Quote:
I have put the files in /root/.bashrc file
As you discovered, this is NOT what you want to do.
It will only work when "root" logs in, and it will only be effective for his login environment (not the rest of the system).

Ideally, Tomcat might already be available as a "service" you could simply "enable". That appears not to be the case for your distro (Enterprise Linux).

"Plan B" is to create your own daemon, by adding a script to /etc/rc3.d and/or /etc/rc5.d. This is basically Good Advice:
Quote:
Put the script in /etc/rc3.d directory and rename it as startup scripts already there in the directory.

Say S99_startup.sh .when the machine will boot it will execute the script.
Here's a good example script you can adapt:
http://www.spaceprogram.com/knowledg...at_init_d.html

Quote:
Q: What is the difference between vi /etc/profile and sudo vi /etc/profile?

A: "sudo SOME_COMMAND" lets you conveniently execute that command (such as "vi /etc/profile" as "root".

You should never EVER stay logged in as "root": you should ALWAYS try to log in - and do as much work as you can for as long as you can - as a "normal" user. It's just good practice, and a good habit
Quote:
You can append the lines in /etc/profile too.
<= it depends on what you want to put into /etc/profile!
Remember:
* ONLY put your "JAVA_HOME" and "JRE_HOME" variable definitions in "/etc/profile".

* Do NOT try to put your startup scripts in /etc/profile: they belong in /etc/rc.*

'Hope that helps .. PSM

Last edited by paulsm4; 05-12-2010 at 02:34 AM.
 
Old 05-12-2010, 04:45 AM   #10
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 36
Wink

Quote:
Originally Posted by paulsm4 View Post
Hi, again -

Cool - this helps enormously! Thank you:


Grail is absolutely correct (grail and I happened to be typing at the same time ):


This is wrong:
As you discovered, this is NOT what you want to do.
It will only work when "root" logs in, and it will only be effective for his login environment (not the rest of the system).

Ideally, Tomcat might already be available as a "service" you could simply "enable". That appears not to be the case for your distro (Enterprise Linux).

"Plan B" is to create your own daemon, by adding a script to /etc/rc3.d and/or /etc/rc5.d. This is basically Good Advice:

Here's a good example script you can adapt:
http://www.spaceprogram.com/knowledg...at_init_d.html




Remember:
* ONLY put your "JAVA_HOME" and "JRE_HOME" variable definitions in "/etc/profile".

* Do NOT try to put your startup scripts in /etc/profile: they belong in /etc/rc.*

'Hope that helps .. PSM
I have one question (don't know if it is stupid one )
Whenever i run <apachedir>/bin/startup.sh.
It needs either JAVA_HOME or JRE_HOME to be setup .

Therefore I just wanted either JAVA_HOME or JRE_HOME to be setup before i call to the startup script .
At what runlevel these variables will be set?
2nd Question.
If we can start a tomcat using startup.sh script present in <apachedir>/bin/startup.sh then why do we need to create a deamon ?

These question might be silly for the seniors but they are keep bothering me so i asked here.
Any way i have modified /etc/profile to include JAVA_HOME and JRE_HOME.
 
Old 05-12-2010, 05:06 AM   #11
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,256

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
Quote:
Any way i have modified /etc/profile to include JAVA_HOME and JRE_HOME
So the fact you have done this means that this:
Quote:
It needs either JAVA_HOME or JRE_HOME to be setup
has been done.

daemon - Computer Science: A program or process that sits idly in the background until it is invoked to perform its task.

daemon and service are kind of interchangeable words.

As for why do we need to create a deamon ?, you don't have to if your happy to continue starting it manually.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Variable MultiLine Spacing With Sed On Linux Or Unix LXer Syndicated Linux News 0 07-07-2008 01:30 AM
LXer: Speaking UNIX, Part 4: Setting and managing permissions on UNIX LXer Syndicated Linux News 0 10-21-2006 02:54 AM
setting a variable variable in a script... this works, but could it be more elegant? pwc101 Programming 3 08-18-2006 12:23 PM
Problem with perl script using a variable from a unix command. abefroman Programming 1 05-11-2006 06:11 PM
Problem with shell script using a variable from a unix command. abefroman Programming 1 05-10-2006 03:14 PM


All times are GMT -5. The time now is 08:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration