Обсуждение: Question: script to start DB on server reboot

Поиск
Список
Период
Сортировка

Question: script to start DB on server reboot

От
"Aurangzeb M. Agha"
Дата:
This is more a scripting question than a DB question but since it relates
to Postgres, and since I'm sure others on this list have tackled this same
problem, I'm hoping I'll be able to get some help here.  Apologies in
advance if this is the incorrect forum.

I have a site hosted by an ISP which, for one reason or another, often
needs to restart their server after upgrades, maintenance, etc...  When
this happens, I need a script to restart my server and my Java processes.
While I've got the entire script written, I'm having a major problem
getting the DB to start up due to the permissions on the DB dir.

The dir out of which my application is served has the following contents:

drwxr-xr-x    9 admin    admin        4096 Mar 30 14:22 .
drwxr-xr-x    3 admin    admin        4096 Mar 31 08:58 ..
drwx------    6 postgres postgres     4096 May 19 20:55 DB
drwxr-xr-x    5 admin    admin        4096 Mar 29 02:01 backup
...
drwxr-xr-x    3 admin    admin        4096 Mar 28 23:06 lib

Note that my DB dir has 700 permissions for the Postgres user and group.
This has made it impossible for me to effect any change in this dir when
the script runs--the script is run on startup by the admin user (this is
requirement due to the setup by the ISP, and I don't have the power to run
the script as root).

What I need to do is very simple.  Before I start any of my other
processes (Java, Apache, etc...), I want to start up the DB:

        1.  Remove postmaster.pid if it exists
        2.  Backup the existing log file
        3.  Start the DB

However, I can't even get into the dir due to its permission structure.
Is my permission structure for the DB incorrect?

So far, I have the following for my bash script (Note: This is my first
bash script, so go easy).  The first line of code is the tricky one, since
I'm not able to check for the file's existance with the current permission
structure I have:

# We only run this script if the DB is running (postmaster.pid exists).
# If the DB is not running, don't bother to do anything else, as the site
# is probably down for a good reason.  Postmaster.pid is in the DB dir,
# which is only accessible to the 'postgres' user, so how do we run this
# script, since we can only run it as 'admin', and the permission
# structure of the DB dir only allows 'postgres' user access?
if [ -f /usr/local/G101/App/DB/postmaster.pid ]; then

        # From here on out, everything can be done by the 'admin' user

        # Check how many java processes are running; if there
    # are less than two (arbitrary), we need to restart Resin
    $numJavaProcs=`ps -ef | grep -i java | grep -v grep | wc -l`
        if [ $numJavaProcs -lt 2 ]; then

        # Run the runResin-site.sh script to start up Resin.
                # Do we need to specify the nohup if the command is run by
        # a script?
                nohup /usr/local/G101/App/bin/runResin-site.sh &

        # Move the nohup.out file to the logs dir
                mv /usr/local/G101/App/bin/nohup.out
/usr/local/G101/App/bin/logs/nohup-site.out

        # Is there a way to send mail to aagha@greece101.com here
        # to let the admin know that Resin had to be restarted?
                # mail -s "Resin had to be restarted!" aagha@greece101.com
        fi
fi

# Do we need this to end the program?
exit 0;

Anyone have any thoughts or suggestions?

    Thanks in Advance,
    Aurangzeb

Re: Question: script to start DB on server reboot

От
Paul Thomas
Дата:
On 09/06/2003 07:40 Aurangzeb M. Agha wrote:

> I have a site hosted by an ISP which, for one reason or another, often
> needs to restart their server after upgrades, maintenance, etc...  When
> this happens, I need a script to restart my server and my Java processes.
> While I've got the entire script written, I'm having a major problem
> getting the DB to start up due to the permissions on the DB dir.
>
> The dir out of which my application is served has the following contents:
>
> drwxr-xr-x    9 admin    admin        4096 Mar 30 14:22 .
> drwxr-xr-x    3 admin    admin        4096 Mar 31 08:58 ..
> drwx------    6 postgres postgres     4096 May 19 20:55 DB
> drwxr-xr-x    5 admin    admin        4096 Mar 29 02:01 backup
> ...
> drwxr-xr-x    3 admin    admin        4096 Mar 28 23:06 lib
>
> Note that my DB dir has 700 permissions for the Postgres user and group.
> This has made it impossible for me to effect any change in this dir when
> the script runs--the script is run on startup by the admin user (this is
> requirement due to the setup by the ISP, and I don't have the power to
> run
> the script as root).
>
> What I need to do is very simple.  Before I start any of my other
> processes (Java, Apache, etc...), I want to start up the DB:
>
>         1.  Remove postmaster.pid if it exists
>         2.  Backup the existing log file
>         3.  Start the DB
>
> However, I can't even get into the dir due to its permission structure.
> Is my permission structure for the DB incorrect?
>

Maybe you could get your admin user added to postgres's group then use
0770 permissions for your postgres directory tree. I think that would work.

  --
