Date: Mon, 1 Apr 2019 04:18:26 +0700 From: Eugene Grosbein <eugen@grosbein.net> To: Jim Trigg <jktrigg@gmail.com>, freebsd-ports@freebsd.org Subject: Re: rc script problems Message-ID: <9db4328c-4b2c-c279-0a82-891b7350f035@grosbein.net> In-Reply-To: <67a15aa3-d506-a2ba-137d-7d8a21bdcd3f@gmail.com> References: <67a15aa3-d506-a2ba-137d-7d8a21bdcd3f@gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
01.04.2019 3:55, Jim Trigg wrote: > How do I write an rc script to preserve the pid of a child process? The "port" I'm working with (technically a commercial package) has a startup script that launches a java process. I had written a simple rc wrapper around the script but have found it doesn't support stop because the pid captured is the script's pid rather than the java process's pid. Use something like this for startup script "portname.in" for Java-based long running service: #!/bin/sh # # $FreeBSD$ # # PROVIDE: portname # REQUIRE: LOGIN # KEYWORD: shutdown # # Add the following line to /etc/rc.conf to enable `portname': # # portname_enable="YES" . /etc/rc.subr command_interpreter="." command="%%PREFIX%%/bin/java" command_args="-jar portname.jar" name="%%PORTNAME%%" rcvar="${name}_enable" start_cmd="start_cmd" stop_cmd="stop_cmd" pidfile="/var/run/${name}.pid" required_files="%%DATADIR%%/portname.jar" portname_chdir="%%DATADIR%%" eval `JAVAVM_DRYRUN=yes ${command} | fgrep JAVAVM_COMMAND` procname=${JAVAVM_COMMAND} start_cmd() { check_startmsgs && echo "Starting ${name}." cd ${portname_chdir} daemon -u %%USERS%% -f -p ${pidfile} ${command} ${command_args} start } stop_cmd() { check_startmsgs && echo "Stopping ${name}." rc_pid=$(check_pidfile $pidfile $procname) pkill -F ${pidfile} wait_for_pids $rc_pid } load_rc_config ${name} : ${portname_enable="NO"} run_rc_command "$1" #EOF That is, use daemon(8) utility that can act as superviser for java process: start it with needed arguments, write its pid to pidfile etc.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?9db4328c-4b2c-c279-0a82-891b7350f035>