Here’s an example of an init script to start and stop Logsurfer on RedHat Linux systems, as well as similar systems such as CentOS. Adapt this script to meet your own needs.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
#!/bin/bash # # logsurfer Starts logsurfer # # # chkconfig: 2345 16 94 # description: Logsurfer monitors syslog files ### BEGIN INIT INFO # Provides: $logsurfer ### END INIT INFO # Source function library. . /etc/init.d/functions [ -f /usr/local/bin/logsurfer ] || exit 0 # Source config if [ -f /etc/sysconfig/logsurfer ] ; then . /etc/sysconfig/logsurfer else LOGSURFER_HOME=/var/logsurfer LOGSURFER_EXE=/usr/local/bin/logsurfer SYSLOG_FILE=/var/log/messages LOGSURFER_CONFFILE=$LOGSURFER_HOME/etc/logsurfer.conf LOGSURFER_PIDFILE=$LOGSURFER_HOME/dump/logsurfer.pid LOGSURFER_LOGFILE=$LOGSURFER_HOME/log/logsurfer.log LOGSURFER_DUMPFILE=$LOGSURFER_HOME/dump/logsurfer.dump fi LOGSURFER_ARGS="-c $LOGSURFER_CONFFILE -d $LOGSURFER_DUMPFILE -f -p $LOGSURFER_PIDFILE $SYSLOG_FILE" RETVAL=0 umask 077 start() { echo -n $"Starting logsurfer: " # Start from the current last line of the log file CURRENT_LOG_POS=`wc -l <$SYSLOG_FILE` daemon --user logsurf "$LOGSURFER_EXE -l $CURRENT_LOG_POS $LOGSURFER_ARGS >$LOGSURFER_LOGFILE 2>&1 &" RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/logsurfer return $RETVAL } stop() { echo -n $"Shutting down logsurfer: " killproc logsurfer RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/logsurfer return $RETVAL } rhstatus() { status logsurfer } restart() { stop start } case "$1" in start) start ;; stop) stop ;; status) rhstatus ;; restart|reload) restart ;; condrestart) [ -f /var/lock/subsys/logsurfer ] && restart || : ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart}" exit 1 esac exit $? |