Suggestion: Include linux upstart / sysvinit scripts
Posted: Wed Jun 03, 2015 9:35 am
Hi,
since I had to write the upstart scripts basically from scratch (I think there was some minimal example floating around somewhere on the OMERO codebase) when I installed OMERO on our ubuntu server, I thought I might include my files for the server and OMERO.web here for others to use. It might be a good idea to include a more complete version of those scripts in the OMERO releases.
/etc/init.d/omero-server:
/etc/omero-web
Hope that proves useful for somebody.
Cheers,
Tristan
EDIT: You need a user "omero" with the right set of environment variables for this to work. I usually put them in ~/.profile, like this:
since I had to write the upstart scripts basically from scratch (I think there was some minimal example floating around somewhere on the OMERO codebase) when I installed OMERO on our ubuntu server, I thought I might include my files for the server and OMERO.web here for others to use. It might be a good idea to include a more complete version of those scripts in the OMERO releases.
/etc/init.d/omero-server:
- Code: Select all
#!/bin/bash
#
# /etc/init.d/omero
# Subsystem file for "omero" server
#
### BEGIN INIT INFO
# Provides: omero
# Required-Start: $local_fs $remote_fs $network $time postgresql
# Required-Stop: $local_fs $remote_fs $network $time postgresql
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: OMERO.server
### END INIT INFO
RETVAL=0
NAME="omero"
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
OMERO_PREFIX=${OMERO_PREFIX:-"/usr/local/share/omero/OMERO.server"}
OMERO_USER=${OMERO_USER:-"omero"}
start() {
echo -n "Starting $NAME: "
sudo -iu ${OMERO_USER} ${OMERO_PREFIX}/bin/omero admin start > /dev/null 2>&1 && echo ' OMERO.server started.'
RETVAL=$?
[[ ! $RETVAL = 0 ]] && echo "OMERO.server startup failed."
}
stop() {
echo -n "Stopping $NAME: "
sudo -iu ${OMERO_USER} ${OMERO_PREFIX}/bin/omero admin stop > /dev/null 2>&1 && echo ' OMERO.server stopped.'
RETVAL=$?
[[ ! $RETVAL = 0 ]] && echo "OMERO.server stopping failed."
}
status() {
echo -n "Status $NAME: "
sudo -iu ${OMERO_USER} ${OMERO_PREFIX}/bin/omero admin status
RET=$?
[ "$RET" = 0 ] && echo 'OMERO.server running'
[ "$RET" != 0 ] && echo 'OMERO.server not running'
RETVAL=$RET
}
diagnostics() {
echo -n "Diagnostics $NAME:"
sudo -iu ${OMERO_USER} ${OMERO_PREFIX}/bin/omero admin diagnostics
RETVAL=$?
}
clearlogs() {
OMERO_LOGDIR=${OMERO_LOGDIR:-${OMERO_PREFIX}/var/log}
OMERO_LOGTARFILE=${OMERO_LOGTARFILE:-omero-logs-$(date '+%F').tar.bz2}
echo -n "Clearing logs $NAME:"
cd $OMERO_LOGDIR && tar -caf $OMERO_LOGTARFILE *.{err,out,log} && \
(for x in ${OMERO_LOGDIR}/*.{err,out,log}; do : > $x ;done) && \
chown $OMERO_USER ${OMERO_LOGDIR}/${OMERO_LOGTARFILE} && \
echo -n " saved to $OMERO_LOGDIR/$OMERO_LOGTARFILE:"
RETVAL=$?
echo
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
RETVAL=$?
;;
diagnostics)
diagnostics
RETVAL=$?
;;
clearlogs)
clearlogs
RETVAL=$?
;;
*)
echo "Usage: $0 {start|stop|restart|status|diagnostics|clearlogs}"
RETVAL=3
esac
exit $RETVAL
/etc/omero-web
- Code: Select all
#!/bin/bash
#
# /etc/init.d/omero
# Subsystem file for "omero" server
#
### BEGIN INIT INFO
# Provides: omero-web
# Required-Start: $local_fs $remote_fs $network $time omero postgresql
# Required-Stop: $local_fs $remote_fs $network $time omero postgresql
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: OMERO.web
### END INIT INFO
RETVAL=0
NAME="omero-web"
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
# Also read the omero config
[ -r /etc/default/omero ] && . /etc/default/omero
OMERO_PREFIX=${OMERO_PREFIX:-"/usr/local/share/omero/OMERO.server"}
OMERO_USER=${OMERO_USER:-"omero"}
start() {
echo -n "Starting $NAME: "
sudo -iu ${OMERO_USER} ${OMERO_PREFIX}/bin/omero web start > /dev/null 2>&1 && echo 'OMERO.web started.'
RETVAL=$?
[[ ! $RETVAL = 0 ]] && echo 'OMERO.web startup failed.'
}
stop() {
echo -n "Stopping $NAME: "
sudo -iu ${OMERO_USER} ${OMERO_PREFIX}/bin/omero web stop > /dev/null 2>&1 && echo 'OMERO.web stopped.'
RETVAL=$?
[[ ! $RETVAL = 0 ]] && echo 'OMERO.web stopping failed.'
}
status() {
echo -n "Status $NAME: "
sudo -iu ${OMERO_USER} ${OMERO_PREFIX}/bin/omero web status
RETVAL=$?
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
RETVAL=$?
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
RETVAL=3
esac
exit $RETVAL
Hope that proves useful for somebody.
Cheers,
Tristan
EDIT: You need a user "omero" with the right set of environment variables for this to work. I usually put them in ~/.profile, like this:
- Code: Select all
export JAVA_HOME=/usr/lib/jvm/default-java
export ICE_HOME=/usr/share/Ice-3.5.1
export POSTGRES_HOME=/usr/lib/postgresql/9.3
export OMERO_PREFIX=/usr/local/share/omero/OMERO.server
export OMERO_LOGS=/var/log/omero
export LD_LIBRARY_PATH=/usr/share/java:/usr/lib:$LD_LIBRARY_PATH
export PYTHONPATH=/usr/lib/pymodules/python2.7:$PYTHONPATH
export PATH=$PATH:$JAVA_HOME/bin:$ICE_HOME:$POSTGRES_HOME/bin:$OMERO_PREFIX/bin