Skip to content

Commit

Permalink
Refactored Linux startup scripts:
Browse files Browse the repository at this point in the history
* Added Init Info Section with description, dependecies and runlevels
* Starting as a dedicated User is possible
* Create Logfile if not existing
* Create Logrotate Job if available
* Added Status Call for wotaskd script
  • Loading branch information
Daniel Kroeger committed Jan 27, 2014
1 parent 238db23 commit 7ec603a
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 43 deletions.
77 changes: 54 additions & 23 deletions Utilities/Linux/StartupScripts/RedHat/womonitor
Original file line number Diff line number Diff line change
@@ -1,44 +1,75 @@
#!/bin/bash

# chkconfig: - 90 20
# description: Provides JavaMonitor service

# Source function library.
. /etc/rc.d/init.d/functions


### BEGIN INIT INFO
# Provides: womonitor
# Required-Start: $all
# Required-Stop:
# Default-Start: 3 5 6
# Default-Stop: 0 1 2 6
# Short-Description: Starts the WebObjects Monitor
# Description: Starts the WebObjects Monitor which is necessary to run
# WebObjects Applications and control them via multiple hosts.
### END INIT INFO

USER=wouser
NEXT_ROOT="/opt"
export NEXT_ROOT

PATH="/bin:/usr/bin:/usr/java/latest/bin"
export PATH

USER=appserver


###############################################################################

# Create Logfile if not already exists and setup permissions.
if [ ! -e "/var/log/womonitor.log" ]; then
touch "/var/log/womonitor.log"
chown $USER "/var/log/womonitor.log"
chgrp root "/var/log/womonitor.log"
chmod 640 "/var/log/womonitor.log"
fi

# Create Logroate Job if available.
if [ -e "/etc/logrotate.d" ] && [ ! -e "/etc/logrotate.d/womonitor" ]; then
echo '/var/log/womonitor.log {' >> /etc/logrotate.d/womonitor
echo ' daily' >> /etc/logrotate.d/womonitor
echo ' rotate 5' >> /etc/logrotate.d/womonitor
echo ' compress' >> /etc/logrotate.d/womonitor
echo ' delaycompress' >> /etc/logrotate.d/womonitor
echo ' missingok' >> /etc/logrotate.d/womonitor
echo ' notifempty' >> /etc/logrotate.d/womonitor
echo '}' >> /etc/logrotate.d/womonitor
fi

###############################################################################

# See how we were called.
case "$1" in
status)
WOMONITOR_PID=`ps aux | awk '/WOPort 1086/ && !/awk/ {print $2}'`
if [ "$WOMONITOR_PID" != "" ]; then
echo "Service is running with PID $WOMONITOR_PID" | tee -a /var/log/womonitor.log
else
echo "Service is not running" | tee -a /var/log/womonitor.log
fi
;;
start)
echo -n "Starting JavaMonitor: "
su $USER -c "$NEXT_ROOT/Local/Library/WebObjects/JavaApplications/JavaMonitor.woa/JavaMonitor -WOPort 56789 &"
echo
echo "Starting womonitor: " | tee -a /var/log/womonitor.log
su $USER -c -l "$NEXT_ROOT/Library/WebObjects/JavaApplications/JavaMonitor.woa/JavaMonitor -WOPort 1086 | tee -a /var/log/womonitor.log &"
;;
stop)
echo -n "Shutting down JavaMonitor: "
MONITOR_PID=`ps aux | awk '/WOPort 56789/ && !/awk/ {print $2}'`
kill $MONITOR_PID
echo
echo "Shutting down womonitor: " | tee -a /var/log/womonitor.log
WOMONITOR_PID=`ps aux | awk '/WOPort 1086/ && !/awk/ {print $2}'`
kill $WOMONITOR_PID
;;
restart)
$0 stop
$0 start
;;
*)
echo -n "Usage: $0 {start|stop|restart}"
exit 1
esac

if [ $# -gt 1 ]; then
shift
$0 $*
fi

exit 0
75 changes: 55 additions & 20 deletions Utilities/Linux/StartupScripts/RedHat/wotaskd
Original file line number Diff line number Diff line change
@@ -1,44 +1,79 @@
#!/bin/bash

# chkconfig: - 90 20
# description: Provides wotaskd service

# Source function library.
. /etc/rc.d/init.d/functions


### BEGIN INIT INFO
# Provides: wotaskd
# Required-Start: $all
# Required-Stop:
# Default-Start: 3 5 6
# Default-Stop: 0 1 2 6
# Short-Description: Starts the WebObjects Task Daemon
# Description: Starts the WebObjects Task Daemon which is necessary to
# run Web Objects Applications at this host. WebObjects Task Daemon
# needs to run to be an configurable host via WebObjects Monitor.
### END INIT INFO

USER=wouser
NEXT_ROOT="/opt"
export NEXT_ROOT

PATH="/bin:/usr/bin:/usr/java/latest/bin"
export PATH

USER=appserver


###############################################################################

# Create Logfile if not already exists and setup permissions.
if [ ! -e "/var/log/wotaskd.log" ]; then
touch "/var/log/wotaskd.log"
chown $USER "/var/log/wotaskd.log"
chgrp root "/var/log/wotaskd.log"
chmod 640 "/var/log/wotaskd.log"
fi

# Create Logroate Job if available.
if [ -e "/etc/logrotate.d" ] && [ ! -e "/etc/logrotate.d/wotaskd" ]; then
echo '/var/log/wotaskd.log {' >> /etc/logrotate.d/wotaskd
echo ' daily' >> /etc/logrotate.d/wotaskd
echo ' rotate 5' >> /etc/logrotate.d/wotaskd
echo ' compress' >> /etc/logrotate.d/wotaskd
echo ' delaycompress' >> /etc/logrotate.d/wotaskd
echo ' missingok' >> /etc/logrotate.d/wotaskd
echo ' notifempty' >> /etc/logrotate.d/wotaskd
echo '}' >> /etc/logrotate.d/wotaskd
fi

###############################################################################

# See how we were called.
case "$1" in
status)
WOTASKD_PID=`ps aux | awk '/WOPort 1085/ && !/awk/ {print $2}'`
if [ "$WOTASKD_PID" != "" ]; then
echo "Service is running with PID $WOTASKD_PID" | tee -a /var/log/wotaskd.log
else
echo "Service is not running" | tee -a /var/log/wotaskd.log
fi
;;
start)
echo -n "Starting wotaskd: "
su $USER -c "$NEXT_ROOT/Local/Library/WebObjects/JavaApplications/wotaskd.woa/wotaskd -WOPort 1085 -er.wotaskd.sshd.enabled true &"
echo
echo "Starting wotaskd: " | tee -a /var/log/wotaskd.log
su $USER -c -l "$NEXT_ROOT/Library/WebObjects/JavaApplications/wotaskd.woa/wotaskd -WOPort 1085 | tee -a /var/log/wotaskd.log &"
;;
stop)
echo -n "Shutting down wotaskd: "
echo "Shutting down wotaskd: " | tee -a /var/log/wotaskd.log
WOTASKD_PID=`ps aux | awk '/WOPort 1085/ && !/awk/ {print $2}'`
kill $WOTASKD_PID
echo
;;
restart)
$0 stop
$0 start
;;
*)
echo -n "Usage: $0 {start|stop|restart}"
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac

if [ $# -gt 1 ]; then
shift
$0 $*
fi
exit 0

exit 0

0 comments on commit 7ec603a

Please sign in to comment.