Created
December 19, 2014 01:13
-
-
Save maus-/3d10b7d11e674f030aee to your computer and use it in GitHub Desktop.
osquery init script for centos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# osqueryd Start/Stop the osquery daemon. | |
# | |
# chkconfig: 2345 90 60 | |
# Description: | |
# With osquery, you can use SQL to query low-level | |
# operating system information. Under the hood, instead | |
# of querying static tables, these queries dynamically execute | |
# high-performance native code. The results of the | |
# SQL query are transparently returned to you quickly and easily | |
# | |
### BEGIN INIT INFO | |
# Provides: osquery osqueryd | |
# Required-Start: $local_fs $syslog | |
# Required-Stop: $local_fs $syslog | |
# Default-Start: 2345 | |
# Default-Stop: 90 | |
# Short-Description: run osqueryd daemon | |
# Description: | |
# With osquery, you can use SQL to query low-level | |
# operating system information. Under the hood, instead | |
# of querying static tables, these queries dynamically execute | |
# high-performance native code. The results of the | |
# SQL query are transparently returned to you quickly and easily | |
# | |
# | |
### END INIT INFO | |
RETVAL=0 | |
prog="osqueryd" | |
exec=/usr/bin/osqueryd | |
config=/etc/osquery/osquery.conf | |
pidfile=/var/run/osquery.pid | |
lockfile=/var/lock/subsys/osquery | |
# Source function library. | |
. /etc/rc.d/init.d/functions | |
[ $UID -eq 0 ] && [ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog | |
start() { | |
if [ $UID -ne 0 ] ; then | |
echo "User has insufficient privilege." | |
exit 4 | |
fi | |
[ -x $exec ] || exit 5 | |
[ -f $config ] || exit 6 | |
echo -n $"Starting $prog: " | |
# TODO : make this chef template so its dynamically set based on node | |
# ATTRS | |
daemon $prog --pidfile=$pidfile --db_path=/etc/osquery/osquery.db --config_path=/etc/osquery/osquery.conf & | |
retval=$? | |
echo | |
[ $retval -eq 0 ] && touch $lockfile | |
} | |
stop() { | |
if [ $UID -ne 0 ] ; then | |
echo "User has insufficient privilege." | |
exit 4 | |
fi | |
echo -n $"Stopping $prog: " | |
if [ -s $pidfile ]; then | |
killproc -p $pidfile | |
RETVAL=3 | |
else | |
failure $"Stopping $prog" | |
fi | |
retval=$? | |
echo | |
[ $retval -eq 0 ] && rm -f $lockfile | |
} | |
restart() { | |
rh_status_q && stop | |
start | |
} | |
reload() { | |
echo -n $"Reloading $prog: " | |
if [ -n "`pidfileofproc $exec`" ]; then | |
killproc $exec -HUP | |
else | |
failure $"Reloading $prog" | |
fi | |
retval=$? | |
echo | |
} | |
rh_status() { | |
# run checks to determine if the service is running or use generic status | |
status -p $pidfile $prog | |
} | |
rh_status_q() { | |
rh_status >/dev/null 2>&1 | |
} | |
case "$1" in | |
start) | |
rh_status_q && exit 0 | |
$1 | |
;; | |
stop) | |
rh_status_q || exit 0 | |
$1 | |
;; | |
restart) | |
$1 | |
;; | |
status) | |
rh_status | |
;; | |
*) | |
echo $"Usage: $0 {start|stop|status|restart}" | |
exit 2 | |
esac | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment