Chris Browne cbbrowne at lists.slony.info
Wed Apr 18 07:57:33 PDT 2007
Update of /home/cvsd/slony1/slony1-engine/tools/mkservice
In directory main.slony.info:/tmp/cvs-serv3198

Modified Files:
	README logrep-mkservice.sh slon-mkservice.sh 
Log Message:
Further changes to mkservice tools, per Andrew Hammond.


Index: README
===================================================================
RCS file: /home/cvsd/slony1/slony1-engine/tools/mkservice/README,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** README	17 Apr 2007 21:58:47 -0000	1.2
--- README	18 Apr 2007 14:57:31 -0000	1.3
***************
*** 12,21 ****
  
  For non-interactive use, set the following environment variables.
! BASEDIR SYSUSR PASSFILE DBUSER HOST PORT DATABASE CLUSTER SLON_BINARY
  If any of the above are not set, the script asks for configuration
! information interactively.
  
  BASEDIR where you want the service directory structure for the slon
  to be created. This should _not_ be the /var/service directory.
  SYSUSR the unix user under which the slon (and multilog) process should run.
  PASSFILE location of the .pgpass file to be used. (default ~sysusr/.pgpass)
--- 12,26 ----
  
  For non-interactive use, set the following environment variables.
! BASEDIR LOGBASE SYSUSR PASSFILE DBUSER HOST PORT DATABASE CLUSTER SLON_BINARY
  If any of the above are not set, the script asks for configuration
! information interactively. The following environment variables are optional.
! LOGMAX LOGNUM
! If they are not set, they will silently default to reasonable values.
  
  BASEDIR where you want the service directory structure for the slon
  to be created. This should _not_ be the /var/service directory.
+ (default /usr/local/etc)
+ LOGBASE where you want your logs to end up. (default /var/log)
+ if set to - then revert to old behaviour and put logs under log/main.
  SYSUSR the unix user under which the slon (and multilog) process should run.
  PASSFILE location of the .pgpass file to be used. (default ~sysusr/.pgpass)
***************
*** 26,29 ****
--- 31,36 ----
  CLUSTER the name of your Slony1 cluster? (default database)
  SLON_BINARY the full path name of the slon binary (default `which slon`)
+ LOGMAX maximum size (in bytes) of logfiles (default 10485760 which is 10MB)
+ LOGNUM number of files to maintain (default 99, assume other tool prunes)
  
  logrep-mkservice.sh
***************
*** 37,50 ****
  
  For non-interactive use, set the following environment variables.
! BASEDIR SYSUSR SOURCE EXTENSION CRITERIA 
  If any of the above are not set, the script asks for configuration
! information interactively.
  
  BASEDIR where you want the service directory structure for the logrep
  to be created. This should _not_ be the /var/service directory.
  SYSUSR unix user under which the service should run.
  SOURCE name of the service with the log you want to follow.
  EXTENSION a tag to differentiate this logrep from others using the same source.
  CRITERIA the multilog filter you want to use.
  
  A trivial example of this would be to provide a log file of all slon
--- 44,63 ----
  
  For non-interactive use, set the following environment variables.
! BASEDIR LOGBASE SYSUSR SOURCE EXTENSION CRITERIA 
  If any of the above are not set, the script asks for configuration
! information interactively. The following environment variables are optional.
! LOGMAX LOGNUM
! If they are not set, they will silently default to reasonable values.
  
  BASEDIR where you want the service directory structure for the logrep
  to be created. This should _not_ be the /var/service directory.
+ LOGBASE where you want your logs to end up. (default /var/log)
+ if set to - then revert to old behaviour and put logs under log/main.
  SYSUSR unix user under which the service should run.
  SOURCE name of the service with the log you want to follow.
  EXTENSION a tag to differentiate this logrep from others using the same source.
  CRITERIA the multilog filter you want to use.
+ LOGMAX maximum size (in bytes) of logfiles (default 10485760 which is 10MB)
+ LOGNUM number of files to maintain (default 99, assume other tool prunes)
  
  A trivial example of this would be to provide a log file of all slon

Index: slon-mkservice.sh
===================================================================
RCS file: /home/cvsd/slony1/slony1-engine/tools/mkservice/slon-mkservice.sh,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** slon-mkservice.sh	30 Mar 2007 14:49:46 -0000	1.1
--- slon-mkservice.sh	18 Apr 2007 14:57:31 -0000	1.2
***************
*** 6,17 ****
  #
  # Create a slon service directory for use with svscan from deamontools.