Paul Thomas
+------------------------------+---------------------------------------------+
| Thomas Micro Systems Limited | Software Solutions for the Smaller
Business |
| Computer Consultants         |
http://www.thomas-micro-systems-ltd.co.uk   |
+------------------------------+---------------------------------------------+

Re: Question: script to start DB on server reboot

От
"scott.marlowe"
Дата:
What OS are you on?  There are standard startup scripts for both BSD and
Linux in the /contrib/start-scripts directory which should work, but they
need to be run by root I believe.  Are you saying you can't get a script
run by root at startup to start postgresql?

The recommendation on changing the directory permissions is misguided, as
you NEED to have the permissions at 700 for postgresql to start up, and no
one but the postgres superuser (whatever account that may be) should be
able to go in there.

On Sun, 8 Jun 2003, Aurangzeb M. Agha wrote:

> This is more a scripting question than a DB question but since it relates
> to Postgres, and since I'm sure others on this list have tackled this same
> problem, I'm hoping I'll be able to get some help here.  Apologies in
> advance if this is the incorrect forum.
>
> I have a site hosted by an ISP which, for one reason or another, often
> needs to restart their server after upgrades, maintenance, etc...  When
> this happens, I need a script to restart my server and my Java processes.
> While I've got the entire script written, I'm having a major problem
> getting the DB to start up due to the permissions on the DB dir.
>
> The dir out of which my application is served has the following contents:
>
> drwxr-xr-x    9 admin    admin        4096 Mar 30 14:22 .
> drwxr-xr-x    3 admin    admin        4096 Mar 31 08:58 ..
> drwx------    6 postgres postgres     4096 May 19 20:55 DB
> drwxr-xr-x    5 admin    admin        4096 Mar 29 02:01 backup
> ...
> drwxr-xr-x    3 admin    admin        4096 Mar 28 23:06 lib
>
> Note that my DB dir has 700 permissions for the Postgres user and group.
> This has made it impossible for me to effect any change in this dir when
> the script runs--the script is run on startup by the admin user (this is
> requirement due to the setup by the ISP, and I don't have the power to run
> the script as root).
>
> What I need to do is very simple.  Before I start any of my other
> processes (Java, Apache, etc...), I want to start up the DB:
>
>         1.  Remove postmaster.pid if it exists
>         2.  Backup the existing log file
>         3.  Start the DB
>
> However, I can't even get into the dir due to its permission structure.
> Is my permission structure for the DB incorrect?
>
> So far, I have the following for my bash script (Note: This is my first
> bash script, so go easy).  The first line of code is the tricky one, since
> I'm not able to check for the file's existance with the current permission
> structure I have:
>
> # We only run this script if the DB is running (postmaster.pid exists).
> # If the DB is not running, don't bother to do anything else, as the site
> # is probably down for a good reason.  Postmaster.pid is in the DB dir,
> # which is only accessible to the 'postgres' user, so how do we run this
> # script, since we can only run it as 'admin', and the permission
> # structure of the DB dir only allows 'postgres' user access?
> if [ -f /usr/local/G101/App/DB/postmaster.pid ]; then
>
>         # From here on out, everything can be done by the 'admin' user
>
>         # Check how many java processes are running; if there
>     # are less than two (arbitrary), we need to restart Resin
>     $numJavaProcs=`ps -ef | grep -i java | grep -v grep | wc -l`
>         if [ $numJavaProcs -lt 2 ]; then
>
>         # Run the runResin-site.sh script to start up Resin.
>                 # Do we need to specify the nohup if the command is run by
>         # a script?
>                 nohup /usr/local/G101/App/bin/runResin-site.sh &
>
>         # Move the nohup.out file to the logs dir
>                 mv /usr/local/G101/App/bin/nohup.out
> /usr/local/G101/App/bin/logs/nohup-site.out
>
>         # Is there a way to send mail to aagha@greece101.com here
>         # to let the admin know that Resin had to be restarted?
>                 # mail -s "Resin had to be restarted!" aagha@greece101.com
>         fi
> fi
>
> # Do we need this to end the program?
> exit 0;
>
> Anyone have any thoughts or suggestions?
>
>     Thanks in Advance,
>     Aurangzeb
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>


Re: Question: script to start DB on server reboot

От
weigelt@metux.de
Дата:
On Fri, Jun 13, 2003 at 02:35:11PM -0600, scott.marlowe wrote:
> What OS are you on?  There are standard startup scripts for both BSD and
> Linux in the /contrib/start-scripts directory which should work, but they
> need to be run by root I believe.  Are you saying you can't get a script
> run by root at startup to start postgresql?

btw: did someone ever try to start the postmaster from init ?

cu
--
---------------------------------------------------------------------
 Enrico Weigelt    ==   metux ITS
 Webhosting ab 5 EUR/Monat.          UUCP, rawIP und vieles mehr.

 phone:     +49 36207 519931         www:       http://www.metux.de/
 fax:       +49 36207 519932         email:     contact@metux.de
 cellphone: +49 174 7066481         smsgate:   sms.weigelt@metux.de
---------------------------------------------------------------------
 Diese Mail wurde mit UUCP versandt.      http://www.metux.de/uucp/

Re: Question: script to start DB on server reboot

От
"Aurangzeb M. Agha"
Дата:
Hi Scott --

I'm running on Red Hat 7.2.  I'll have a look at the scripts you've
mentioned, but the prob is that since this is a "virtual server", I don't
have root privileges.  Your assessment is correct.

Thanks for the permissions info on the DB server.

    Rgs,
    Zeb

On Fri, 13 Jun 2003, scott.marlowe wrote:

:What OS are you on?  There are standard startup scripts for both BSD and
:Linux in the /contrib/start-scripts directory which should work, but they
:need to be run by root I believe.  Are you saying you can't get a script
:run by root at startup to start postgresql?
:
:The recommendation on changing the directory permissions is misguided, as
:you NEED to have the permissions at 700 for postgresql to start up, and no
:one but the postgres superuser (whatever account that may be) should be
:able to go in there.
:
:On Sun, 8 Jun 2003, Aurangzeb M. Agha wrote:
:
:> This is more a scripting question than a DB question but since it relates
:> to Postgres, and since I'm sure others on this list have tackled this same
:> problem, I'm hoping I'll be able to get some help here.  Apologies in
:> advance if this is the incorrect forum.
:>
:> I have a site hosted by an ISP which, for one reason or another, often
:> needs to restart their server after upgrades, maintenance, etc...  When
:> this happens, I need a script to restart my server and my Java processes.
:> While I've got the entire script written, I'm having a major problem
:> getting the DB to start up due to the permissions on the DB dir.
:>
:> The dir out of which my application is served has the following contents:
:>
:> drwxr-xr-x    9 admin    admin        4096 Mar 30 14:22 .
:> drwxr-xr-x    3 admin    admin        4096 Mar 31 08:58 ..
:> drwx------    6 postgres postgres     4096 May 19 20:55 DB
:> drwxr-xr-x    5 admin    admin        4096 Mar 29 02:01 backup
:> ...
:> drwxr-xr-x    3 admin    admin        4096 Mar 28 23:06 lib
:>
:> Note that my DB dir has 700 permissions for the Postgres user and group.
:> This has made it impossible for me to effect any change in this dir when
:> the script runs--the script is run on startup by the admin user (this is
:> requirement due to the setup by the ISP, and I don't have the power to run
:> the script as root).
:>
:> What I need to do is very simple.  Before I start any of my other
:> processes (Java, Apache, etc...), I want to start up the DB:
:>
:>         1.  Remove postmaster.pid if it exists
:>         2.  Backup the existing log file
:>         3.  Start the DB
:>
:> However, I can't even get into the dir due to its permission structure.
:> Is my permission structure for the DB incorrect?
:>
:> So far, I have the following for my bash script (Note: This is my first
:> bash script, so go easy).  The first line of code is the tricky one, since
:> I'm not able to check for the file's existance with the current permission
:> structure I have:
:>
:> # We only run this script if the DB is running (postmaster.pid exists).
:> # If the DB is not running, don't bother to do anything else, as the site
:> # is probably down for a good reason.  Postmaster.pid is in the DB dir,
:> # which is only accessible to the 'postgres' user, so how do we run this
:> # script, since we can only run it as 'admin', and the permission
:> # structure of the DB dir only allows 'postgres' user access?
:> if [ -f /usr/local/G101/App/DB/postmaster.pid ]; then
:>
:>         # From here on out, everything can be done by the 'admin' user
:>
:>         # Check how many java processes are running; if there
:>     # are less than two (arbitrary), we need to restart Resin
:>     $numJavaProcs=`ps -ef | grep -i java | grep -v grep | wc -l`
:>         if [ $numJavaProcs -lt 2 ]; then
:>
:>         # Run the runResin-site.sh script to start up Resin.
:>                 # Do we need to specify the nohup if the command is run by
:>         # a script?
:>                 nohup /usr/local/G101/App/bin/runResin-site.sh &
:>
:>         # Move the nohup.out file to the logs dir
:>                 mv /usr/local/G101/App/bin/nohup.out
:> /usr/local/G101/App/bin/logs/nohup-site.out
:>
:>         # Is there a way to send mail to aagha@greece101.com here
:>         # to let the admin know that Resin had to be restarted?
:>                 # mail -s "Resin had to be restarted!" aagha@greece101.com
:>         fi
:> fi
:>
:> # Do we need this to end the program?
:> exit 0;
:>
:> Anyone have any thoughts or suggestions?
:>
:>     Thanks in Advance,
:>     Aurangzeb
:>
:> ---------------------------(end of broadcast)---------------------------
:> TIP 2: you can get off all lists at once with the unregister command
:>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
:>
:

--
Aurangzeb M. Agha     | Email : ama@mltp.com
                      | Home  : +1 617 739.7324
38A Saint Paul St. #2 | Mobile: <coming soon>
Brookline, MA 02446   | e-Fax : +1 978 246.0770
USA                   | PGP id: <coming soon>

"Those who would give up essential liberty to purchase a little
 temporary safety deserve neither liberty nor safety."

                    - Benjamin Franklin