#!/bin/bash # Use chkconfig --add psm to set up the script to start and stop automatically. # P4Search Init Script. # chkconfig: 345 91 29 # description: Start P4Search Monitor for instance REPL_SDP_INSTANCE. # Load SDP controlled shell environment. source /p4/common/bin/p4_vars REPL_SDP_INSTANCE ||\ { echo -e "\nError: Failed to load SDP environment for instance REPL_SDP_INSTANCE.\n"; exit 1; } source $P4CBIN/ps_functions.sh ||\ { echo -e "\nError: Failed to load SDP ps_functions.sh lib.\n"; exit 1; } if [[ $(id -u) -eq 0 ]]; then exec su - $OSUSER -c "$0 $*" elif [[ $(id -u -n) != $OSUSER ]]; then echo "$0 can only be run by root or $OSUSER" exit 1 fi export PSM_ROOT=${P4HOME}}/psm/ export RACK_ENV=production export THISSCRIPT=${0##*/} pid=0 GetPID() { pid=`ps ax | grep ruby | grep psm | grep -v grep | awk '{print $1;}'` } Status() { GetPID if [ "q$pid" = q ] ; then echo "psm is stopped" else echo "psm ($pid) is running" fi exit 0 } Start() { psm & exit $? } Stop() { GetPID kill $pid exit $? } Usage() { echo -e "\nUsage: $THISSCRIPT {start|stop|status|restart}\n" exit 100 } if [ $# != 1 ] ; then Usage fi case ${1:-status} in reload) GetPID kill -HUP $pid opid=$pid GetPID if [ "q$pid" != q -a $pid = $opid ] ; then echo "psm reloaded" else echo "psm not running" fi ;; restart) Stop Start ;; start) Start ;; status) Status ;; stop) Stop ;; *) Usage ;; esac
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 23960 | noe_gonzalez | "Forking branch Dev of perforce-software-sdp to noe_gonzalez-sdp." | ||
//guest/perforce_software/sdp/dev/Server/Unix/p4/common/etc/init.d/psm_init.template | |||||
#4 | 20491 | C. Thomas Tyler |
Fixed an environment insulation bug in init scripts. More testing (and thinking) revealed that the only way to truly provide a guarantee of insulation from user-set defaults in ~perforce/.bashrc (etc.) is to pass SDP_INSTANCE as a parameter to the *_base scripts, so that the instance name is explicitly passed into the su/exec call (when run as root). This change also includes minor cleanup in init scripts and *_base scripts. |
||
#3 | 20448 | C. Thomas Tyler |
Fixed env bug seen when running init scripts as root. Updated *_base scripts and *_init script templates to a new standard. Goals: 1. Init scripts that use corresponding *_base scripts are minimized so that do nothing more than set SDP_INSTANCE and then call the corresponding *_base script. 2. The 'su' commands always pass $* instead of $1, deferring all processing to the *_base script. 3. The shell environment is now guaranteeds to have the same results regardless of whether it is called as 'root' or as the defined OSUSER. 4. The p4_vars file is always sourced exactly once. Two calls to 'source p4_vars' appear in some cases, one immediatley before the su/exec call, and another after the after the 'su/exec'. Only one or the other is sourced. 5. All init scripts have a reasonably consistent usage message. 6. All init scripts accept a 'status' argument. This change fixes a bug where 'p4broker_N_init status' run as the 'perforce' user would report many pids unrelated to Perforce if run as root, e.g. doing 'service p4broker_N_init status'. This also eliminates a potential issue where the 'perforce' user might source a p4_vars with a default instance in ~/.profile or ~/.bashrc, thus invalidating the instance specified when the user ran the init script as root. |
||
#2 | 20341 | C. Thomas Tyler |
Tweaked all init scripts to default to 'status' (rather than an ugly syntax error) of the user forgets the start/stop/status parameter, as was done previosly for the broker init script. Removed unnecessary 'source' call when calling p4<whateve>_base scripts. Cleaned up comments. |
||
#1 | 15607 | C. Thomas Tyler |
Routine merge-down to dev from main using: p4 merge -b perforce_software-sdp-dev |
||
//guest/perforce_software/sdp/main/Server/Unix/p4/common/etc/init.d/psm_init.template | |||||
#1 | 15582 | Russell C. Jackson (Rusty) |
Init script that works with the psm module from Insights as opposed to the example one that calls commands that do not exist. |