! # This uses multilog in a pretty basic way. See logrep for cleverness.
! # Currently very limited error handling. This probably needs to be fixed...
! #
  # For non-interactive use, set the following environment variables.
! # BASEDIR SYSUSR PASSFILE DBUSER HOST PORT DATABASE CLUSTER SLON_BINARY
  
  DEFAULT_SLON_BINARY=`which slon`                # silly, wild-ass guess
  DEFAULT_BASEDIR='/usr/local/etc'
  DEFAULT_SYSUSR='pgsql'                          # FreeBSD-centric. Oh well.
  DEFAULT_DBUSR='slony'                           # Best Practice...
--- 6,40 ----
  #
  # Create a slon service directory for use with svscan from deamontools.
! # This uses multilog in a pretty basic way, which seems to be standard 
! # for daemontools / multilog setups. If you want clever logging, see
! # logrep below. Currently this script has very limited error handling
! # capabilities.
! # 
  # For non-interactive use, set the following environment variables.
! # BASEDIR LOGBASE SYSUSR PASSFILE DBUSER HOST PORT DATABASE CLUSTER SLON_BINARY
! # If any of the above are not set, the script asks for configuration
! # information interactively. The following environment variables are optional.
! # LOGMAX LOGNUM
! # If they are not set, they will silently default to reasonable values.
! # 
! # BASEDIR where you want the service directory structure for the slon
! # to be created. This should _not_ be the /var/service directory.
! # (default /usr/local/etc)
! # LOGBASE where you want your logs to end up. (default /var/log)
! # if set to - then revert to old behaviour and put logs under log/main.
! # SYSUSR the unix user under which the slon (and multilog) process should run.
! # PASSFILE location of the .pgpass file to be used. (default ~sysusr/.pgpass)
! # DBUSER the postgres user the slon should connect as (default slony)
! # HOST what database server to connect to (default localhost)
! # PORT what port to connect to (default 5432)
! # DATABASE which database to connect to (default dbuser)
! # CLUSTER name of your Slony1 cluster? (default database)
! # SLON_BINARY full path name of the slon binary (default `which slon`)
! # LOGMAX maximum size (in bytes) of logfiles (default 10485760 which is 10MB)
! # LOGNUM number of files to maintain (default 99, assume other tool prunes)
  
  DEFAULT_SLON_BINARY=`which slon`                # silly, wild-ass guess
  DEFAULT_BASEDIR='/usr/local/etc'
+ DEFAULT_LOGBASE='/var/log'
  DEFAULT_SYSUSR='pgsql'                          # FreeBSD-centric. Oh well.
  DEFAULT_DBUSR='slony'                           # Best Practice...
***************
*** 21,25 ****
  
  if [ -z "$BASEDIR" ]; then
!     echo -n "Where do you want the service dir created? Don't want to created this in /service or /var/service. Once it's created, either link or move it to the service directory (since linking is an atomic filesystem action). If your service directory is on a small, relatively static partition, you will almost certainly want to put this on a partition that can handle some log files and then link.
  [$DEFAULT_BASEDIR]: "
      read BASEDIR
--- 44,52 ----
  
  if [ -z "$BASEDIR" ]; then
