openHAB install after windows service feature install

This commit is contained in:
2019-11-08 16:28:55 -06:00
commit 6a5b2422b6
973 changed files with 22607 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Karaf Service
#
KARAF_SERVICE_PATH="${KARAF_SERVICE_PATH}"
KARAF_SERVICE_NAME="${KARAF_SERVICE_NAME}"
KARAF_SERVICE_LOG="${KARAF_SERVICE_LOG}"
KARAF_SERVICE_USER="${KARAF_SERVICE_USER}"
KARAF_SERVICE_GROUP="${KARAF_SERVICE_GROUP}"
KARAF_LOCKFILE="/var/lock/subsys/$KARAF_SERVICE_NAME"
KARAF_SERVICE_PIDFILE="${KARAF_SERVICE_PIDFILE}"
KARAF_SERVICE_EXECUTABLE="${KARAF_SERVICE_EXECUTABLE}"
#
# Karaf
#
#
# User
#

View File

@@ -0,0 +1,171 @@
#!/bin/sh
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Karaf control script
# description: Karaf startup script
# processname: ${KARAF_SERVICE_NAME}
# pidfile: ${KARAF_SERVICE_PIDFILE}
# config: ${KARAF_SERVICE_CONF}
#
if [ -r "${KARAF_SERVICE_CONF}" ]; then
. "${KARAF_SERVICE_CONF}"
else
echo "Error KARAF_SERVICE_CONF not defined"
exit -1
fi
# Location of JDK
if [ -n "$JAVA_HOME" ]; then
export JAVA_HOME
fi
# Setup the JVM
if [ -z "$JAVA" ]; then
if [ -n "$JAVA_HOME" ]; then
JAVA="$JAVA_HOME/bin/java"
else
JAVA="java"
fi
fi
if [ -z "$STARTUP_WAIT" ]; then
STARTUP_WAIT=30
fi
if [ -z "$SHUTDOWN_WAIT" ]; then
SHUTDOWN_WAIT=30
fi
prog=${KARAF_SERVICE_NAME}
do_start() {
echo "Starting $prog: "
if [ -f "$KARAF_SERVICE_PIDFILE" ]; then
read ppid < "$KARAF_SERVICE_PIDFILE"
if [ `ps -p $ppid 2> /dev/null | grep -c $ppid 2> /dev/null` -eq '1' ]; then
echo "$prog is already running"
return 1
else
rm -f "$KARAF_SERVICE_PIDFILE"
fi
fi
LOG_PATH=`dirname "$KARAF_SERVICE_LOG"`
mkdir -p "$LOG_PATH"
cat /dev/null > "$KARAF_SERVICE_LOG"
chown $KARAF_SERVICE_USER:$KARAF_SERVICE_GROUP "$KARAF_SERVICE_LOG"
PID_PATH=`dirname "$KARAF_SERVICE_PIDFILE"`
mkdir -p "$PID_PATH"
chown $KARAF_SERVICE_USER:$KARAF_SERVICE_GROUP "$PID_PATH" || true
if [ ! -z "$KARAF_SERVICE_USER" ]; then
if [ "$KARAF_SERVICE_USER" = "root" ]; then
KARAF_EXEC=exec
export KARAF_EXEC
JAVA_HOME=$JAVA_HOME
export JAVA_HOME
"$KARAF_SERVICE_PATH/bin/$KARAF_SERVICE_EXECUTABLE" daemon >> "$KARAF_SERVICE_LOG" 2>&1 &
echo $! > "$KARAF_SERVICE_PIDFILE"
else
su - $KARAF_SERVICE_USER \
-c " { export KARAF_EXEC=exec; export JAVA_HOME=$JAVA_HOME; \"$KARAF_SERVICE_PATH/bin/$KARAF_SERVICE_EXECUTABLE\" daemon >> \"$KARAF_SERVICE_LOG\" 2>&1 & } ; echo \$! >| \"$KARAF_SERVICE_PIDFILE\" "
fi
sleep 1
if [ -f "$KARAF_SERVICE_PIDFILE" ]; then
chown $KARAF_SERVICE_USER:$KARAF_SERVICE_GROUP "$KARAF_SERVICE_PIDFILE"
fi
fi
RETVAL=$?
return $RETVAL
}
do_stop() {
echo $"Stopping $prog: "
count=0;
if [ -f "$KARAF_SERVICE_PIDFILE" ]; then
read kpid < "$KARAF_SERVICE_PIDFILE"
kwait=$SHUTDOWN_WAIT
if [ "$KARAF_SERVICE_USER" = "root" ]; then
JAVA_HOME=$JAVA_HOME
export JAVA_HOME
"$KARAF_SERVICE_PATH/bin/$KARAF_SERVICE_EXECUTABLE" stop >> "$KARAF_SERVICE_LOG" 2>&1
else
su - $KARAF_SERVICE_USER \
-c "export JAVA_HOME=$JAVA_HOME; \"$KARAF_SERVICE_PATH/bin/$KARAF_SERVICE_EXECUTABLE\" stop >> \"$KARAF_SERVICE_LOG\" 2>&1"
fi
until [ `ps -p $kpid 2> /dev/null | grep -c $kpid 2> /dev/null` -eq '0' ] || [ $count -gt $kwait ]
do
sleep 1
count=`expr $count + 1`
done
if [ $count -gt $kwait ]; then
if [ `ps -p $kpid 2> /dev/null | grep -c $kpid 2> /dev/null` -eq '1' ]; then
kill -9 $kpid
fi
fi
fi
rm -f "$KARAF_SERVICE_PIDFILE"
rm -f $KARAF_LOCKFILE
}
do_status() {
if [ -f "$KARAF_SERVICE_PIDFILE" ]; then
read ppid < "$KARAF_SERVICE_PIDFILE"
if [ `ps -p $ppid 2> /dev/null | grep -c $ppid 2> /dev/null` -eq '1' ]; then
echo "$prog is running (pid $ppid)"
return 0
else
echo "$prog dead but pid file exists"
return 1
fi
fi
echo "$prog is not running"
return 3
}
case "$1" in
start)
do_start
;;
stop)
do_stop
;;
restart)
do_stop
do_start
;;
status)
do_status
;;
*)
## If no parameters are given, print which are avaiable.
echo "Usage: $0 {start|stop|status|restart}"
exit 1
;;
esac

