diff --git a/netkernel/attributes/default.rb b/netkernel/attributes/default.rb index 39d5afb..3ae5da5 100644 --- a/netkernel/attributes/default.rb +++ b/netkernel/attributes/default.rb @@ -6,6 +6,9 @@ default[:netkernel][:backend][:address] = "localhost" default[:netkernel][:backend][:port] = 1060 +default[:netkernel][:user] = "netkernel" +default[:netkernel][:log_path] = "/var/log/netkernel" + # PER INSTALL SETTINGS default[:netkernel][:starting_heap] = "128m" default[:netkernel][:max_heap] = "128m" diff --git a/netkernel/metadata.rb b/netkernel/metadata.rb index 9d99a3c..62efbdb 100644 --- a/netkernel/metadata.rb +++ b/netkernel/metadata.rb @@ -4,3 +4,5 @@ description "Installs/Configures netkernel" long_description IO.read(File.join(File.dirname(__FILE__), 'README.rdoc')) version "0.0.2" + +supports 'ubuntu', ">= 11.04" diff --git a/netkernel/recipes/default.rb b/netkernel/recipes/default.rb index 340bbdf..e66e405 100644 --- a/netkernel/recipes/default.rb +++ b/netkernel/recipes/default.rb @@ -80,4 +80,33 @@ mode "0644" owner "root" group "root" -end \ No newline at end of file +end + + +init_script = value_for_platform( + ["centos", "redhat", "suse", "fedora" ] => { + "default" => "/etc/init.d/netkernel" + }, + ["ubuntu", "debian"] => { + "default" => "/etc/init/netkernel.conf" + } +) + +template init_script do + source "init_script.erb" + mode 755 + owner "root" + group "root" +end + +template "/etc/default/netkernel" do + source defaults.erb + mode 644 + owner "root" + group "root" +end + +service "netkernel" do + supports [:restart, :status] + action [:enable, :start] +end diff --git a/netkernel/templates/default/defaults.erb b/netkernel/templates/default/defaults.erb new file mode 100644 index 0000000..a87cd66 --- /dev/null +++ b/netkernel/templates/default/defaults.erb @@ -0,0 +1,15 @@ +INSTALLPATH='<%= node[:netkernel][:install_path] %>' +NK_USER='<%= node[:netkernel][:user] %>' +BACKENDPORT="<%= node[:netkernel][:backend][:port] %>" +LOG_DIR="<%= node[:netkernel][:log_path] %>" + +LIB="$INSTALLPATH/lib" +EXT="$INSTALLPATH/lib/ext" +PROPS="-Djava.endorsed.dirs=$LIB/endorsed -Djava.protocol.handler.pkgs=org.ten60.netkernel.protocolhandler -Djava.awt.headless=false" +SUN_PROPS="-Dsun.net.client.defaultConnectTimeout=20000 -Dsun.net.client.defaultReadTimeout=20000" +PID="-Dten60.pid=1" #Process id must be set when using 'netkernel' daemon +STOP_CMD="http://localhost:$BACKENDPORT/tools/shutdown?action2=force" +POLLURL="http://localhost:$BACKENDPORT" + +read BOOTLOADER_JAR < "$INSTALLPATH/bin/bootjar.cnf" || true +read JVMSETTINGS < "$INSTALLPATH/bin/jvmsettings.cnf" || true \ No newline at end of file diff --git a/netkernel/templates/default/init_script.erb b/netkernel/templates/default/init_script.erb new file mode 100644 index 0000000..5b06ffc --- /dev/null +++ b/netkernel/templates/default/init_script.erb @@ -0,0 +1 @@ +# SYSV init script \ No newline at end of file diff --git a/netkernel/templates/ubuntu/init_script.erb b/netkernel/templates/ubuntu/init_script.erb new file mode 100644 index 0000000..a621a5a --- /dev/null +++ b/netkernel/templates/ubuntu/init_script.erb @@ -0,0 +1,39 @@ +# netkernel +# +# cron is a standard UNIX program that runs user-specified programs at +# periodic scheduled times + +description "NetKernel Application Engine" + +start on runlevel [2345] +stop on runlevel [!2345] + +respawn + +env DEFAULTFILE=/etc/default/netkernel +kill timeout 60 + +pre-start script + . "$DEFAULTFILE" + chown -R $NK_USER $INSTALLPATH || true + chown -R $NK_USER $LOG_DIR || true +end script + +script + . "$DEFAULTFILE" + sudo -u $NK_USER java $JVMSETTINGS $PROP $SUN_PROPS $PID -cp "$BOOTLOADER_JAR" BootLoader "$INSTALLPATH" 2>&1 >/tmp/nk +end script + +post-start script + . "$DEFAULTFILE" + local starttime=`date +"%s"` + while ! wget --tries=1 --timeout=1 --server-response -O - "$POLLURL" 2>&1 | grep -qai " HTTP/1.1 " ; do + sleep 3 + local now=`date +"%s"` + if [ $(($now - 50)) -gt $starttime ]; then + logger $0 "NK did not start in time (50 seconds)... exiting..." + stop + exit 0 + fi + done +end script \ No newline at end of file