!     echo -n "Where do you want the service dir created? Don't create this in 
! /service or /var/service. Once it's created, either symlink or move
! it to the service directory (since linking is an atomic filesystem action). 
! Note that log files will not be stored here (that's the next question), so 
! this doesn't have to be on a high storage / IO capacity filesystem.
  [$DEFAULT_BASEDIR]: "
      read BASEDIR
***************
*** 30,33 ****
--- 57,73 ----
  echo "BASEDIR=$BASEDIR"
  
+ if [ -z "$LOGBASE" ]; then
+     echo -n "Where should the logfiles live? You probably want to put this
+ somewhere with plenty of storage and some IO capacity. Note that this
+ creates a subdirectory where the actual log files are stored.
+ Use - to disable this (putting the log files under log/main according to
+ daemontools convention).
+ [$DEFAULT_LOGDIR]: "
+     read LOGDIR
+     if [ -z "$LOGDIR" ]; then
+         LOGDIR="$DEFAULT_LOGDIR"
+     fi
+ fi
+ 
  if [ -z "$SYSUSR" ]; then
      echo -n "System user name for slon to run under [$DEFAULT_SYSUSR]: "
***************
*** 115,125 ****
  echo "SLON_BINARY=$SLON_BINARY"
  
! DIR="$BASEDIR/slon_${CLUSTER}_${HOST}_${PORT}_$DATABASE"
  CONFIGFILE="$DIR/slon.conf"
  echo "CONFIGFILE=$CONFIGFILE"
  
  echo "Service dir will be created under $DIR"
  
! mkdir -p "$DIR/env" "$DIR/supervise" "$DIR/log/supervise" "$DIR/log/main" || exit -1
  # Make sure the log file initially exists. This allows others to tail -F it
  # before it starts getting populated. go go logrep!
--- 155,174 ----
  echo "SLON_BINARY=$SLON_BINARY"
  
! SVCNAME="slon_${CLUSTER}_${HOST}_${PORT}_$DATABASE"
! DIR="$BASEDIR/$SVCNAME"
! LOGDIR="$DIR/log/main"
! if [ '-' != "$LOGBASE" ]; then      # - means don't use a different logdir
!     LOGDIR="$LOGBASE/$SVCNAME"      # otherwise we're logging somewhere else
! fi
  CONFIGFILE="$DIR/slon.conf"
  echo "CONFIGFILE=$CONFIGFILE"
  
  echo "Service dir will be created under $DIR"
+ echo "Logs will live under $LOGDIR"
  
! mkdir -p "$DIR/env" "$DIR/supervise" "$DIR/log/env" "$DIR/log/supervise" "$LOGDIR" || exit -1
! if [ '-' != "$LOGBASE" ]; then          # - means it's not a linked logdir
!     ln -s "$LOGDIR" "$DIR/log/main"
! fi
  # Make sure the log file initially exists. This allows others to tail -F it
  # before it starts getting populated. go go logrep!
***************
*** 277,281 ****
  EOF
  
! # Set up the envdir contents. Generously.
  echo "$SLON_BINARY"                 > $DIR/env/SLON_BINARY
  echo "$CONFIGFILE"                  > $DIR/env/CONFIGFILE
--- 326,330 ----
  EOF
  
! # Set up the envdir contents for the admins. Generously.
  echo "$SLON_BINARY"                 > $DIR/env/SLON_BINARY
  echo "$CONFIGFILE"                  > $DIR/env/CONFIGFILE
***************
*** 284,288 ****
  echo "$PORT"                        > $DIR/env/PGPORT
  echo "$DATABASE"                    > $DIR/env/PGDATABASE
! # The absence of PGPASSWORD is not an oversight. Use .pgpass
  # Configure the location of .pgpass file here...
  # I'd like a better solution than this for expanding the homedir.
--- 333,338 ----
  echo "$PORT"                        > $DIR/env/PGPORT
  echo "$DATABASE"                    > $DIR/env/PGDATABASE
! # The absence of PGPASSWORD is not an oversight. Use .pgpass, see
! # http://www.postgresql.org/docs/current/interactive/libpq-pgpass.html
  # Configure the location of .pgpass file here...
  # I'd like a better solution than this for expanding the homedir.
***************
*** 293,301 ****
  echo 'UTC'                          > $DIR/env/PGTZ
  
  # create the run script for the slon
  cat > "$DIR/run" <<EOF
  #!/bin/sh
! # Note that the slon binary is a variable, so you can edit your envdir
! # settings to upgrade slons then restart them.
  exec 2>&1
  exec envdir ./env sh -c 'exec setuidgid ${SYSUSR} "\${SLON_BINARY}" -f "\${CONFIGFILE}"'
--- 343,394 ----
  echo 'UTC'                          > $DIR/env/PGTZ
  
+ # Avoid some subtle errors by documenting stuff... such as
+ cat > "$DIR/README.txt" <<EOF
+ This service will start on boot. If you do not want it to, then
+ touch $DIR/down
+ 
+ To upgrade your slon, first update env/SLON_BINARY to the full
+ path and name of the new slon binary. Then stop the slon.
+ svc -d $DIR
+ Apply your slonik UPDATE FUNCTIONS script(s) then restart your slon.
+ svc -u $DIR
+ Finally, check your logs to ensure that the new slon has started and
+ is running happily.
+ 
+ If you need to have a special purpose config file, or test version,
+ then you can simply copy the existing slon.conf to some other name,
+ make your changes there, update env/CONFIGFILE to point at the new
+ config and restart the slon.
+ svc -k $DIR
+ 
+ Note that changing variables such as CLUSTER, PGHOST, PGPORT,
+ PGDATABASE and PGUSER in the env directory will not change where
+ the slon connects. They are only there for admin/DBA convenience.
+ exec envdir $DIR/env bash
+ Is a quick way to get your variables all set up.
+ 
+ If you want to change where the slon connects, you need to edit
+ $CONFIGFILE
+ But you probably should not be doing that anyway, because then you
+ have to rename a whole bunch of stuff and edit all over the place
+ to keep the naming scheme consistent. Yuck. You should probably
+ just create a new slon service directory with the correct information,
+ and shut this one down.
+ touch $DIR/down; svc -dx $DIR $DIR/log
+ 
+ EOF
+ 
+ cat > "$DIR/env/README.txt" <<EOF
+ Many of these environment variables are only set as a convenience
+ for administrators and DBAs. To load them, try
+ exec envdir $DIR/env bash
+ Before you change stuff here, please read ../README.txt
+ EOF
+ 
  # create the run script for the slon
  cat > "$DIR/run" <<EOF
  #!/bin/sh
! # Note that the slon binary is a variable, so you can edit the value in
! # env/SLON_BINARY and restart to upgrade slons. See README.txt in this dir.
  exec 2>&1
  exec envdir ./env sh -c 'exec setuidgid ${SYSUSR} "\${SLON_BINARY}" -f "\${CONFIGFILE}"'
***************
*** 304,307 ****
--- 397,427 ----
  echo "$DIR/run created"
  
+ # setup an envdir for multilog
+ echo ${LOGMAX-"10485760"}           > $DIR/log/env/LOGMAX
+ echo ${LOGNUM-"99"}                 > $DIR/log/env/LOGNUM
+ 
+ cat > "$DIR/log/README.txt" <<EOF
+ To force a log rotation, use
+ svc -a $DIR/log
+ 
+ The size (in bytes) of the log files (before they get rotated) is controlled
+ by the s parameter for multilog. This is set up as an envdir variable at
+ $DIR/log/env/LOGMAX
+ You might want to increase or decrease this. It goes up to a maximum of
+ 16777215 (15MB) and defaults to 99999 (97kB) if unset. Leaving it unset 
+ will break this script. It defaults to 10485760 (which is 10MB).
+ You need to restart multilog for changes to this to take effect.
+ svc -k $DIR/log
+ 
+ The n paramter decides how many old log files to keep around. This is set
+ up as an envdir variable at
+ $DIR/log/env/LOGNUM
+ You will probably want to decrease this if you are not using some other
+ tool to manage old logfiles. Multilog defaults to 10 if this is unset, but
+ like the size above, it will break this script if left unset. The script
+ defaults to 99 under the assumption that you are using some other, system
+ wide tool (like cfengine) to prune your logs.
+ EOF
+ 
  # create the run file for the multilog
  cat > "$DIR/log/run" <<EOF
***************
*** 309,330 ****
  # This puts everything in the main log. Unfortunately multilog only allows
  # you to select which log you want to write to as opposed to writing each
! # line to every log which matches the criteria.
! #
! # Note that size (in bytes) of the log files (before they get rotated) is 
! # controlled by the s parameter. You might want to increase this. It goes
! # up to a maximum of 16777215 (15MB) and defaults to 99999 (97kB).
! # I'm using 10485760 (10MB)
! # The n paramter decides how many old log files to keep around. Defaults
! # to 10. 
! exec setuidgid $SYSUSR multilog t s10485760 n99 ./main
  EOF
  chmod a+x "$DIR/log/run"
  echo "$DIR/log/run created"
  
! # create and fix permissions for .pgpass appropriately
  touch "$PASSFILE"
! chmod 600 "$PASSSFILE"
  if [ ! -s "$PASSFILE" ]; then
!     echo "Populating $PASSFILE"
      cat > "$PASSFILE" <<EOF
  #hostname:port:database:username:password
--- 429,446 ----
  # This puts everything in the main log. Unfortunately multilog only allows
  # you to select which log you want to write to as opposed to writing each
! # line to every log which matches the criteria. Split up logs would make
! # debugging harder. See also README.txt in this directory.
! 
! exec envdir ./env sh -c 'exec setuidgid $SYSUSR multilog t s"\$LOGMAX" n"\$LOGNUM" ./main'
  EOF
  chmod a+x "$DIR/log/run"
  echo "$DIR/log/run created"
  
! # create and fix ownerships and permissions for .pgpass appropriately
  touch "$PASSFILE"
! chown "$SYSUSR" "$PASSFILE"
! chmod 600 "$PASSFILE"
  if [ ! -s "$PASSFILE" ]; then
!     echo "Populating $PASSFILE with header and example."
      cat > "$PASSFILE" <<EOF
  #hostname:port:database:username:password
***************
*** 357,360 ****
--- 473,477 ----
  has been created and populated with some sample data.
  
+ Logfiles can be found at $LOGDIR
  You may also want to set up a logrep to filter out the more intresting
  log lines. See logrep-mkservice.sh.

Index: logrep-mkservice.sh
===================================================================
RCS file: /home/cvsd/slony1/slony1-engine/tools/mkservice/logrep-mkservice.sh,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** logrep-mkservice.sh	30 Mar 2007 14:49:46 -0000	1.1
--- logrep-mkservice.sh	18 Apr 2007 14:57:31 -0000	1.2
***************
*** 5,21 ****
  # contributed by Andrew Hammond <andrew.george.hammond at gmail.com>
  #
! # logrep: use tail -F to pull from another log file for filtering to create
! # special purpose log files. Some example filters follow.
! #
  # For non-interactive use, set the following environment variables.
! # BASEDIR SYSUSR SOURCE EXTENSION CRITERIA 
! #
! # Slony subscribe specific information
! # '-*' '+* * ERROR*' '+* * WARN*' '+* * CONFIG enableSubscription*' '+* * DEBUG2 remoteWorkerThread_* prepare to copy table*' '+* * DEBUG2 remoteWorkerThread_* all tables for set * found on subscriber*' '+* * DEBUG2 remoteWorkerThread_* copy*' '+* * DEBUG2 remoteWorkerThread_* Begin COPY of table*' '+* * DEBUG2 remoteWorkerThread_* * bytes copied for table*' '+* * DEBUG2 remoteWorkerThread_* * seconds to*' '+* * DEBUG2 remoteWorkerThread_* set last_value of sequence*' '+* * DEBUG2 remoteWorkerThread_* copy_set*'
! #
! # Errors to trigger nagios
! # '-*' '+* * ERROR*'
  
  DEFAULT_BASEDIR='/usr/local/etc'
  DEFAULT_SYSUSR='pgsql'                          # FreeBSD-centric. Oh well.
  DEFAULT_SOURCE='slon_123'
--- 5,58 ----
  # contributed by Andrew Hammond <andrew.george.hammond at gmail.com>
  #
! # This uses "tail -F" to pull data from log files allowing you to use
! # multilog filters (by setting the CRITERIA) to create special purpose
! # log files. The goal is to provide a way to monitor log files in near 
! # realtime for "interesting" data without either hacking up the initial
! # log file or wasting CPU/IO by re-scanning the same log repeatedly.
! # 
  # For non-interactive use, set the following environment variables.
! # BASEDIR LOGBASE SYSUSR SOURCE EXTENSION CRITERIA 
! # If any of the above are not set, the script asks for configuration
! # information interactively. The following environment variables are optional.
! # LOGMAX LOGNUM
! # If they are not set, they will silently default to reasonable values.
! # 
! # BASEDIR where you want the service directory structure for the logrep
! # to be created. This should _not_ be the /var/service directory.
! # LOGBASE where you want your logs to end up. (default /var/log)
! # if set to - then revert to old behaviour and put logs under log/main.
! # SYSUSR unix user under which the service should run.
! # SOURCE name of the service with the log you want to follow.
! # EXTENSION a tag to differentiate this logrep from others using the same source.
! # CRITERIA the multilog filter you want to use.
! # LOGMAX maximum size (in bytes) of logfiles (default 10485760 which is 10MB)
! # LOGNUM number of files to maintain (default 99, assume other tool prunes)
! # 
! # A trivial example of this would be to provide a log file of all slon
! # ERROR messages which could be used to trigger a nagios alarm.
! # EXTENSION='ERRORS'
! # CRITERIA="'-*' '+* * ERROR*'"
! # (Reset the monitor by rotating the log using svc -a $svc_dir)
! # 
! # A more interesting application is a subscription progress log.
! # EXTENSION='COPY'
! # CRITERIA="'-*' '+* * ERROR*' '+* * WARN*' '+* * CONFIG enableSubscription*' '+* * DEBUG2 remoteWorkerThread_* prepare to copy table*' '+* * DEBUG2 remoteWorkerThread_* all tables for set * found on subscriber*' '+* * DEBUG2 remoteWorkerThread_* copy*' '+* * DEBUG2 remoteWorkerThread_* Begin COPY of table*' '+* * DEBUG2 remoteWorkerThread_* * bytes copied for table*' '+* * DEBUG2 remoteWorkerThread_* * seconds to*' '+* * DEBUG2 remoteWorkerThread_* set last_value of sequence*' '+* * DEBUG2 remoteWorkerThread_* copy_set*'"
! # 
! # If you have a subscription log then it's easy to determine if a given
! # slon is in the process of handling copies or other subscription activity.
! # If the log isn't empty, and doesn't end with a 
! # "CONFIG enableSubscription: sub_set:1"
! # (or whatever set number you've subscribed) then the slon is currently in
! # the middle of initial copies.
! # If you happen to be monitoring the mtime of your primary slony logs to 
! # determine if your slon has gone brain-dead, checking this is a good way
! # to avoid mistakenly clobbering it in the middle of a subscribe. As a bonus,
! # recall that since the the slons are running under svscan, you only need to
! # kill it (via the svc interface) and let svscan start it up again laster.
! # I've also found the COPY logs handy for following subscribe activity 
! # interactively.
  
  DEFAULT_BASEDIR='/usr/local/etc'
+ DEFAULT_LOGDIR='/var/log'
  DEFAULT_SYSUSR='pgsql'                          # FreeBSD-centric. Oh well.
  DEFAULT_SOURCE='slon_123'
***************
*** 24,28 ****
  
  if [ -z "$BASEDIR" ]; then
!     echo -n "Where do you want the service dir created? Don't want to created this in /service or /var/service. Once it's created, either link or move it to the service directory (since linking is an atomic filesystem action). If your service directory is on a small, relatively static partition, you will almost certainly want to put this on a partition that can handle some log files and then link.
  [$DEFAULT_BASEDIR]: "
      read BASEDIR
--- 61,69 ----
  
  if [ -z "$BASEDIR" ]; then
!     echo -n "Where do you want the service dir created? Don't create this in 
! /service or /var/service. Once it's created, either symlink or move
! it to the service directory (since linking is an atomic filesystem action). 
! Note that log files will not be stored here (that's the next question), so 
! this doesn't have to be on a high storage / IO capacity filesystem.
  [$DEFAULT_BASEDIR]: "
      read BASEDIR
***************
*** 33,36 ****
--- 74,90 ----
  echo "BASEDIR=$BASEDIR"
  
+ if [ -z "$LOGBASE" ]; then
+     echo -n "Where should the logfiles live? You probably want to put this 
+ somewhere with plenty of storage and some IO capacity. Note that this
+ creates a subdirectory where the actual log files are stored.
+ Use - to disable this (putting the log files under log/main according to
+ daemontools convention).
+ [$DEFAULT_LOGDIR]: "
+     read LOGDIR
+     if [ -z "$LOGDIR" ]; then
+         LOGDIR="$DEFAULT_LOGDIR"
+     fi
+ fi
+ 
  if [ -z "$SYSUSR" ]; then
      echo -n "System user name for followgrep to run under [$DEFAULT_SYSUSR]: "
***************
*** 69,78 ****
  echo "CRITERIA=$CRITERIA"
  
! DIR="$BASEDIR/logrep_$SOURCE$EXTENSION"
  echo "Service dir will be created under $DIR"
  
! mkdir -p "$DIR/supervise" "$DIR/log/supervise" "$DIR/log/main" || exit -1
  # Make sure the log file initially exists. This allows others to tail -F it
! # before it starts getting populated.
  touch "$DIR/log/main/current" || exit -1
  
--- 123,144 ----
  echo "CRITERIA=$CRITERIA"
  
! 
! SVCNAME="logrep_$SOURCE$EXTENSION"
! DIR="$BASEDIR/$SVCNAME"
! LOGDIR="$DIR/log/main"
! if [ '-' != "$LOGBASE" ]; then      # - means don't use a different logdir
!     LOGDIR="$LOGBASE/$SVCNAME"      # otherwise we're logging somewhere else
! fi
! 
  echo "Service dir will be created under $DIR"
+ echo "Logs will live under $LOGDIR"
  
! 
! mkdir -p "$DIR/env" "$DIR/supervise" "$DIR/log/env" "$DIR/log/supervise" "$LOGDIR" || exit -1
! if [ '-' != "$LOGBASE" ]; then          # - means it's not a linked logdir
!     ln -s "$LOGDIR" "$DIR/log/main"
! fi
  # Make sure the log file initially exists. This allows others to tail -F it
! # before it starts getting populated. go go recursive logrep!
  touch "$DIR/log/main/current" || exit -1
  
***************
*** 81,101 ****
  #!/bin/sh
  exec 2>&1
! exec setuidgid $SYSUSR tail -F "$BASEDIR/$SOURCE/log/main/current"
  EOF
  chmod a+x "$DIR/run"
  echo "$DIR/run created"
  
  # create the run file for the multilog
  cat > "$DIR/log/run" <<EOF
  #!/bin/sh
! # DO NOT add another timestamp using the t parameter to multilog. Unless
! # of course you like being confused.
! # Note that size (in bytes) of the log files (before they get rotated) is 
! # controlled by the s parameter. You might want to increase this. It goes
! # up to a maximum of 16777215 (15MB) and defaults to 99999 (97kB).
! # I'm using 10485760 (10MB)
! # The n paramter decides how many old log files to keep around. Defaults
! # to 10. 
! exec setuidgid $SYSUSR multilog s10485760 n99 $CRITERIA ./main
  EOF
  chmod a+x "$DIR/log/run"
--- 147,193 ----
  #!/bin/sh
  exec 2>&1
! exec env ./env setuidgid $SYSUSR tail -F "$BASEDIR/$SOURCE/log/main/current"
  EOF
  chmod a+x "$DIR/run"
  echo "$DIR/run created"
  
+ # setup an envdir for multilog
+ echo ${LOGMAX-"10485760"}           > $DIR/log/env/LOGMAX
+ echo ${LOGNUM-"99"}                 > $DIR/log/env/LOGNUM
+ 
+ cat > "$DIR/log/README.txt" <<EOF
+ To force a log rotation, use
+ svc -a $DIR/log
+ 
+ The size (in bytes) of the log files (before they get rotated) is controlled
+ by the s parameter for multilog. This is set up as an envdir variable at
+ $DIR/log/env/LOGMAX
+ You might want to increase or decrease this. It goes up to a maximum of
+ 16777215 (15MB) and defaults to 99999 (97kB) if unset. Leaving it unset 
+ will break this script. It defaults to 10485760 (which is 10MB).
+ You need to restart multilog for changes to this to take effect.
+ svc -k $DIR/log
+ 
+ The n paramter decides how many old log files to keep around. This is set
+ up as an envdir variable at
+ $DIR/log/env/LOGNUM
+ You will probably want to decrease this if you are not using some other
+ tool to manage old logfiles. Multilog defaults to 10 if this is unset, but
+ like the size above, it will break this script if left unset. The script
+ defaults to 99 under the assumption that you are using some other, system
+ wide tool (like cfengine) to prune your logs.
+ EOF
+ 
  # create the run file for the multilog
  cat > "$DIR/log/run" <<EOF
  #!/bin/sh
! # This puts everything in the main log. Unfortunately multilog only allows
! # you to select which log you want to write to as opposed to writing each
! # line to every log which matches the criteria. Split up logs would make
! # debugging harder. See also README.txt in this directory.
! # Since we're presumably drawing data from another logfile which already 
! # has timestamps, adding another would simply sow confusion.
! 
! exec envdir ./env sh -c 'exec setuidgid $SYSUSR multilog s"\$LOGMAX" n"\$LOGNUM" ./main'
  EOF
  chmod a+x "$DIR/log/run"



More information about the Slony1-commit mailing list