bcaf [Solved] rc.d Script for a program which need long time to close gracefully - The FreeBSD Forums
The FreeBSD Forums  

Go Back   The FreeBSD Forums > Development > Userland Programming & Scripting

Userland Programming & Scripting C, Shell, Perl, Sed & Awk

Reply
 
Thread Tools Display Modes
  #1  
Old March 29th, 2012, 00:02
freebuser freebuser is offline
Junior Member
 
Join Date: Feb 2012
Posts: 38
Thanks: 8
Thanked 1 Time in 1 Post
Default rc.d Script for a program which need long time to close gracefully

Hi,

I have recently migrated from Debian Wheezy to FreeBSD 9.0 Release. One of the programs I use is OpenKM which is a jboss based document management system. I was able to create an rc.d script to start this program on system startup and close the program on system shutdown. Startup works fine as there is no time limit on how long the program can take to start. But on shutdown the program couldn't close properly as the system shutdown is too fast.

I have included
Code:
# PROVIDES: Sopenkm java
# KEYWORD: shutdown
in rc.d script but no difference in the results.

Is there anything more I need to do to give the program enough time to close properly before the system shutdown?

Thanks heaps,

Last edited by phoenix; July 27th, 2012 at 07:11. Reason: spelling nits
Reply With Quote
  #2  
Old March 29th, 2012, 00:06
freebuser freebuser is offline
Junior Member
 
Join Date: Feb 2012
Posts: 38
Thanks: 8
Thanked 1 Time in 1 Post
Default

Complete : script
Code:
#!/bin/sh
# Sopenkm startup Script

# PROVIDE: Sopenkm java
# KEYWORD: shutdown

. /etc/rc.subr

name="Sopenkm"
rcvar=${name}_enable
Sopenkm_enable=${Sopenkm_enable-"NO"}

start_cmd="${name}_start"
stop_cmd="${name}_stop"

load_rc_config $name

JAVA_HOME="/usr/local/openjdk6/";

export JAVA_HOME

Sopenkm_start(){
echo "Starting OpenKM....."
rm -r /mydata/jboss/server/default/work & rm -r /mydata/jboss/server/default/tmp & /usr/local/lib/libreoffice/program/soffice "-accept=socket,host=localhost,port=2222;urp;StarOffice.ServiceManager" -nologo -headless -nofirststartwizard & /mydata/jboss/bin/run.sh -b 0.0.0.0 &

}

Sopenkm_stop(){

echo "Stopping OpenKM....."
/mydata/jboss/bin/shutdown.sh -S
killall -9 soffice.bin &
}


run_rc_command "$1"
Cheers,

Last edited by DutchDaemon; March 29th, 2012 at 00:19.
Reply With Quote
  #3  
Old April 1st, 2012, 11:22
samu samu is offline
Junior Member
 
Join Date: Aug 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think that doing killall -9 soffice.bin & can be the issue. You are sending a SIGKILL to the processes and detaching, so that the rest of shutdown goes on.

I'm not sure if I understand it correctly, but if you use SIGKILL, it will not be given a chance to shutdown properly (if shutdown.sh didn't finish). Use a SIGTERM instead (if the software can catch it and perform a clean shutdown by itself). If I'm wrong, somebody please correct me.

Last edited by DutchDaemon; April 1st, 2012 at 20:37. Reason: Proper formatting: http://forums.freebsd.org/showthread.php?t=8816
Reply With Quote
  #4  
Old July 27th, 2012, 02:05
freebuser freebuser is offline
Junior Member
 
Join Date: Feb 2012
Posts: 38
Thanks: 8
Thanked 1 Time in 1 Post
Default

The reason the script didn't shutdown properly was the java process is the one which actually started by the script not Openkm.

So adding
Code:
procname="java"
solved the problem.

My new script looks like this:
Code:
#!/bin/sh
# Openkm startup Script

# PROVIDE: Openkm
# REQUIRE: mysql LOGIN
# KEYWORD: shutdown

. /etc/rc.subr

name="Openkm"
rcvar=${name}_enable
Openkm_enable=${Openkm_enable-"NO"}

start_cmd="${name}_start"
stop_cmd="${name}_stop"

load_rc_config $name

JAVA_HOME="/usr/local/openjdk6/";

export JAVA_HOME

procname="java"

Openkm_start(){
echo "Starting OpenKM....."
rm -r /alldata/programs/jboss/server/default/work &
rm -r /alldata/programs/jboss/server/default/tmp &
/usr/local/lib/libreoffice/program/soffice "--accept=socket,host=localhost,port=2222;urp;StarOffice.ServiceManager" --nologo --headless --nofirststartwizard &
su -m nobody -c /alldata/programs/jboss/bin/run.sh -b 0.0.0.0 & > /dev/null

}

Openkm_stop(){

echo "Stopping OpenKM....."
/alldata/programs/jboss/bin/shutdown.sh -S
killall -9 soffice.bin &
}


run_rc_command "$1"
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ZFS: nfs mountd 100% CPU for very long time Leroy_van_Logchem Storage 1 February 23rd, 2012 15:05
[Solved] yet another crontab question - what about program that takes long time? ivand58 General 4 July 31st, 2011 01:18
[Solved] Installing KDE, taking a LONG time sysop1911 Installation and Maintenance of FreeBSD Ports or Packages 5 July 27th, 2011 19:05
[Solved] why so long time needed? pkhtut Installing & Upgrading 12 October 22nd, 2009 08:18
sshd take long time to start mfaridi Web & Network Services 4 April 26th, 2009 19:05


All times are GMT +1. The time now is 21:11.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
The mark FreeBSD is a registered trademark of The FreeBSD Foundation and is used by The FreeBSD Project with the permission of The FreeBSD Foundation.
Web protection and acceleration provided by CloudFlare
0