View File

@@ -0,0 +1,246 @@
#!/bin/sh
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# /etc/init.d/${KARAF_SERVICE_NAME} -- startup script for Karaf
#
#
### BEGIN INIT INFO
# Provides: ${KARAF_SERVICE_NAME}
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs $network
# Should-Start: $named
# Should-Stop: $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Karaf
# Description: Provide Karaf startup/shutdown script
### END INIT INFO
NAME=${KARAF_SERVICE_NAME}
DESC=${KARAF_SERVICE_NAME}
DEFAULT="/etc/default/$NAME"
# Check privileges
if [ `id -u` -ne 0 ]; then
echo "You need root privileges to run this script"
exit 1
fi
# Make sure karaf is started with system locale
if [ -r /etc/default/locale ]; then
. /etc/default/locale
export LANG
fi
. /lib/lsb/init-functions
if [ -r /etc/default/rcS ]; then
. /etc/default/rcS
fi
# Overwrite settings from default file
if [ -f "$DEFAULT" ]; then
. "$DEFAULT"
fi
if [ -r "${KARAF_SERVICE_CONF}" ]; then
. "${KARAF_SERVICE_CONF}"
else
echo "Error KARAF_SERVICE_CONF not defined"
exit -1
fi
# Location of JDK
if [ -n "$JAVA_HOME" ]; then
export JAVA_HOME
fi
# Setup the JVM
if [ -z "$JAVA" ]; then
if [ -n "$JAVA_HOME" ]; then
JAVA="$JAVA_HOME/bin/java"
else
JAVA="java"
fi
fi
# Check karaf user
id $KARAF_SERVICE_USER > /dev/null 2>&1
if [ $? -ne 0 -o -z "$KARAF_SERVICE_USER" ]; then
echo "User \"$KARAF_SERVICE_USER\" does not exist..." >&2
exit 1
fi
# Check owner of KARAF_SERVICE_PATH
if [ ! $(stat -L -c "%U" "$KARAF_SERVICE_PATH") = $KARAF_SERVICE_USER ]; then
echo "The user \"$KARAF_SERVICE_USER\" is not owner of \"$KARAF_SERVICE_PATH\"" >&2
exit 1
fi
# The amount of time to wait for startup
if [ -z "$STARTUP_WAIT" ]; then
STARTUP_WAIT=30
fi
# The amount of time to wait for shutdown
if [ -z "$SHUTDOWN_WAIT" ]; then
SHUTDOWN_WAIT=30
fi
# Helper function to check status of karaf service
check_status() {
pidofproc -p "$KARAF_SERVICE_PIDFILE" "$JAVA" >/dev/null 2>&1
}
case "$1" in
start)
echo "Starting $DESC" "$NAME"
# PID file
PID_PATH=$(dirname "$KARAF_SERVICE_PIDFILE")
if [ ! -d "$PID_PATH" ]; then
mkdir -p "$PID_PATH"
fi
chown $KARAF_SERVICE_USER:$KARAF_SERVICE_GROUP "$PID_PATH" || true
# Console log
LOG_PATH=$(dirname "$KARAF_SERVICE_LOG")
if [ ! -d "$LOG_PATH" ]; then
mkdir -p "$LOG_PATH"
fi
cat /dev/null > "$KARAF_SERVICE_LOG"
chown $KARAF_SERVICE_USER:$KARAF_SERVICE_GROUP "$LOG_PATH"
chown $KARAF_SERVICE_USER:$KARAF_SERVICE_GROUP "$KARAF_SERVICE_LOG"
start-stop-daemon \
--start \
--user "$KARAF_SERVICE_USER" \
--chuid "$KARAF_SERVICE_USER" \
--chdir "$KARAF_SERVICE_PATH" \
--pidfile "$KARAF_SERVICE_PIDFILE" \
--make-pidfile \
--exec "$KARAF_SERVICE_PATH/bin/$KARAF_SERVICE_EXECUTABLE" -- "daemon" \
>> "$KARAF_SERVICE_LOG" 2>&1 &
count=0
launched=0
until [ $count -gt $STARTUP_WAIT ]
do
sleep 1
count=$((count + 1));
if check_status; then
launched=1
break
fi
done
if check_status; then
log_end_msg 0
else
log_end_msg 1
fi
if [ $launched -eq 0 ]; then
log_warning_msg "$DESC hasn't started within the timeout allowed"
log_warning_msg "please review file \"$KARAF_SERVICE_LOG\" to see the status of the service"
fi
;;
stop)
check_status
status_stop=$?
if [ $status_stop -eq 0 ]; then
kwait=$SHUTDOWN_WAIT
read kpid < "$KARAF_SERVICE_PIDFILE"
log_daemon_msg "Stopping $DESC" "$NAME"
children_pids=$(pgrep -P $kpid)
su - $KARAF_SERVICE_USER \
-c "export JAVA_HOME=$JAVA_HOME; \"$KARAF_SERVICE_PATH/bin/$KARAF_SERVICE_EXECUTABLE\" stop"
count=0
until [ `ps --pid $kpid 2> /dev/null | grep -c $kpid 2> /dev/null` -eq '0' ] || [ $count -gt $kwait ]
do
sleep 1
count=$((count + 1));
done
if check_status; then
start-stop-daemon \
--stop \
--quiet \
--pidfile "$KARAF_SERVICE_PIDFILE" \
--user "$KARAF_SERVICE_USER" \
--retry=TERM/$SHUTDOWN_WAIT/KILL/5 \
> /dev/null 2>&1
if [ $? -eq 2 ]; then
log_failure_msg "$DESC can't be stopped"
exit 1
fi
fi
for child in $children_pids; do
/bin/kill -9 $child >/dev/null 2>&1
done
log_end_msg 0
rm -rf "$KARAF_SERVICE_PIDFILE"
elif [ $status_stop -eq 1 ]; then
log_action_msg "$DESC is not running but the pid file exists, cleaning up"
rm -f "$KARAF_SERVICE_PIDFILE"
elif [ $status_stop -eq 3 ]; then
log_action_msg "$DESC is not running"
fi
;;
restart)
check_status
status_restart=$?
if [ $status_restart -eq 0 ]; then
$0 stop
fi
$0 start
;;
status)
check_status
status=$?
if [ $status -eq 0 ]; then
read pid < $KARAF_SERVICE_PIDFILE
log_action_msg "$DESC is running with pid $pid"
exit 0
elif [ $status -eq 1 ]; then
log_action_msg "$DESC is not running and the pid file exists"
exit 1
elif [ $status -eq 3 ]; then
log_action_msg "$DESC is not running"
exit 3
else
log_action_msg "Unable to determine $DESC status"
exit 4
fi
;;
*)
log_action_msg "Usage: $0 {start|stop|restart|status}"
exit 2
;;
esac
exit 0

View File

@@ -0,0 +1,164 @@
#!/bin/sh
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Karaf control script
#
# chkconfig: - 80 20
# description: Karaf startup script
# processname: ${KARAF_SERVICE_NAME}
# pidfile: ${KARAF_SERVICE_PIDFILE}
# config: ${KARAF_SERVICE_CONF}
#
# Source function library.
. /etc/init.d/functions
# Load Java configuration.
[ -r /etc/java/java.conf ] && . /etc/java/java.conf
export JAVA_HOME
if [ -r "${KARAF_SERVICE_CONF}" ]; then
. "${KARAF_SERVICE_CONF}"
else
echo "Error KARAF_SERVICE_CONF not defined"
exit -1
fi
if [ -z "$STARTUP_WAIT" ]; then
STARTUP_WAIT=30
fi
if [ -z "$SHUTDOWN_WAIT" ]; then
SHUTDOWN_WAIT=30
fi
prog=${KARAF_SERVICE_NAME}
currenttime=$(date +%s%N | cut -b1-13)
start() {
echo -n "Starting $prog: "
if [ -f "$KARAF_SERVICE_PIDFILE" ]; then
read ppid < "$KARAF_SERVICE_PIDFILE"
if [ `ps --pid $ppid 2> /dev/null | grep -c $ppid 2> /dev/null` -eq '1' ]; then
echo -n "$prog is already running"
failure
echo
return 1
else
rm -f "$KARAF_SERVICE_PIDFILE"
fi
fi
LOG_PATH=`dirname "$KARAF_SERVICE_LOG"`
mkdir -p "$LOG_PATH"
cat /dev/null > "$KARAF_SERVICE_LOG"
chown $KARAF_SERVICE_USER:$KARAF_SERVICE_GROUP "$KARAF_SERVICE_LOG"
PID_PATH=`dirname "$KARAF_SERVICE_PIDFILE"`
mkdir -p "$PID_PATH"
chown $KARAF_SERVICE_USER:$KARAF_SERVICE_GROUP "$PID_PATH" || true
if [ ! -z "$KARAF_SERVICE_USER" ]; then
if [ -r /etc/rc.d/init.d/functions ]; then
daemon \
--user="$KARAF_SERVICE_USER" \
--pidfile="$KARAF_SERVICE_PIDFILE" \
" { \"$KARAF_SERVICE_PATH/bin/$KARAF_SERVICE_EXECUTABLE\" daemon >> \"$KARAF_SERVICE_LOG\" 2>&1 & } ; echo \$! >| \"$KARAF_SERVICE_PIDFILE\" "
else
su - $KARAF_SERVICE_USER \
-c " { \"$KARAF_SERVICE_PATH/bin/$KARAF_SERVICE_EXECUTABLE\" daemon >> \"$KARAF_SERVICE_LOG\" 2>&1 & } ; echo \$! >| \"$KARAF_SERVICE_PIDFILE\" "
fi
if [ -f "$KARAF_SERVICE_PIDFILE" ]; then
chown $KARAF_SERVICE_USER:$KARAF_SERVICE_GROUP "$KARAF_SERVICE_PIDFILE"
fi
fi
RETVAL=$?
echo
if [ $RETVAL -eq 0 ]; then
touch $KARAF_LOCKFILE
fi
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
count=0;
if [ -f "$KARAF_SERVICE_PIDFILE" ]; then
read kpid < "$KARAF_SERVICE_PIDFILE"
let kwait=$SHUTDOWN_WAIT
# Try issuing SIGTERM
su - $KARAF_SERVICE_USER \
-c "export JAVA_HOME=$JAVA_HOME; \"$KARAF_SERVICE_PATH/bin/$KARAF_SERVICE_EXECUTABLE\" stop"
until [ `ps --pid $kpid 2> /dev/null | grep -c $kpid 2> /dev/null` -eq '0' ] || [ $count -gt $kwait ]
do
sleep 1
let count=$count+1;
done
if [ $count -gt $kwait ]; then
kill -9 $kpid
fi
fi
rm -f "$KARAF_SERVICE_PIDFILE"
rm -f "$KARAF_LOCKFILE"
success
echo
}
status() {
if [ -f "$KARAF_SERVICE_PIDFILE" ]; then
read ppid < "$KARAF_SERVICE_PIDFILE"
if [ `ps --pid $ppid 2> /dev/null | grep -c $ppid 2> /dev/null` -eq '1' ]; then
echo "$prog is running (pid $ppid)"
return 0
else
echo "$prog dead but pid file exists"
return 1
fi
fi
echo "$prog is not running"
return 3
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
$0 stop
$0 start
;;
status)
status
;;
*)
## If no parameters are given, print which are avaiable.
echo "Usage: $0 {start|stop|status|restart}"
exit 1
;;
esac

View File

@@ -0,0 +1,94 @@
<?xml version="1.0" ?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!DOCTYPE service_bundle
SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'>
<service_bundle type="manifest" name="application/${KARAF_SERVICE_NAME}">
<service version="1" type="service" name="application/${KARAF_SERVICE_NAME}">
<create_default_instance enabled='false' />
<single_instance />
<dependency
restart_on="none"
type="service"
name="multi_user_dependency"
grouping="require_all">
<service_fmri value="svc:/milestone/multi-user"/>
</dependency>
<method_context>
<method_credential user='${KARAF_SERVICE_USER}' group='${KARAF_SERVICE_GROUP}'/>
<method_environment>
<envvar name="JAVA_HOME" value="${JAVA_HOME}"/>
</method_environment>
</method_context>
<!-- *************************************************************** -->
<!-- STOP/START -->
<!-- *************************************************************** -->
<exec_method
timeout_seconds="60"
type="method"
name="start"
exec="${KARAF_SERVICE_PATH}/bin/${KARAF_SERVICE_EXECUTABLE} daemon &amp;">
</exec_method>
<exec_method
timeout_seconds="60"
type="method"
name="stop"
exec="${KARAF_SERVICE_PATH}/bin/${KARAF_SERVICE_EXECUTABLE} stop">
</exec_method>
<!-- *************************************************************** -->
<!-- -->
<!-- *************************************************************** -->
<!-- do not restart the service in case of errors -->
<property_group name='startd' type='framework'>
<propval name='duration'
type='astring'
value='transient'/>
<propval name='ignore_error'
type='astring'
value='core,signal'/>
</property_group>
<stability value='Evolving' />
<template>
<common_name>
<loctext xml:lang="C">
${KARAF_SERVICE_NAME}
</loctext>
</common_name>
<description>
<loctext xml:lang="C">
${KARAF_SERVICE_NAME}
</loctext>
</description>
</template>
</service>
</service_bundle>

View File

@@ -0,0 +1,39 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
[Unit]
Description=Karaf - ${KARAF_SERVICE_NAME}
After=syslog.target network.target
[Service]
EnvironmentFile=${KARAF_SERVICE_CONF}
ExecStart=${KARAF_SERVICE_PATH}/bin/${KARAF_SERVICE_EXECUTABLE} daemon
ExecStop=${KARAF_SERVICE_PATH}/bin/${KARAF_SERVICE_EXECUTABLE} stop
User=${KARAF_SERVICE_USER}
Group=${KARAF_SERVICE_GROUP}
SuccessExitStatus=0 143
RestartSec=15
Restart=on-failure
LimitNOFILE=102642
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,42 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
[Unit]
Description=Karaf - ${KARAF_SERVICE_NAME} - %i
After=syslog.target network.target
Requires=${KARAF_SERVICE_NAME}.service
[Service]
EnvironmentFile=-${KARAF_SERVICE_PATH}/etc/${KARAF_SERVICE_NAME}-%i.conf
EnvironmentFile=-${KARAF_SERVICE_PATH}/instances/%i/etc/${KARAF_SERVICE_NAME}.conf
Environment=KARAF_HOME=${KARAF_SERVICE_PATH}
Environment=KARAF_BASE=${KARAF_SERVICE_PATH}/instances/%i
ExecStart=${KARAF_SERVICE_PATH}/bin/${KARAF_SERVICE_EXECUTABLE} daemon
ExecStop=${KARAF_SERVICE_PATH}/bin/${KARAF_SERVICE_EXECUTABLE} stop
User=${KARAF_SERVICE_USER}
Group=${KARAF_SERVICE_GROUP}
SuccessExitStatus=0 1 143
RestartSec=15
Restart=on-failure
LimitNOFILE=102642
[Install]
WantedBy=multi-user.target

Binary file not shown.

View File

@@ -0,0 +1,50 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<service>
<!--
This script is provided as a template you can quckly customize by replacing
the following variables:
KARAF_SERVICE_NAME
KARAF_SERVICE_PATH
KARAF_SERVICE_EXECUTABLE
For a detailed overview of the confguration options, please visit winsw home
page (https://github.com/kohsuke/winsw)
-->
<id>%KARAF_SERVICE_NAME%</id>
<name>%KARAF_SERVICE_NAME%</name>
<description>Apache Karaf %KARAF_SERVICE_NAME%</description>
<!-- start -->
<executable>%KARAF_SERVICE_PATH%\bin\%KARAF_SERVICE_EXECUTABLE%</executable>
<startargument>daemon</startargument>
<!-- stop -->
<stopexecutable>%KARAF_SERVICE_PATH%\bin\%KARAF_SERVICE_EXECUTABLE%</stopexecutable>
<stopargument>stop</stopargument>
<stoptimeout>10sec</stoptimeout>
<!-- logging -->
<logpath>%KARAF_SERVICE_PATH%\data\log</logpath>
<log mode="roll-by-time">
<pattern>yyyyMMdd</pattern>
</log>
</service>

View File

@@ -0,0 +1,206 @@
#!/usr/bin/env bash
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
function usage {
cat <<-END >&2
USAGE: $0
-k KARAF_SERVICE_PATH # Karaf installation path
-d KARAF_SERVICE_DATA # Karaf data path (default to \${KARAF_SERVICE_PATH}/data)
-c KARAF_SERVICE_CONF # Karaf configuration file (default to \${KARAF_SERVICE_PATH/etc/\${KARAF_SERVICE_NAME}.conf
-t KARAF_SERVICE_ETC # Karaf etc path (default to \${KARAF_SERVICE_PATH/etc}
-p KARAF_SERVICE_PIDFILE # Karaf pid path (default to \${KARAF_SERVICE_DATA}/\${KARAF_SERVICE_NAME}.pid)
-n KARAF_SERVICE_NAME # Karaf service name (default karaf)
-e KARAF_ENV # Karaf environment variable (can be repeated)
-u KARAF_SERVICE_USER # Karaf user
-g KARAF_SERVICE_GROUP # Karaf group (default \${KARAF_SERVICE_USER)
-l KARAF_SERVICE_LOG # Karaf console log (default to \${KARAF_SERVICE_DATA}/log/\${KARAF_SERVICE_NAME}-console.log)
-f KARAF_SERVICE_TEMPLATE # Template file to use
-x KARAF_SERVICE_EXECUTABLE # Karaf executable name (defaul karaf, should support daemon and stop commands)
-h # this usage message
END
exit
}
CONF_TEMPLATE="karaf-service-template.conf"
SYSTEMD_TEMPLATE="karaf-service-template.systemd"
SYSTEMD_TEMPLATE_INSTANCES="karaf-service-template.systemd-instances"
INIT_TEMPLATE="karaf-service-template.init"
INIT_REDHAT_TEMPLATE="karaf-service-template.init-redhat"
INIT_DEBIAN_TEMPLATE="karaf-service-template.init-debian"
SOLARIS_SMF_TEMPLATE="karaf-service-template.solaris-smf"
################################################################################
#
################################################################################
KARAF_ENV=()
while getopts k:d:c:p:n:u:g:l:t:e:f:x:h opt
do
case $opt in
k) export KARAF_SERVICE_PATH="$OPTARG" ;;
d) export KARAF_SERVICE_DATA="$OPTARG" ;;
c) export KARAF_SERVICE_CONF="$OPTARG" ;;
p) export KARAF_SERVICE_PIDFILE="$OPTARG" ;;
n) export KARAF_SERVICE_NAME="$OPTARG" ;;
u) export KARAF_SERVICE_USER="$OPTARG" ;;
g) export KARAF_SERVICE_GROUP="$OPTARG" ;;
l) export KARAF_SERVICE_LOG="$OPTARG" ;;
t) export KARAF_SERVICE_ETC="$OPTARG" ;;
f) export KARAF_SERVICE_TEMPLATE="$OPTARG" ;;
x) export KARAF_SERVICE_EXECUTABLE="$OPTARG" ;;
e) KARAF_ENV+=("$OPTARG") ;;
h|?) usage ;;
esac
done
shift $(( $OPTIND - 1 ))
if [[ ! $KARAF_SERVICE_PATH ]]; then
echo "Warning, KARAF_SERVICE_PATH is required"
usage
fi
if [[ ! $KARAF_SERVICE_DATA ]]; then
export KARAF_SERVICE_DATA="${KARAF_SERVICE_PATH}/data"
fi
if [[ ! $KARAF_SERVICE_ETC ]]; then
export KARAF_SERVICE_ETC="${KARAF_SERVICE_PATH}/etc"
fi
if [[ ! $KARAF_SERVICE_NAME ]]; then
export KARAF_SERVICE_NAME="karaf"
fi
if [[ ! $KARAF_SERVICE_CONF ]]; then
export KARAF_SERVICE_CONF="${KARAF_SERVICE_PATH}/etc/${KARAF_SERVICE_NAME}.conf"
fi
if [[ ! $KARAF_SERVICE_PIDFILE ]]; then
export KARAF_SERVICE_PIDFILE="${KARAF_SERVICE_DATA}/${KARAF_SERVICE_NAME}.pid"
fi
if [[ ! $KARAF_SERVICE_LOG ]]; then
export KARAF_SERVICE_LOG="${KARAF_SERVICE_DATA}/log/${KARAF_SERVICE_NAME}-console.log"
fi
if [[ ! $KARAF_SERVICE_USER ]]; then
export KARAF_SERVICE_USER="root"
fi
if [[ ! $KARAF_SERVICE_GROUP ]]; then
export KARAF_SERVICE_GROUP="${KARAF_SERVICE_USER}"
fi
if [[ ! $KARAF_SERVICE_EXECUTABLE ]]; then
export KARAF_SERVICE_EXECUTABLE="karaf"
fi
################################################################################
#
################################################################################
function generate_service_descriptor {
echo "Writing service file \"$2\""
perl -p -e 's/\$\{([^}]+)\}/defined $ENV{$1} ? $ENV{$1} : $&/eg' < "$1" > "$2"
if [ $# -eq 4 ]; then
echo "Writing service configuration file \"$4\""
perl -p -e 's/\$\{([^}]+)\}/defined $ENV{$1} ? $ENV{$1} : $&/eg' < "$3" > "$4"
for var in "${KARAF_ENV[@]}"; do
echo "${var}" >> "$4"
done
fi
}
################################################################################
#
################################################################################
if [[ ! $KARAF_SERVICE_TEMPLATE ]]; then
case $(uname | tr [:upper:] [:lower:]) in
sunos)
# add KARAF_ENV vars to envirioment
for var in "${KARAF_ENV[@]}"; do
export $var
done
# Default java path if not set
if [[ ! $JAVA_HOME ]]; then
export JAVA_HOME=/usr/java
fi
# escape spaces in path
export KARAF_SERVICE_PATH="$(echo $KARAF_SERVICE_PATH | sed 's/ /\\ /g')"
export KARAF_SERVICE_DATA="$(echo $KARAF_SERVICE_DATA | sed 's/ /\\ /g')"
export KARAF_SERVICE_CONF="$(echo $KARAF_SERVICE_CONF | sed 's/ /\\ /g')"
export KARAF_SERVICE_PIDFILE="$(echo $KARAF_SERVICE_PIDFILE | sed 's/ /\\ /g')"
generate_service_descriptor \
"$SOLARIS_SMF_TEMPLATE" \
"${PWD}/${KARAF_SERVICE_NAME}.xml"
;;
linux)
if [ -d /run/systemd/system ]; then
generate_service_descriptor \
"$SYSTEMD_TEMPLATE" \
"${PWD}/${KARAF_SERVICE_NAME}.service" \
"${CONF_TEMPLATE}" \
"${KARAF_SERVICE_CONF}"
generate_service_descriptor \
"$SYSTEMD_TEMPLATE_INSTANCES" \
"${PWD}/${KARAF_SERVICE_NAME}@.service"
elif [ -f /etc/redhat-release ]; then
generate_service_descriptor \
"$INIT_REDHAT_TEMPLATE" \
"${PWD}/${KARAF_SERVICE_NAME}" \
"${CONF_TEMPLATE}" \
"${KARAF_SERVICE_CONF}"
chmod 755 "${PWD}/${KARAF_SERVICE_NAME}"
elif [ -f /etc/debian-release ] || [ -f /etc/debian_version ]; then
generate_service_descriptor \
"$INIT_DEBIAN_TEMPLATE" \
"${PWD}/${KARAF_SERVICE_NAME}" \
"${CONF_TEMPLATE}" \
"${KARAF_SERVICE_CONF}"
chmod 755 "${PWD}/${KARAF_SERVICE_NAME}"
fi
;;
*)
generate_service_descriptor \
"$INIT_TEMPLATE" \
"${PWD}/${KARAF_SERVICE_NAME}" \
"${CONF_TEMPLATE}" \
"${KARAF_SERVICE_CONF}"
chmod 755 "${PWD}/${KARAF_SERVICE_NAME}"
;;
esac
else
generate_service_descriptor \
"$KARAF_SERVICE_TEMPLATE" \
"${PWD}/${KARAF_SERVICE_NAME}" \
"${CONF_TEMPLATE}" \
"${KARAF_SERVICE_CONF}"
fi