Skip to content

Instantly share code, notes, and snippets.

@geoffgarside
Created June 18, 2014 07:25
Show Gist options
  • Save geoffgarside/19caa41bdc5aa15d5ce0 to your computer and use it in GitHub Desktop.
Save geoffgarside/19caa41bdc5aa15d5ce0 to your computer and use it in GitHub Desktop.
Graylog2 0.20 Service Scripts for FreeBSD
#!/bin/sh
#
# PROVIDE: graylog2_server
# REQUIRE: NETWORKING SERVERS
# BEFORE: DAEMON
# KEYWORD: shutdown
#
# Add the following line to /etc/rc.conf to enable graylog2_server:
#
# graylog2_server_enable="YES"
#
# graylog2_server_user (username): Set to graylog2 by default.
# Set it to required username. Use root if you need to bind to ports <1024.
# graylog2_server_group (group): Set to graylog2 by default.
# Set it to required group.
# graylog2_server_config (path): Set to /usr/local/etc/graylog2/graylog2.conf by default.
# Set it to the config file location.
# graylog2_server_logfile (path): Set to /var/log/graylog2-server.log by default.
# graylog2_server_props (args): Additional java properties or arguments.
#
. /etc/rc.subr
name=graylog2_server
rcvar=graylog2_server_enable
load_rc_config $name
: ${graylog2_server_enable:="NO"}
: ${graylog2_server_user:="graylog2"}
: ${graylog2_server_group:="graylog2"}
: ${graylog2_server_config:="/usr/local/etc/graylog2/graylog2.conf"}
: ${graylog2_server_elasticsearch:="/usr/local/etc/graylog2/elasticsearch.yml"}
: ${graylog2_server_logfile:="/var/log/graylog2-server.log"}
: ${graylog2_server_props:=""}
# Force the JVM to use IPv4 stack
# graylog2_server_props="-Djava.net.preferIPv4Stack=true"
required_files="${graylog2_server_config} ${graylog2_server_elasticsearch}"
pidfile="/var/run/graylog2.pid"
jarfile="/usr/local/share/graylog2-server/graylog2-server.jar"
extra_commands="status"
start_precmd="graylog2_server_precmd"
status_cmd="graylog2_server_status"
stop_cmd="graylog2_server_stop"
command="/usr/sbin/daemon"
command_args="/usr/local/bin/java ${graylog2_server_props} -jar ${jarfile} -f ${graylog2_server_config} -p ${pidfile} >> ${graylog2_server_logfile}"
graylog2_server_precmd() {
touch ${pidfile}
chown ${graylog2_server_user}:${graylog2_server_group} ${pidfile}
}
graylog2_server_stop() {
rc_pid=$(graylog2_server_check_pidfile $pidfile)
if [ -z "$rc_pid" ]; then
[ -n "$rc_fast" ] && return 0
echo "${name} not running? (check $pidfile)."
return 1
fi
echo "Stopping ${name}."
kill ${rc_pid} 2> /dev/null
}
graylog2_server_status() {
rc_pid=$(graylog2_server_check_pidfile $pidfile)
if [ -z "$rc_pid" ]; then
[ -n "$rc_fast" ] && return 0
echo "${name} not running? (check $pidfile)."
return 1
fi
echo "${name} is running as pid ${rc_pid}."
}
graylog2_server_check_pidfile() {
_pidfile=$1
if [ -z "$_pidfile" ]; then
err 3 'USAGE: graylog2_server_check_pidfile pidfile'
fi
if [ ! -f $_pidfile ]; then
debug "pid file ($_pidfile): not readable."
return
fi
read _pid _junk < $_pidfile
if [ -z "$_pid" ]; then
debug "pid file ($_pidfile): no pid in file."
return
fi
if [ -n "`/usr/local/bin/jps -l | grep -e "^$_pid graylog2-server.jar\$"`" ]; then
echo -n $_pid
fi
}
load_rc_config ${name}
run_rc_command "$1"
#!/bin/sh
#
# PROVIDE: graylog2_web
# REQUIRE: NETWORKING SERVERS
# BEFORE: DAEMON
# KEYWORD: shutdown
#
# Add the following line to /etc/rc.conf to enable graylog2_web:
#
# graylog2_web_enable="YES"
#
# graylog2_web_user (username): Set to graylog2 by default.
# Set it to required username.
# graylog2_web_group (group): Set to graylog2 by default.
# Set it to required group.
# graylog2_web_config (path): Set to /usr/local/etc/graylog2/graylog2-web.conf by default.
# Set it to the config file location.
# graylog2_web_min_mem (num): Minumum JVM heap size, 1024m by default.
# graylog2_web_max_mem (num): Maximum JVM heap size, 1024m by default.
# graylog2_web_perm_mem (num): Perm JVM heap size, 256m by default.
# graylog2_web_props (args): Additional java properties or arguments.
# graylog2_web_tmp (path): Set to /var/tmp/graylog2_web by default.
# Set it to the path to be used for temp files.
#
. /etc/rc.subr
name=graylog2_web
rcvar=graylog2_web_enable
load_rc_config $name
: ${graylog2_web_enable:="NO"}
: ${graylog2_web_user:="graylog2"}
: ${graylog2_web_group:="graylog2"}
: ${graylog2_web_config:="/usr/local/etc/graylog2/graylog2-web.conf"}
: ${graylog2_web_home:="/usr/local/share/graylog2-web-interface"}
: ${graylog2_web_addr:="0.0.0.0"}
: ${graylog2_web_port:="9000"}
: ${graylog2_web_logconf:="/usr/local/etc/graylog2/graylog2-web-log.xml"}
: ${graylog2_web_min_mem:="1024m"}
: ${graylog2_web_max_mem:="1024m"}
: ${graylog2_web_perm_mem:="256m"}
: ${graylog2_web_props:=""}
# Force the JVM to use IPv4 stack
# graylog2_web_props="-Djava.net.preferIPv4Stack=true"
required_files="${graylog2_web_config} ${graylog2_web_logconf}"
pidfile="/var/run/graylog2/graylog2-web.pid"
GRAYLOG2_LIB="${graylog2_web_home}/lib"
GRAYLOG2_CLASSPATH="${GRAYLOG2_LIB}/*"
GRAYLOG2_CLASSPATH="${GRAYLOG2_LIB}/graylog2-web-interface.graylog2-web-interface-0.20.3.jar:\
${GRAYLOG2_LIB}/org.scala-lang.scala-library-2.10.3.jar:\
${GRAYLOG2_LIB}/com.typesafe.play.play_2.10-2.2.2-RC1.jar:\
${GRAYLOG2_LIB}/com.typesafe.play.sbt-link-2.2.2-RC1.jar:\
${GRAYLOG2_LIB}/org.javassist.javassist-3.18.0-GA.jar:\
${GRAYLOG2_LIB}/com.typesafe.play.play-exceptions-2.2.2-RC1.jar:\
${GRAYLOG2_LIB}/com.typesafe.play.templates_2.10-2.2.2-RC1.jar:\
${GRAYLOG2_LIB}/com.github.scala-incubator.io.scala-io-file_2.10-0.4.2.jar:\
${GRAYLOG2_LIB}/com.github.scala-incubator.io.scala-io-core_2.10-0.4.2.jar:\
${GRAYLOG2_LIB}/com.jsuereth.scala-arm_2.10-1.3.jar:\
${GRAYLOG2_LIB}/com.typesafe.play.play-iteratees_2.10-2.2.2-RC1.jar:\
${GRAYLOG2_LIB}/org.scala-stm.scala-stm_2.10-0.7.jar:\
${GRAYLOG2_LIB}/com.typesafe.config-1.0.2.jar:\
${GRAYLOG2_LIB}/com.typesafe.play.play-json_2.10-2.2.2-RC1.jar:\
${GRAYLOG2_LIB}/com.typesafe.play.play-functional_2.10-2.2.2-RC1.jar:\
${GRAYLOG2_LIB}/com.typesafe.play.play-datacommons_2.10-2.2.2-RC1.jar:\
${GRAYLOG2_LIB}/joda-time.joda-time-2.2.jar:\
${GRAYLOG2_LIB}/org.joda.joda-convert-1.3.1.jar:\
${GRAYLOG2_LIB}/com.fasterxml.jackson.core.jackson-annotations-2.2.2.jar:\
${GRAYLOG2_LIB}/com.fasterxml.jackson.core.jackson-core-2.2.2.jar:\
${GRAYLOG2_LIB}/com.fasterxml.jackson.core.jackson-databind-2.2.2.jar:\
${GRAYLOG2_LIB}/org.scala-lang.scala-reflect-2.10.3.jar:\
${GRAYLOG2_LIB}/io.netty.netty-3.7.0.Final.jar:\
${GRAYLOG2_LIB}/com.typesafe.netty.netty-http-pipelining-1.1.2.jar:\
${GRAYLOG2_LIB}/org.slf4j.slf4j-api-1.7.5.jar:\
${GRAYLOG2_LIB}/org.slf4j.jul-to-slf4j-1.7.5.jar:\
${GRAYLOG2_LIB}/org.slf4j.jcl-over-slf4j-1.7.5.jar:\
${GRAYLOG2_LIB}/ch.qos.logback.logback-core-1.0.13.jar:\
${GRAYLOG2_LIB}/ch.qos.logback.logback-classic-1.0.13.jar:\
${GRAYLOG2_LIB}/com.typesafe.akka.akka-actor_2.10-2.2.0.jar:\
${GRAYLOG2_LIB}/com.typesafe.akka.akka-slf4j_2.10-2.2.0.jar:\
${GRAYLOG2_LIB}/org.apache.commons.commons-lang3-3.1.jar:\
${GRAYLOG2_LIB}/com.ning.async-http-client-1.7.18.jar:\
${GRAYLOG2_LIB}/oauth.signpost.signpost-core-1.2.1.2.jar:\
${GRAYLOG2_LIB}/commons-codec.commons-codec-1.3.jar:\
${GRAYLOG2_LIB}/oauth.signpost.signpost-commonshttp4-1.2.1.2.jar:\
${GRAYLOG2_LIB}/org.apache.httpcomponents.httpcore-4.0.1.jar:\
${GRAYLOG2_LIB}/org.apache.httpcomponents.httpclient-4.0.1.jar:\
${GRAYLOG2_LIB}/commons-logging.commons-logging-1.1.1.jar:\
${GRAYLOG2_LIB}/xerces.xercesImpl-2.11.0.jar:\
${GRAYLOG2_LIB}/xml-apis.xml-apis-1.4.01.jar:\
${GRAYLOG2_LIB}/javax.transaction.jta-1.1.jar:\
${GRAYLOG2_LIB}/com.typesafe.play.play-java_2.10-2.2.2-RC1.jar:\
${GRAYLOG2_LIB}/org.yaml.snakeyaml-1.12.jar:\
${GRAYLOG2_LIB}/org.hibernate.hibernate-validator-5.0.1.Final.jar:\
${GRAYLOG2_LIB}/javax.validation.validation-api-1.1.0.Final.jar:\
${GRAYLOG2_LIB}/org.jboss.logging.jboss-logging-3.1.1.GA.jar:\
${GRAYLOG2_LIB}/com.fasterxml.classmate-0.8.0.jar:\
${GRAYLOG2_LIB}/org.springframework.spring-context-3.2.3.RELEASE.jar:\
${GRAYLOG2_LIB}/org.springframework.spring-core-3.2.3.RELEASE.jar:\
${GRAYLOG2_LIB}/org.springframework.spring-beans-3.2.3.RELEASE.jar:\
${GRAYLOG2_LIB}/org.reflections.reflections-0.9.8.jar:\
${GRAYLOG2_LIB}/dom4j.dom4j-1.6.1.jar:\
${GRAYLOG2_LIB}/com.google.guava.guava-14.0.1.jar:\
${GRAYLOG2_LIB}/com.google.code.findbugs.jsr305-2.0.1.jar:\
${GRAYLOG2_LIB}/javax.servlet.javax.servlet-api-3.0.1.jar:\
${GRAYLOG2_LIB}/com.typesafe.play.play-cache_2.10-2.2.2-RC1.jar:\
${GRAYLOG2_LIB}/net.sf.ehcache.ehcache-core-2.6.6.jar:\
${GRAYLOG2_LIB}/com.typesafe.play.play-java-jdbc_2.10-2.2.2-RC1.jar:\
${GRAYLOG2_LIB}/com.typesafe.play.play-jdbc_2.10-2.2.2-RC1.jar:\
${GRAYLOG2_LIB}/com.jolbox.bonecp-0.8.0.RELEASE.jar:\
${GRAYLOG2_LIB}/com.h2database.h2-1.3.172.jar:\
${GRAYLOG2_LIB}/tyrex.tyrex-1.0.1.jar:\
${GRAYLOG2_LIB}/com.typesafe.play.play-java-ebean_2.10-2.2.2-RC1.jar:\
${GRAYLOG2_LIB}/org.avaje.ebeanorm.avaje-ebeanorm-3.2.2.jar:\
${GRAYLOG2_LIB}/org.avaje.ebeanorm.avaje-ebeanorm-agent-3.2.1.jar:\
${GRAYLOG2_LIB}/org.hibernate.javax.persistence.hibernate-jpa-2.0-api-1.0.1.Final.jar:\
${GRAYLOG2_LIB}/com.google.code.gson.gson-2.2.jar:\
${GRAYLOG2_LIB}/org.apache.shiro.shiro-core-1.2.2.jar:\
${GRAYLOG2_LIB}/commons-beanutils.commons-beanutils-1.8.3.jar:\
${GRAYLOG2_LIB}/com.google.inject.guice-3.0.jar:\
${GRAYLOG2_LIB}/javax.inject.javax.inject-1.jar:\
${GRAYLOG2_LIB}/aopalliance.aopalliance-1.0.jar:\
${GRAYLOG2_LIB}/org.sonatype.sisu.inject.cglib-2.2.1-v20090111.jar:\
${GRAYLOG2_LIB}/asm.asm-3.1.jar:\
${GRAYLOG2_LIB}/com.google.inject.extensions.guice-assistedinject-3.0.jar:\
${GRAYLOG2_LIB}/org.graylog2.play2-graylog2_2.10-1.0.jar:\
${GRAYLOG2_LIB}/com.sun.jersey.jersey-server-1.17.1.jar:\
${GRAYLOG2_LIB}/com.sun.jersey.jersey-grizzly2-1.17.1.jar:\
${GRAYLOG2_LIB}/org.glassfish.grizzly.grizzly-http-2.2.16.jar:\
${GRAYLOG2_LIB}/org.glassfish.grizzly.grizzly-framework-2.2.16.jar:\
${GRAYLOG2_LIB}/org.glassfish.grizzly.grizzly-http-server-2.2.16.jar:\
${GRAYLOG2_LIB}/org.glassfish.grizzly.grizzly-rcm-2.2.16.jar:\
${GRAYLOG2_LIB}/com.sun.jersey.jersey-bundle-1.17.1.jar:\
${GRAYLOG2_LIB}/javax.ws.rs.jsr311-api-1.1.1.jar\
"
java_options="-Xms${graylog2_web_min_mem} \
-Xmx${graylog2_web_max_mem} \
-Xss256k \
-XX:MaxPermSize=${graylog2_web_perm_mem} \
-XX:ReservedCodeCacheSize=128m \
-Duser.dir=${graylog2_web_home} \
-Dconfig.file=${graylog2_web_config} \
-Dpidfile.path=${pidfile} \
-Dhttp.port=${graylog2_web_port} \
-Dhttp.address=${graylog2_web_addr} \
-Dlogger.file=${graylog2_web_logconf} \
-cp ${GRAYLOG2_CLASSPATH}"
extra_commands="status"
start_precmd="graylog2_web_precmd"
status_cmd="graylog2_web_status"
stop_cmd="graylog2_web_stop"
command="/usr/sbin/daemon"
command_args="-f /usr/local/bin/java ${graylog2_web_props} ${java_options} play.core.server.NettyServer"
graylog2_web_precmd() {
piddir=$(dirname $pidfile)
if [ ! -d ${piddir} ]; then
mkdir -p ${piddir}
chown ${graylog2_web_user}:${graylog2_web_group} ${piddir}
fi
}
graylog2_web_stop() {
rc_pid=$(graylog2_web_check_pidfile $pidfile)
if [ -z "$rc_pid" ]; then
[ -n "$rc_fast" ] && return 0
echo "${name} not running? (check $pidfile)."
return 1
fi
echo "Stopping ${name}."
kill ${rc_pid} 2> /dev/null
}
graylog2_web_status() {
rc_pid=$(graylog2_web_check_pidfile $pidfile)
if [ -z "$rc_pid" ]; then
[ -n "$rc_fast" ] && return 0
echo "${name} not running? (check $pidfile)."
return 1
fi
echo "${name} is running as pid ${rc_pid}."
}
graylog2_web_check_pidfile() {
_pidfile=$1
if [ -z "$_pidfile" ]; then
err 3 'USAGE: graylog2_web_check_pidfile pidfile'
fi
if [ ! -f $_pidfile ]; then
debug "pid file ($_pidfile): not readable."
return
fi
read _pid _junk < $_pidfile
if [ -z "$_pid" ]; then
debug "pid file ($_pidfile): no pid in file."
return
fi
if [ -n "`/usr/local/bin/jps -l | grep -e "^$_pid play.core.server.NettyServer\$"`" ]; then
echo -n $_pid
fi
}
load_rc_config ${name}
run_rc_command "$1"
<configuration>
<!--
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date %-5level [%thread] - [%logger]- %msg%n</pattern>
</encoder>
</appender>
-->
<appender name="ROLLING_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/var/log/graylog2/graylog2-web.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>/var/log/graylog2/graylog2-web.log.%d{yyyy-MM-dd}.%i.log.gz</FileNamePattern>
<MaxHistory>30</MaxHistory>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%date [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<!--<appender-ref ref="STDOUT" />-->
<appender-ref ref="ROLLING_FILE" />
</root>
</configuration>
@girgen
Copy link

girgen commented Oct 12, 2016

Hi, do you have suggestions for installing Graylog 2.1.0 on FreeBSD as well? Seems a bit hariy from the docs, haven't had the time to try it out yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment