Created attachment 163804 [details] Riemann startup script patch Hi, I have an ELK stack running on a fbsd-10.2 (so elasticsearch, kibana and logstash). Tried to add riemann on top of it refuses to start it because it finds another java (procname) process running and exit (1): root@fbsd:~ # service riemann start riemann already running? (pid=74112 604). root@fbsd:~ # ps axwww | grep -E '(74112|604)' 74111 - Is 0:00.00 daemon: /usr/local/logstash/bin/logstash[74112] (daemon) 74112 - S 5:27.99 /usr/local/openjdk7/bin/java -Des.path.data=/var/db/logstash -Xmx1g -Xss2048k -Djffi.boot.library.path=/usr/local/logstash/vendor/jruby/lib/jni -Des.path.data=/var/db/logstash -Xbootclasspath/a:/usr/local/logstash/vendor/jruby/lib/jruby.jar -classpath : -Djruby.home=/usr/local/logstash/vendor/jruby -Djruby.lib=/usr/local/logstash/vendor/jruby/lib -Djruby.script=jruby -Djruby.shell=/bin/sh org.jruby.Main --1.9 /usr/local/logstash/lib/bootstrap/environment.rb logstash/runner.rb agent -f /usr/local/etc/logstash/logstash.conf --log /var/log/logstash.log 604 u0- I 16:32.84 /usr/local/openjdk7/bin/java -Des.path.conf=/usr/local/etc/elasticsearch -Des.path.scripts=/usr/local/libexec/elasticsearch -Xms256m -Xmx1g -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:+DisableExplicitGC -Dfile.encoding=UTF-8 -Djna.nosys=true -Des.path.home=/usr/local/lib/elasticsearch -cp /usr/local/lib/elasticsearch/lib/elasticsearch-2.1.0.jar:/usr/local/lib/elasticsearch/lib/* org.elasticsearch.bootstrap.Elasticsearch start -d --pidfile=/var/run/elasticsearch.pid So I patched the startup script with the attached patch to make it work (it uses jps).
Comment on attachment 163804 [details] Riemann startup script patch >diff -ruh riemann.orig/files/riemann.in riemann/files/riemann.in >--- riemann.orig/files/riemann.in 2015-02-27 14:35:09.000000000 -0500 >+++ riemann/files/riemann.in 2015-12-03 03:36:46.418837000 -0500 >@@ -28,11 +28,11 @@ > load_rc_config $name > > : ${riemann_enable="NO"} >-: ${riemann_user:="%%RIEMANN_USER%%"} >-: ${riemann_group:="%%RIEMANN_GROUP%%"} >-: ${riemann_config:="%%PREFIX%%/etc/riemann/riemann.config.sample"} >-: ${riemann_jarfile:="%%JAVAJARDIR%%/riemann.jar"} >-: ${riemann_java_home:="%%JAVA_HOME%%"} >+: ${riemann_user:="riemann"} >+: ${riemann_group:="riemann"} >+: ${riemann_config:="/usr/local/etc/riemann/riemann.config.sample"} >+: ${riemann_jarfile:="/usr/local/share/java/classes/riemann.jar"} >+: ${riemann_java_home:="/usr/local/openjdk7"} > : ${riemann_min_mem:="256m"} > : ${riemann_max_mem:="1g"} > : ${riemann_java_opts:=" -server \ >@@ -53,12 +53,15 @@ > -XX:+UseParNewGC \ > -XX:CMSInitiatingOccupancyFraction=75 "} > >-riemann_pidfile="%%RIEMANN_PIDDIR%%${name}.pid" >+riemann_pidfile="/var/run/riemann/${name}.pid" > command="/usr/sbin/daemon" > procname="${riemann_java_home}/bin/java" > command_args="-f -c -p ${riemann_pidfile} ${procname} ${riemann_java_opts} \ > -jar ${riemann_jarfile} ${riemann_config}" > required_files="${java_cmd} ${riemann_config}" >+status_cmd="riemann_status" >+start_cmd="riemann_start" >+stop_cmd="riemann_stop" > > riemann_prestart() > { >@@ -66,4 +69,72 @@ > } > start_precmd=${name}_prestart > >+riemann_start() >+{ >+ check_if_running=$(/usr/local/bin/jps | grep ${name} | awk '{print $1}') >+ if [ ! -z "${check_if_running}" ]; then >+ echo "${name} seems running (pid: ${check_if_running})." >+ return 1 >+ fi >+ >+ rc_pid=$(riemann_check_pidfile $riemann_pidfile) >+ if [ -z "$rc_pid" ]; then >+ echo "Starting ${name}." >+ ${command} ${command_args} >+ else >+ echo "${name} seems running ($rc_pid)." >+ return 1 >+ fi >+ >+} >+ >+riemann_status() >+{ >+ rc_pid=$(riemann_check_pidfile $riemann_pidfile) >+ >+ if [ -z "$rc_pid" ]; then >+ [ -n "$rc_fast" ] && return 0 >+ echo "${name} not running? (check $riemann_pidfile)." >+ return 1 >+ fi >+ echo "${name} is running as pid ${rc_pid}." >+} >+ >+riemann_check_pidfile() >+{ >+ _pidfile=$1 >+ if [ -z "$_pidfile" ]; then >+ err 3 'USAGE: riemann_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"`" ]; then >+ echo -n $_pid >+ fi >+} >+ >+riemann_stop() >+{ >+ rc_pid=$(riemann_check_pidfile $riemann_pidfile) >+ >+ if [ -z "$rc_pid" ]; then >+ [ -n "$rc_fast" ] && return 0 >+ echo "${name} not running? (check $riemann_pidfile)." >+ return 1 >+ fi >+ >+ echo "Stopping ${name}." >+ kill ${rc_pid} 2> /dev/null >+} >+ >+ >+ >+ > run_rc_command "$1"
Created attachment 163807 [details] riemann.in patch
ping
Well, nevermind.
Thanks for supplying the patch & adding the issue. I've taken a look at your patch and was comparing it to the tomcat one https://github.com/freebsd/freebsd-ports/blob/master/www/tomcat6/files/tomcat6.in , did you base it off a specific port or is this from scratch? AFAICT jps is bundled in openjdk, even though it's not explicitly part of the pkg-list. I filed #204989 for that.
Maintainer is active actually, so re-open.
@Dave Do you approve attachment 163807 [details] or do you have alternative instructions on how to proceed to resolution?
The patch doesn't work consistently with jps so I'm fiddling with alternatives. I've tried a jsvc approach like tomcat but its not quite working yet :/.
So not approved, for now, yes?
jsvc requires code changes to riemann, so that's a no-go either atm.
I see why /usr/local/bin/jps (that is a symlink to /usr/local/bin/javavm in the case of openjdk) is not a good approach: there is a sysutils/jps project that installs a /usr/local/bin/jps and that's bad.
Created attachment 165624 [details] use daemon and rc.subr better This came from a couple of good suggestions from @hirojin, traded in kind for miso soup. David - here's a link to the updated /usr/local/etc/rc.d/riemann script, you can just drop this in instead of needing to build the port from source if you want to check it -- I know you're not using riemann any more so no problem if you can't. I used `lien repl` here as a duplicate and that was sufficient. # checks - portlint -C is ok - poudriere is ok # diff https://github.com/dch/freebsd-ports/commit/9f006ed
Created attachment 165625 [details] attach the correct patch :/ # changes PR: 204988 Submitted by: Dave Cottlehuber <dch@skunkwerks.at> (maintainer) Assisted by: Igor Galić <i.galic@brainsware.org> - use a simple pidfile instead of a whole piddir - add a -Dapp=riemann parameter to java invocation so ps | grep can find riemann easily - remove procname and rely on daemon to handle this - use daemon's pid and not riemanns' pid (-P parent flag change) - add daemon's -r restart flag to keep java running at all costs # checks - poudriere OK (10.2 amd64) - portlint -C OK - start, kill -9, status, stop, start of riemann while running `lein repl` suggests we got this fixed now :-) # questions I changed SUB_LIST to include the pidfile (RIEMANN_PIDFILE=${RIEMANN_PIDFILE} ) The pidfile is not listed in pkg-list either.
David: built version of /usr/local/etc/riemann if needed https://dpaste.de/v5qT
Like the -Dapp.name. This should be propagated to all other java apps, imho. Thanks, d.
Testbuilds@work
Testbuilds are fine.
A commit references this bug: Author: pi Date: Sat Feb 6 17:10:58 UTC 2016 New revision: 408306 URL: https://svnweb.freebsd.org/changeset/ports/408306 Log: net-mgmt/riemann: fix startup script - use a simple pidfile instead of a whole piddir - add a -Dapp=riemann parameter to java invocation so ps | grep can find riemann easily - remove procname and rely on daemon to handle this - use daemon's pid and not riemanns' pid (-P parent flag change) - add daemon's -r restart flag to keep java running at all costs PR: 204988 Submitted by: David D'Amico <davide.damico@gmail.com> Approved by: Dave Cottlehuber <dch@skunkwerks.at> (maintainer) Changes: head/net-mgmt/riemann/Makefile head/net-mgmt/riemann/files/riemann.in head/net-mgmt/riemann/pkg-plist
Committed, thanks.