We're Hiring!

Suggestion: Include linux upstart / sysvinit scripts

General user discussion about using the OMERO platform to its fullest. Please ask new questions at https://forum.image.sc/tags/omero
Please note:
Historical discussions about OMERO. Please look for and ask new questions at https://forum.image.sc/tags/omero

There are workflow guides for various OMERO functions on our help site - http://help.openmicroscopy.org

You should find answers to any basic questions about using the clients there.

Suggestion: Include linux upstart / sysvinit scripts

Postby Sethur » 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:
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
Sethur
 
Posts: 112
Joined: Thu Jan 16, 2014 11:34 pm

Re: Suggestion: Include linux upstart / sysvinit scripts

Postby manics » Wed Jun 03, 2015 9:52 am

Hi Tristan

We've got some init.d files in our documentation (they've been tested on Centos 6 and Ubuntu 14.04): http://www.openmicroscopy.org/site/supp ... ning-omero

Simon
User avatar
manics
Team Member
 
Posts: 261
Joined: Mon Oct 08, 2012 11:01 am
Location: Dundee

Re: Suggestion: Include linux upstart / sysvinit scripts

Postby Sethur » Wed Jun 03, 2015 12:09 pm

Hi Simon,

thanks for pointing this out, I guess the init.d-scripts you linked to were refined after I had last seen then. Anyway, this is nice have for a linux setup.

Cheers,

Tristan
Sethur
 
Posts: 112
Joined: Thu Jan 16, 2014 11:34 pm


Return to User Discussion

Who is online

Users browsing this forum: Google [Bot] and 1 guest