Koozali.org: home of the SME Server

Adding a system environment variable or path

Offline edb

  • *
  • 548
  • +0/-0
Adding a system environment variable or path
« on: September 09, 2007, 07:20:40 AM »
   
Does anyone know how I can create a system environment variable?
I had this working in SME6x by adding two lines to /etc/init.d/httpd file in the section below start() { of the httpd file.... like this:

# The semantics of these two functions differ from the way apachectl does
# things -- attempting to start while running is a failure, and shutdown
# when not running is also a failure.  So we just do it the way init scripts
# are expected to behave here.
start() {
        my_variable=/home/e-smith/files/ibays/store
    export my_variable

    echo -n $"Starting $prog: "
        daemon $httpd `moduleargs` $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch /var/lock/subsys/httpd
        return $RETVAL
}
stop() {

The two added lines set the variable that tells my one website where to find it's custom files.
I had this working in SME6x by directly editing the "httpd" file but I can't seem to reproduce this in SME 7.2 ,  I believe because "/etc/init.d/httpd" is no longer available and is replaced by "/etc/init.d/httpd-e-smith". When I try to edit the "httpd-e-smith" file the same way I did with the "httpd" file in SME-6x it doesn't seem to work or give me the same result.
I just cannot seem to get this working in SME7.2 .... I understand that there may be other ways to accomplish setting this system variable which is necessary for one of my websites?
If someone knows of an alternate way I would be greatful.

Any advise is welcome.
Thanks

edb
......

Offline edb

  • *
  • 548
  • +0/-0
Re: Adding a system environment variable or path
« Reply #1 on: September 15, 2007, 08:47:39 PM »
Still looking for some assistance on this issue but what I have discovered is that if I modify the /etc/httpd file then shut down /etc/init.d/httpd-e-smith stop and do a /etc/init.d/httpd start I then have the results I'm looking for as far as adding the system variable through the httpd file.
What I want to simply be able to accomplish is the same result but by using the /etc/init.d/httpd-e-smith file which is the way e-smith was designed to start Apache.
Is there a template that I could create or something becuase a direct modify of the /etc/init.d/httpd-e-smith file for some reason doesn't add the variable as it does when I modify the /etc/init.d/httpd file.

Hope you can make sense of what I saying as I'm trying to be as clear as I can.

Maybe Charlie could shed some light if he's watching this thread.

Any help appreciated.
......

Offline byte

  • *
  • 2,183
  • +2/-0
Re: Adding a system environment variable or path
« Reply #2 on: September 16, 2007, 11:05:49 PM »
--[byte]--

Have you filled in a Bug Report over @ http://bugs.contribs.org ? Please don't wait to be told this way you help us to help you/others - Thanks!

Offline edb

  • *
  • 548
  • +0/-0
Re: Adding a system environment variable or path
« Reply #3 on: September 17, 2007, 12:40:07 AM »
Thanks Byte

Yes I looked at it, but nothing in there helps me with my specific question or I'm not smart enough to find what I'm supose to be looking for but either way it doesn't help.
......

Offline cactus

  • *
  • 4,880
  • +3/-0
    • http://www.snetram.nl
Re: Adding a system environment variable or path
« Reply #4 on: September 17, 2007, 12:29:08 PM »
I just cannot seem to get this working in SME7.2 .... I understand that there may be other ways to accomplish setting this system variable which is necessary for one of my websites?
If someone knows of an alternate way I would be greatful.

Any advise is welcome.
It is not quite clear to me whyt you tried to solve things like this, perhaps you can explain your situation a bit more. What is your goal for instance?

Perhaps we can template your solution in the configuration file of the server, which will also make it portable over upgrades and updates...
Be careful whose advice you buy, but be patient with those who supply it. Advice is a form of nostalgia, dispensing it is a way of fishing the past from the disposal, wiping it off, painting over the ugly parts and recycling it for more than its worth ~ Baz Luhrmann - Everybody's Free (To Wear Sunscreen)

Offline edb

  • *
  • 548
  • +0/-0
Re: Adding a system environment variable or path
« Reply #5 on: September 17, 2007, 03:29:45 PM »
Hi cactus,

My situation is that I have a custom ecommerce site where the third party programmer designed the software to use a system variable to define the path of where to find the applications files. Whithout this system variable defined it will not work.

The way we got it working in SME6x was by adding two lines to /etc/init.d/httpd file in the section below start() { of the httpd file.... like this:

# The semantics of these two functions differ from the way apachectl does
# things -- attempting to start while running is a failure, and shutdown
# when not running is also a failure.  So we just do it the way init scripts
# are expected to behave here.
start() {
        STORE_BASE=/home/e-smith/files/ibays/store
        export STORE_BASE

        echo -n $"Starting $prog: "
        daemon $httpd `moduleargs` $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch /var/lock/subsys/httpd
        return $RETVAL
}
stop() {

The two added lines set the variable that tells my ecommerce website where to find it's custom config files.

I wrote a simple info.php script to obtain the two reqired variables if things are working properly I should get a value returned for

Here is the info.php file I made to test if the variable is present.


start of file ----------

<body bgcolor="rgb(210,160,95)"
<strong>This php script is to echo out the two necessary STORE variables to confirm that they are set as required.</strong></br></br>

<div>Server Name =
<td><strong><?php echo $_SERVER['SERVER_NAME'] ?></strong></td></div></br>
<div>STORE Base Directory =
<td><strong><?php echo getenv('STORE_BASE') ?></strong></td></div></br></br>

<font color=red <strong>If you not conficts between what is shown here and where you have your STORE files located you will need to correct this before continuing!</strong></font>
</bgcolor></br></br>

End of file -------------

The results displayed by this php file should indicate the
Server Name = www.mycompany.com
STORE Base Directory = /home/e-smith/files/ibays/store

This is all I'm trying to accomplish.

Thanks for helping ...

edb
......

Offline cactus

  • *
  • 4,880
  • +3/-0
    • http://www.snetram.nl
Re: Adding a system environment variable or path
« Reply #6 on: September 17, 2007, 05:23:42 PM »
I think you are far better of using the SET_ENV command in the apache configuration

You probably defined a configuration template for your application of is it running in an ibay?

Anyway we need to make a configuration template to be incorporated in the httpd.conf file:

1. First step is to create a custom template directory to add the template fragment:
Code: [Select]
mkdir -p /etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf2. Now we are going to add our directive to a template which we call 25SetEnv:
Code: [Select]
cat 'SetEnv STORE_BASE /home/e-smith/files/ibays/store' > /etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf/25SetEnv3. The only thing that needs to be done is to regenerate the configuration file:
Code: [Select]
expand-template /etc/httpd/conf/httpd.conf4. Make sure that our settinfgs are in the configuration file:
Code: [Select]
grep 'SetEnv STORE_BASE' /etc/httpd/conf/httpd.confwhich should output the text we entered in quotes atr step 2.
5. and restart the Apache webserver:
Code: [Select]
service httpd-e-smith restart

    You do not need the lines in your startup script anymore. This way changes can be portable over backups and upgrades.
    Be careful whose advice you buy, but be patient with those who supply it. Advice is a form of nostalgia, dispensing it is a way of fishing the past from the disposal, wiping it off, painting over the ugly parts and recycling it for more than its worth ~ Baz Luhrmann - Everybody's Free (To Wear Sunscreen)

    Offline edb

    • *
    • 548
    • +0/-0
    Re: Adding a system environment variable or path
    « Reply #7 on: September 17, 2007, 08:57:00 PM »
    Hi cactus,

    I tried what you suggested and it worked great!!  :shock:

    Thank you very much for your help cactus you are the best!!
    « Last Edit: September 17, 2007, 09:03:24 PM by edb »
    ......

    Offline cactus

    • *
    • 4,880
    • +3/-0
      • http://www.snetram.nl
    Re: Adding a system environment variable or path
    « Reply #8 on: September 17, 2007, 09:38:26 PM »
    Thank you very much for your help cactus you are the best!!
    Thanks very much... if you feel this way please hit the good advice button!
    Be careful whose advice you buy, but be patient with those who supply it. Advice is a form of nostalgia, dispensing it is a way of fishing the past from the disposal, wiping it off, painting over the ugly parts and recycling it for more than its worth ~ Baz Luhrmann - Everybody's Free (To Wear Sunscreen)

    Offline edb

    • *
    • 548
    • +0/-0
    Re: Adding a system environment variable or path
    « Reply #9 on: September 17, 2007, 10:23:46 PM »
    As you wish .... thanks again
    ......