Skip to content

Commit

Permalink
Initial stake on #3
Browse files Browse the repository at this point in the history
  • Loading branch information
jhulten committed Dec 8, 2011
1 parent 0bf8ba2 commit 1d3e869
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 1 deletion.
3 changes: 3 additions & 0 deletions netkernel/attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions netkernel/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
31 changes: 30 additions & 1 deletion netkernel/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,33 @@
mode "0644"
owner "root"
group "root"
end
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
15 changes: 15 additions & 0 deletions netkernel/templates/default/defaults.erb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions netkernel/templates/default/init_script.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# SYSV init script
39 changes: 39 additions & 0 deletions netkernel/templates/ubuntu/init_script.erb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1d3e869

Please sign in to comment.