Skip to content

Commit

Permalink
Merge pull request #1 from justintime32/redhat_init
Browse files Browse the repository at this point in the history
Add SysV-style init script and systemd service unit configuration
  • Loading branch information
nbrownus authored Dec 1, 2016
2 parents 8982cc8 + c801c80 commit d76a81b
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions contrib/rh-sysv.go-audit.init
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/sh
#
# go-audit
#
# chkconfig: - 15 85
# description: go-audit is an alternative to the auditd daemon that \
# ships with many distros.
# processname: go-audit
# config: /etc/go-audit.yaml
# pidfile: /var/run/go-audit.pid

# Source function library.
. /etc/rc.d/init.d/functions

exec="/usr/local/bin/go-audit"
prog=$(basename $exec)
pidfile=/var/run/${prog}.pid

CONFIG_FILE="/etc/go-audit.yaml"
LOG_DIRECTORY="/var/log/go-audit"

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

start() {
[ -f $pidfile ] && checkpid $(cat $pidfile) && echo "$prog already running" && return

echo -n $"Starting $prog: "
nohup $exec --config $CONFIG_FILE >>${LOG_DIRECTORY}/go-audit.out 2>>${LOG_DIRECTORY}/go-audit.err </dev/null &
pid=$!
echo $pid >$pidfile

sleep 0.1 # Sleep briefly to see if the process ends immediately
checkpid $(cat $pidfile)
status=$?
if [ $status -eq 0 ]; then success; else failure; fi
echo
return $status
}

stop() {
echo -n $"Stopping $prog: "
killproc -p $pidfile $prog
retval=$?
echo
[ $retval -eq 0 ] && rm -f $pidfile
return $retval
}

restart() {
stop
start
}

rh_status() {
status -p $pidfile $prog
}

case "$1" in
start|stop|restart)
$1
;;
status)
rh_status
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
exit 2
esac

0 comments on commit d76a81b

Please sign in to comment.