Find the answer to your Linux question:
Results 1 to 10 of 10
please can anyone help. i need to get root user environment when run e.g. "/sbin/service myapp start" i have tried to include these lines in /etc/init.d/myapp: . /etc/profile . /root/.bash_profile ...
  1. #1
    Just Joined!
    Join Date
    Jul 2009
    Posts
    5

    Angry how to get user environment into /sbin/service



    please can anyone help.

    i need to get root user environment when run e.g. "/sbin/service myapp start"

    i have tried to include these lines in /etc/init.d/myapp:

    . /etc/profile
    . /root/.bash_profile

    but i still cannot get the environment as logged on as root, verified by set.

    i am using rhel 4.8

    thanks
    zcw

  2. #2
    Linux Newbie
    Join Date
    Mar 2009
    Posts
    228
    The problem is you can't access /root/.bash_profile because the permissions on the /root directory doesn't allow non-root users to access it.

    You could change the permisions on the /root directory so non-root users has access it but strongly not adviced.

    The thing to do would be take the parts of .bash_profile that non-root users need and place it in another script somewhere that anyone can access it and execute that.

  3. #3
    Just Joined!
    Join Date
    Jul 2009
    Posts
    5
    but "/sbin/service myapp start" is run by root, so it should have access to /root/*

  4. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,485
    You can write a script that sources /root/.bash_profile and then executes /sbin/service. You still need to be root to do this.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  5. #5
    Just Joined!
    Join Date
    Jul 2009
    Posts
    5
    but i think that /sbin/service runs on empty environment? if i set up environment first, then run /sbin/service, it may reset to empty, but worth trying. thanks. ideally we want to keep using /sbin/service.

    Quote Originally Posted by Rubberman View Post
    You can write a script that sources /root/.bash_profile and then executes /sbin/service. You still need to be root to do this.

  6. #6
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,485
    Quote Originally Posted by zcwlinux View Post
    but i think that /sbin/service runs on empty environment? if i set up environment first, then run /sbin/service, it may reset to empty, but worth trying. thanks. ideally we want to keep using /sbin/service.
    Well, it is a script itself that executes another script for the named service in turn. You might want to look at it in detail to see why you are losing your environment.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  7. #7
    Just Joined!
    Join Date
    Jul 2009
    Posts
    5
    en, i think that i may need to expand my problem description a little bit. it is grails/spring we used in our website, which is served by tomcat has this problem. Without this bit of grails/spring, tomcat works fine and can be started/stopped using /sbin/service. once this grails/spring is included, we can only start tomcat using any of the following:

    /etc/init.d/tomcat start
    /etc/rc5.d/S80tomcat start
    $CATALINA_HOME/bin/startup.sh

    but "/sbin/service tomcat start" does not work and most importantly, tomcat will not start on reboot. even if i put $CATALINA_HOME/bin/startup.sh in /etc/rc.local, tomcat still cannot start on reboot.

    Obviously, i have posted in tomcat and grails user groups, but no clue.

  8. #8
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,485
    Thanks for the expansion of the situation. It's the "little" details like this that can save everyone a lot of time and effort giving you the wrong advice...
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  9. #9
    Just Joined!
    Join Date
    Jul 2009
    Posts
    5
    hi

    your inputa are very useful. i think that the problem is the environment. if i gave all the details it not likely i will have any suggestions.

    thank very much i will try ut your suggestions wehn i can play with the server.

  10. #10
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,485
    Quote Originally Posted by zcwlinux View Post
    your inputa are very useful. i think that the problem is the environment. if i gave all the details it not likely i will have any suggestions.
    Or, you might just find that there is someone on the forums that has had a similar experience and knows what to do to fix it... I just hate spending my valuable time going down dead-ends because the originator of the thread left out important information like you did.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •