📄 opennms.sh
字号:
#!/bin/sh -## chkconfig: 345 99 01# description: Starts and stops the OpenNMS network management \# poller and backend processes# processname: opennms# pidfile: @install.pid.file@#### BEGIN INIT INFO# Provides: opennms# Required-Start: $local_fs $network @install.postgresql.service@# Should-Start: $time $named ypbind# Required-Stop: $local_fs $network# Should-Stop: $time $named ypbind# Default-Start: 3 5# Default-Stop: 0 1 2 6# Short-Description: OpenNMS daemon for network monitoring# Description: OpenNMS daemon for network monitoring### END INIT INFO## $Id: opennms.sh 5173 2006-11-19 00:36:06Z djgregor $## For info on the "chkconfig:" section, see:# http://www.sensi.org/~alec/unix/redhat/sysvinit.html## For info on the "BEGIN INIT INFO" section, see:# http://www.suse.de/~mmj/Package-Conventions/##### ------------> DO NOT CHANGE VARIABLES IN THIS FILE <------------- ######## Create $OPENNMS_HOME/etc/opennms.conf and put overrides in there. ######## ------------> DO NOT CHANGE VARIABLES IN THIS FILE <------------- ##### Home directory for OpenNMS.OPENNMS_HOME="@install.dir@"# PID file for OpenNMS.OPENNMS_PIDFILE="@install.pid.file@"# Where to redirect "start" output.REDIRECT="@install.logs.dir@/output.log"# Number of times to do "opennms status" after starting OpenNMS to see# if it comes up completely. Set to "0" to disable. Between each# attempt we sleep for STATUS_WAIT seconds. START_TIMEOUT=10# Number of seconds to wait between each "opennms status" check when# START_TIMEOUT > 0.STATUS_WAIT=5# Value of the -Xmx<size>m option passed to Java.JAVA_HEAP_SIZE=256# Additional options that should be passed to Java when starting OpenNMS.ADDITIONAL_MANAGER_OPTIONS=""# Classpath additions. These go on the front of our classpath.ADDITIONAL_CLASSPATH=""# Use incremental garbage collection.USE_INCGC=""# Use the Java Hotspot server VM.HOTSPOT=""# Enable verbose garbage collection debugging.VERBOSE_GC=""# Additional options to pass to runjava.RUNJAVA_OPTIONS=""# URL that this script uses to communicate with a running OpenNMS daemon.INVOKE_URL="http://127.0.0.1:8181/invoke?objectname=OpenNMS:Name=FastExit"# Unset http_proxy. If people have it set, it will likely break wget/curl# when it tries to connect to localhost.unset http_proxy#### ------------> DO NOT CHANGE VARIABLES IN THIS FILE <------------- ######## Create $OPENNMS_HOME/etc/opennms.conf and put overrides in there. ######## ------------> DO NOT CHANGE VARIABLES IN THIS FILE <------------- ##### Load opennms.conf, if it exists, to override above configuration options.if [ -f $OPENNMS_HOME/etc/opennms.conf ]; then . $OPENNMS_HOME/etc/opennms.conffishow_help () { cat <<ENDUsage: $0 [-n] [-t] [-v] <command> [<service>] command options: start|stop|restart|status|check|pause|resume|kill service options: all|<a service id from the etc/service-configuration.xml> defaults to all The following options are available: -n "No execute" mode. Don't call Java to do anything. -t Test mode. Enable JPDA on port 8001. -v Verbose mode. When used with the "status" command, gives the results for all OpenNMS services. When used with "start", enables some verbose debugging, such as details on garbage collection.END return}if `ps auxwww >/dev/null 2>&1`; then PS="ps auxwww"elif `ps -ef >/dev/null 2>&1`; then PS="ps -ef"else echo "I don't know how to run PS on your system!" exit 1fiexport PSget_url () { [ -n "$1" ] || return 1 URL="$1" HTTP=`which curl 2>/dev/null | egrep -v 'no such|no curl'` if [ -n "$HTTP" ]; then $HTTP -o - -s "$URL" | $OPENNMS_HOME/bin/parse-status.pl return 0 fi HTTP=`which wget 2>/dev/null | egrep -v 'no such|no wget'` if [ -n "$HTTP" ]; then $HTTP --quiet -O - "$URL" | $OPENNMS_HOME/bin/parse-status.pl return 0 fi HTTP=`which lynx 2>/dev/null | egrep -v 'no such|no lynx'` if [ -n "$HTTP" ]; then $HTTP -dump "$URL" | $OPENNMS_HOME/bin/parse-status.pl return 0 fi return 1}getStatus(){ get_url "${INVOKE_URL}&operation=status" && return 0 APP_VM_PARMS="$CONTROLLER_OPTIONS" APP_CLASS="$CONTROLLER_CLASS" APP_PARMS_BEFORE="status $SERVICE" if [ -z "$NOEXECUTE" ]; then $JAVA_CMD -classpath $APP_CLASSPATH $APP_VM_PARMS $APP_CLASS $APP_PARMS_BEFORE "$@" $APP_PARMS_AFTER 2>&1 | $OPENNMS_HOME/bin/parse-status.pl fi}checkRpmFiles(){ # XXX need to have a way to specify the Tomcat directory to check if [ -d /var/tomcat4/webapps/opennms/WEB-INF ]; then TOMCATDIR=/var/tomcat4/webapps/opennms/WEB-INF else TOMCATDIR="" fi if [ `find $OPENNMS_HOME $TOMCATDIR -name \*.rpmnew | wc -l` -gt 0 ]; then cat <<ENDWARNING! You have files that end in .rpmnew in yourOPENNMS_HOME ($OPENNMS_HOME) directory.The format of the original files may have changed sinceyou modified them before installing a new version.Please double-check that your configuration files areup-to-date and delete any leftover .rpmnew files orOpenNMS will not start.END return 6 # From LSB: 6 - program is not configured fi if [ `find $OPENNMS_HOME $TOMCATDIR -name \*.dpkg-dist | wc -l` -gt 0 ]; then cat <<ENDWARNING! You have files that end in .dpkg-dist in yourOPENNMS_HOME ($OPENNMS_HOME) directory.The format of the original files may have changed sinceyou modified them before installing a new version.Please double-check that your configuration files areup-to-date and delete any leftover .dpkg-dist files orOpenNMS will not start.END return 6 # From LSB: 6 - program is not configured fi if [ `find $OPENNMS_HOME $TOMCATDIR -name \*.rpmsave | wc -l` -gt 0 ]; then cat <<ENDWARNING! You have files that end in .rpmsave in yourOPENNMS_HOME ($OPENNMS_HOME) directory.The format of the original files may have changed sinceyou modified them before installing a new version, soyour modified configuration files have been backed upand replaced. Please double-check that your changes tothe configuration files are added back into the updatefiles and delete any leftover .rpmsave files or OpenNMSwill not start.END return 6 # From LSB: 6 - program is not configured fi return 0}doStart(){ if id | grep '^uid=0(' > /dev/null; then true # all is well else echo "Error: you must start OpenNMS as root" >&2 return 4 # According to LSB: 4 - user had insufficient privileges fi checkRpmFiles || return $? doStatus status=$? case $status in 0) echo "OpenNMS is already running." >&2 return 1 ;; 160) echo "OpenNMS is partially running." >&2 echo "If you have just attempted starting OpenNMS, please try again in a few" >&2 echo "moments, otherwise, at least one service probably had issues starting." >&2 echo "Check your logs in @install.logs.dir@ for errors." >&2 return 1 ;; 3) true # don't do anything, it isn't running, which is good # because we are going to start it. :-) break ;; *) echo "Unknown value return from doStatus: $status" >&2 return 1 esac ########################################################################## # Run opennms.sh with the "-t" option to enable the Java Platform Debugging # Architecture. This will open a server socket on port 8001 that can be # connected to by a remote java debugger. A good choice is JSwat which can # be found at http://www.bluemarsh.com ########################################################################### if [ $TEST -gt 0 ]; then echo "- enabling JPDA debugging on port 8001" JPDA="-Xdebug -Xnoagent -Djava.compiler=none -Xrunjdwp:transport=dt_socket,server=y,address=8001,suspend=n" else JPDA="" fi if [ "$SERVICE" = "" ]; then APP_VM_PARMS="$JPDA $MANAGER_OPTIONS" APP_CLASS="$MANAGER_CLASS" APP_PARMS_BEFORE="" else APP_VM_PARMS="$CONTROLLER_OPTIONS" APP_CLASS="$CONTROLLER_CLASS" APP_PARMS_BEFORE="start $SERVICE" fi if [ -z "$NOEXECUTE" ]; then echo "------------------------------------------------------------------------------" >> "$REDIRECT" date >> "$REDIRECT" echo "begin ulimit settings:" >> "$REDIRECT" ulimit -a >> "$REDIRECT" echo "end ulimit settings" >> "$REDIRECT" CMD="$JAVA_CMD -classpath $APP_CLASSPATH $APP_VM_PARMS $APP_CLASS $APP_PARMS_BEFORE "$@" $APP_PARMS_AFTER" echo "Executing command: $CMD" >> "$REDIRECT" $CMD >>"$REDIRECT" 2>&1 & OPENNMS_PID=$! echo $OPENNMS_PID > "$OPENNMS_PIDFILE" # disown # XXX specific to bash fi if [ $START_TIMEOUT -eq 0 ]; then # don't wait for OpenNMS to startup $opennms_echo "(not waiting for startup) \c" return 0 fi # wait for OpenNMS to startup STATUS_ATTEMPTS=0 while [ $STATUS_ATTEMPTS -lt $START_TIMEOUT ]; do if doStatus; then return 0 fi if ps -p $OPENNMS_PID | grep "^ *$OPENNMS_PID " > /dev/null; then true # Java process is still running... don't do anything else echo "Started OpenNMS, but it stopped running: check output.log" >&2 return 1 fi sleep $STATUS_WAIT STATUS_ATTEMPTS=`expr $STATUS_ATTEMPTS + 1` done echo "Started OpenNMS, but it has not finished starting up" >&2 return 1 }doPause(){ if doStatus; then APP_VM_PARMS="$CONTROLLER_OPTIONS" APP_CLASS="$CONTROLLER_CLASS" APP_PARMS_BEFORE="pause $SERVICE" if [ -z "$NOEXECUTE" ]; then $JAVA_CMD -classpath $APP_CLASSPATH $APP_VM_PARMS $APP_CLASS $APP_PARMS_BEFORE "$@" $APP_PARMS_AFTER fi else echo "OpenNMS is not running." fi}doResume(){ if doStatus; then APP_VM_PARMS="$CONTROLLER_OPTIONS" APP_CLASS="$CONTROLLER_CLASS" APP_PARMS_BEFORE="resume $SERVICE" if [ -z "$NOEXECUTE" ]; then $JAVA_CMD -classpath $APP_CLASSPATH $APP_VM_PARMS $APP_CLASS $APP_PARMS_BEFORE "$@" $APP_PARMS_AFTER fi else echo "OpenNMS is not running." fi}doCheck() { if doStatus; then # do nothing.. it's running exit 0 fi echo `date`": OpenNMS is not running... Restarting"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -