Thursday, July 29, 2010

Startup scripts

Sample startup file, place in /etc/init.d:

cat /etc/init.d/archiva
#! /bin/sh
# chkconfig: 345 90 10
# description: Archiva server

# uncoment to set JAVA_HOME as the value present when Continuum installed
export JAVA_HOME=/opt/SDK/jdk
export ARCHIVA=/opt/archiva/current/bin/archiva

case "$1" in

'start')
su - archiva -c "$ARCHIVA start"

;;

'stop')
su - archiva -c "$ARCHIVA stop"

;;

'restart')
su - archiva -c "$ARCHIVA stop"
sleep 20
su - archiva -c "$ARCHIVA start"

;;

*)
echo "Usage: $0 { start | stop | restart }"
exit 1
;;
esac

exit 0


To add it to startup, execute as root:
chkconfig --add archiva


Done.




Another example, using Geronimo:

[geronimo@mypc bin]$ ./geronimo.sh --help
Using GERONIMO_HOME: /home/geronimo/geronimo-tomcat6-javaee5-2.1.6
Using GERONIMO_TMPDIR: var/temp
Using JRE_HOME: /opt/SDK/jdk/jre
Usage: geronimo.sh command [geronimo_args]
commands:
debug Debug Geronimo in jdb debugger
jpda run Start Geronimo in foreground under JPDA debugger
jpda start Start Geronimo in background under JPDA debugger
run Start Geronimo in the foreground
start Start Geronimo in the background
stop Stop Geronimo
stop --force Stop Geronimo (followed by kill -KILL)




Create /etc/init.d/geronimo as follows:

#! /bin/sh
# chkconfig: 345 90 10
# description: geronimo server

# uncoment to set JAVA_HOME as the value present when Continuum installed
export JAVA_HOME=/opt/SDK/jdk
export GERONIMO=/opt/geronimo/current/bin/geronimo.sh

case "$1" in

'start')
su - geronimo -c "$GERONIMO start"

;;

'stop')
su - geronimo -c "$GERONIMO stop"

;;

'restart')
su - geronimo -c "$GERONIMO stop"
sleep 20
su - geronimo -c "$GERONIMO start"

;;

'debug')
su - geronimo -c "$GERONIMO debug"

;;

'jpdarun')
su - geronimo -c "$GERONIMO jpda run"

;;

'jpdastart')
su - geronimo -c "$GERONIMO jpda start"

;;

'jpdastop')
su - geronimo -c "$GERONIMO stop"

;;



*)
echo "Usage: $0 { start | stop | restart | debug | jpdarun | jpdastart | jpdastop }"
exit 1
;;

esac

exit 0



Test each entry:

/etc/init.d/geronimo
Usage: /etc/init.d/geronimo { start | stop | restart | debug | jpdarun | jpdastart | jpdastop }

/etc/init.d/geronimo start

/etc/init.d/geronimo stop
(login/pass = system / manager)

/etc/init.d/geronimo debug


# add to startup
chkconfig --add geronimo

# check that the file exists in the startup location, ex:
ls -la /etc/rc.d/init.d/geronimo

No comments:

Post a Comment