Question: script to start DB on server reboot - Mailing list pgsql-general
From | Aurangzeb M. Agha |
---|---|
Subject | Question: script to start DB on server reboot |
Date | |
Msg-id | Pine.LNX.4.53.0306082321070.8486@cinemaspace.berkeley.edu Whole thread Raw |
Responses |
Re: Question: script to start DB on server reboot
Re: Question: script to start DB on server reboot |
List | pgsql-general |
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
pgsql-general by date: