Skip to content

Instantly share code, notes, and snippets.

@jhpedemonte
Created May 29, 2012 01:23
Show Gist options
  • Save jhpedemonte/2822045 to your computer and use it in GitHub Desktop.
Save jhpedemonte/2822045 to your computer and use it in GitHub Desktop.
Run Maqetta server as a Linux service

Installation

  • Choose one of maqetta.daemonize.sh or maqetta.start-stop-daemon.sh and copy it to /etc/init.d/maqetta

    • maqetta.daemonize.sh supports logging (to /var/log/maqetta.log) but depends on daemonize.
    • maqetta.start-stop-daemon.sh depends only on start-stop-daemon, but doesn't do logging.
      • NOTE: This script has not been updated to reflect the latest changes and is only here for historical purposes.
  • chmod a+x /etc/init.d/maqetta

  • Activate the init script; run one of the following:

      # Ubuntu
      update-rc.d maqetta defaults
      # CentOS
      chkconfig --add maqetta
      chkconfig maqetta on
    
  • copy maqetta.conf to /etc/maqetta.conf

Usage

  • Start: /etc/init.d/maqetta start
  • Stop: /etc/init.d/maqetta stop
  • Query status: /etc/init.d/maqetta status

Known Issues

  • If you wish to use logrotate for logs produced by maqetta.daemonize.sh, you must use the copytruncate feature. See the explanation here.
#
# Change to this user before running Maqetta server
#
maqetta.user=maqetta
#
# Directory containing user workspaces.
#
maqetta.baseDirectory=/var/lib/maqetta/users
#
# Site configuration directory.
#
maqetta.siteConfigDirectory=/var/lib/maqetta/siteConfig
#
# Point to 'users' directory of pre-M7 version, in order to enable migration
#
#migrateWorkspaceLoc=/var/lib/maqetta/users-M6
#
# Enable Dojo Web Builder, by specify its URL.
# (No trailing slash.)
#
#maqetta.dojoWebBuilder=http://build.dojotoolkit.org
#
# Additional arguments for the java process.
#
#maqetta.extra_java_args=-Xmx512m -Xms256m
#
# Network port for server. Defaults to 8080.
#
#org.eclipse.equinox.http.jetty.http.port=8080
#
# User authentication which the server should use. Possible values:
# * FORM+OpenId: (default) Form-based authentication. NOTE: OpenId auth
# is not supported by Maqetta (yet).
# * Basic: basic HTTP authentication
# * ldaplogin: LDAP server authentication
#
#orion.auth.name=
#
# Setup admin password (account name is 'admin').
# Only use once to set up, then comment out this line and remove password
#
#orion.auth.admin.default.password=abracadabra
#maqetta.serverDebug=true
###############################################
# LDAP Options
###############################################
#
# To use LDAP user authentication, set "orion.auth.name=ldaplogin" (see above)
# and set the appropriate values in the maqetta.auth.ldap.* options
#
# the ldap url to use when authenticating a user
maqetta.auth.ldap.provider.url=ldaps://ldapserver.example.com:636
# the ldap url to use when looking up a uses ldap information
# non ssl is faster.
maqetta.auth.ldap.lookup.provider.url=ldap://ldapserver.example.com:389
# the jndi directory context to use, optional, if not defined defaults to
# com.sun.jndi.ldap.LdapCtxFactory
maqetta.auth.ldap.initial.context.factory=com.sun.jndi.ldap.LdapCtxFactory
# (defaults to com.sun.jndi.url)
maqetta.auth.ldap.url.pkg.prefixes=com.sun.jndi.url
# (defaults to ignore)
maqetta.auth.ldap.referral=ignore
# Used when authenticating a user
maqetta.auth.ldap.security.authentication=SIMPLE
# Used when looking up a user. Possible values:
# * none: (default)
# * SIMPLE
maqetta.auth.ldap.lookup.security.authentication=none
# used when when authenticating a user
maqetta.auth.ldap.security.protocol=ssl
# used when when looking up a user. Possible values:
# * none: (default)
# * ssl
#maqetta.auth.ldap.lookup.security.protocol=ssl
# ldap base to use when searching for user
maqetta.auth.ldap.base=dc=example,dc=com
# ldap attribute to use when searching for user (i.e. "email" or
# "employeenumber")
maqetta.auth.ldap.user.filter=mail
# ldap attribute that will be used as the user's display name
maqetta.auth.ldap.user.displayname=cn
# ldap attribute that will be used as user's email
#maqetta.auth.ldap.user.email=email
# Used to bind with the ldap server for lookup if ldap server does not
# allow anonymous lookup.
#maqetta.auth.ldap.bind.user=cn=Directory Manager
#maqetta.auth.ldap.bind.password=secret
# Location of trust store to be used with SSL for self-signed certificates.
#maqetta.auth.ldap.truststore=C:/OpenDS-2.2.1/OpenDS_no_anon/config/truststore
# Truststore password, not needed in most cases.
#maqetta.auth.ldap.truststorepassword=secret
# Truststore type.
#maqetta.auth.ldap.truststoretype=JKS
# keystore not used in most server.
#maqetta.auth.ldap.keystore=C:/OpenDS-2.2.1/OpenDS_no_anon/config/keystore
#maqetta.auth.ldap.keystorepassword=secret
###############################################
# Mail Options
###############################################
#
# SMTP server, used for sending registration and review emails.
#
#smtp.mailServer=<host>[:<port>]
smtp.mailServer=localhost
#
# SMTP server authentication; optional
#
#smtp.loginUser=<user name>
#smtp.password=<loginUser password>
#
# Specify the email address to use as "from" when sending emails.
# Defaults to "admin@<hostname>"
#
#smtp.notificationId=admin@domain.ltd
# 'mail.smtp.host' => cannot use, instead use 'smtp.mailServer'
# 'mail.transport.protocol' => always set to 'smtp'
#
# Enable use of the STARTTLS command. Will also need to enable the
# mail.smtp.socketFactory.class property.
#
#mail.smtp.starttls.enable=true
#
# Athenticate using AUTH command
#
#mail.smtp.auth=true
# Use the following if you need SSL
#mail.smtp.socketFactory.port=d_port
#mail.smtp.socketFactory.class="javax.net.ssl.SSLSocketFactory"
#mail.smtp.socketFactory.fallback=false
#mail.debug=true
###############################################
# SSL Options
###############################################
#jetty.https.enabled=true
#jetty.https.port=8443
#jetty.ssl.keystore=/var/lib/maqetta/keystore
#jetty.ssl.password=password
#jetty.ssl.keypassword=password
#jetty.ssl.protocol=SSLv3
#! /bin/bash
### BEGIN INIT INFO
# Provides: maqetta
# Required-Start: $remote_fs $network $syslog
# Required-Stop: $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Maqetta Designer server
# Description: Controls the Maqetta server.
### END INIT INFO
#
# Author: Javier Pedemonte <javier@pedemonte.us>
#
#
# NOTES:
#
# * `logrotate`: must use the "copytruncate" option
#
# Do NOT "set -e"
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Maqetta server"
NAME=maqetta
DAEMONIZE=/usr/local/sbin/daemonize
JAVA=/usr/bin/java
JAVA_ARGS=""
# XXX Issue 2941 - Need to specify "-clean" flag due to possible Eclipse bug.
APP_ARGS="-noExit -clean"
PIDFILE=/var/run/$NAME.pid
LOCKFILE=/var/lock/$NAME.lock
LOG=/var/log/$NAME.log
SCRIPTNAME=/etc/init.d/$NAME
# XXX move to config file?
MAQ_BASE="/usr/local/maqetta/latest"
USER=maqetta
# Exit if the package is not installed
[ -x "$DAEMONIZE" ] || exit 0
[ -x "$JAVA" ] || exit 0
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
# Load the VERBOSE setting and other rcS variables
[ -r /lib/init/vars.sh ] && . /lib/init/vars.sh
if [ -r /etc/debian_version ]; then
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
elif [ -r /etc/init.d/functions ] ; then
. /etc/init.d/functions
fi
#
# Check minimum Java version. Must be >= 1.6
#
check_java() {
javaversion=`java -version 2>&1 | grep "java version"`
if [ -z "$javaversion" ]; then
echo Unable to determine which version of Java is installed on this machine
else
majorversionnumber=`echo "$javaversion" | sed 's/^[^0-9]*\([0-9][0-9]*\)\..*$/\1/'`
minorversionnumber=`echo "$javaversion" | sed 's/^[^0-9]*[0-9][0-9]*\.\([0-9][0-9]*\).*$/\1/'`
if [ $majorversionnumber -lt 1 -o $minorversionnumber -lt 6 ]; then
echo "Error: Maqetta requires Java 1.6"
exit 2
fi
fi
}
#
# Function which reads in configuration options
#
read_conf()
{
# check for configuration file
MAQ_CONFIG=/etc/maqetta.conf
test -r $MAQ_CONFIG || { echo "$MAQ_CONFIG not found";
if [ "$1" = "stop" ]; then exit 0;
else exit 2; fi; }
JAVA_ARGS="${JAVA_ARGS} -Dorion.core.configFile=${MAQ_CONFIG}"
# check for site configuration directory
MAQ_SITE_CONFIG=$MAQ_BASE/siteConfig
test -r $MAQ_SITE_CONFIG || { echo "$MAQ_SITE_CONFIG not found";
if [ "$1" = "stop" ]; then exit 0;
else exit 2; fi; }
JAVA_ARGS="${JAVA_ARGS} -Dmaqetta.siteConfigDirectory=${MAQ_SITE_CONFIG}"
# read config
while read line
do
key=${line%%=*}
val=${line#*=}
case "$key" in
"maqetta.user")
USER=$val
continue # don't add to JAVA_ARGS
;;
"maqetta.baseDirectory")
if [ ! -d $val ]; then
mkdir -p ${val}
chown $USER:$USER ${val}
fi
# pass in as "-data" property (used by Orion)
APP_ARGS="${APP_ARGS} -data ${val}"
;;
"maqetta.extra_java_args")
extra_java_args=$val
;;
"org.eclipse.equinox.http.jetty.http.port")
port=$val
# Add to the Java args
JAVA_ARGS="${JAVA_ARGS} -D${line}"
;;
# all other config items are read directly from file by server code
esac
done < <(grep -v "^#" ${MAQ_CONFIG} | grep -v "^\s*$")
# get jar path
jarFilePath=`ls "$MAQ_BASE"/plugins/org.eclipse.equinox.launcher*.jar`
JAR_FILE="-jar ${jarFilePath}"
}
#
# Function which returns PID of Maqetta server process
#
pidof_maqetta() {
PIDS=`pgrep -u $USER -f ".*java.*equinox.*"` || true
[ -e $PIDFILE ] && PIDS2=`cat $PIDFILE`
for i in $PIDS; do
if [ "$i" = "$PIDS2" ]; then
echo $i
return 0
fi
done
return 1
}
#
# Function that starts the daemon/service
#
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
check_java
if [ ! -f $LOG ]; then
touch $LOG
chown $USER:$USER $LOG
fi
echo "" >> $LOG
echo "===============================================================" >> $LOG
date "+Starting Maqetta: %Y-%m-%d %H:%M:%S%n" >> $LOG
ulimit -n 2000
$DAEMONIZE -u $USER -p $PIDFILE -l $LOCKFILE -a -o $LOG -e $LOG -v \
$JAVA $JAVA_ARGS ${extra_java_args} $JAR_FILE $APP_ARGS
}
#
# Function that stops the daemon/service
#
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
PID=$(pidof_maqetta)
[ -z "$PID" ] && return 1
kill $PID
# check that process has stopped
sleep 1
PID=$(pidof_maqetta)
if [ -z "$PID" ]; then
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return 0
fi
return 2
}
read_conf
case "$1" in
start)
log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) log_end_msg 0 ;;
2) log_end_msg 1 ;;
esac
;;
stop)
log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) log_end_msg 0 ;;
2) log_end_msg 1 ;;
esac
;;
restart|force-reload)
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
status)
PID=$(pidof_maqetta)
if [ "$PID" ]; then
log_action_msg "Maqetta server is running"
else
log_action_msg "Maqetta server is stopped."
exit 3
fi
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status}" >&2
exit 3
;;
esac
:
#! /bin/sh
### BEGIN INIT INFO
# Provides: maqetta
# Required-Start: $remote_fs $network $syslog
# Required-Stop: $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Maqetta Designer server
# Description: Controls the Maqetta server.
### END INIT INFO
#
# Author: Javier Pedemonte <javier@pedemonte.us>
#
# Do NOT "set -e"
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Maqetta server"
NAME=maqetta
JAVA=/usr/bin/java
JAVA_ARGS="-Dmaqetta.localInstall=false"
APP_ARGS="-noExit"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
# XXX move to config file?
MAQ_BASE="/usr/local/maqetta"
# Exit if the package is not installed
[ -x "$JAVA" ] || exit 0
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
# Load the VERBOSE setting and other rcS variables
[ -r /lib/init/vars.sh ] && . /lib/init/vars.sh
if [ -r /etc/debian_version ]; then
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
elif [ -r /etc/init.d/functions ] ; then
. /etc/init.d/functions
fi
#
# Function to check minimum Java version. Must be >= 1.5
#
check_java()
{
javaversion=`java -version 2>&1 | grep "java version"`
if [ -z "$javaversion" ]; then
echo Unable to determine which version of Java is installed on this machine
else
majorversionnumber=`echo "$javaversion" | sed 's/^[^0-9]*\([0-9][0-9]*\)\..*$/\1/'`
minorversionnumber=`echo "$javaversion" | sed 's/^[^0-9]*[0-9][0-9]*\.\([0-9][0-9]*\).*$/\1/'`
if [ $majorversionnumber -lt 1 -o $minorversionnumber -lt 5 ]; then
echo Maqetta requires Java 1.5+.
exit 2
fi
fi
}
#
# Function which reads in configuration options
#
read_conf()
{
# check for configuration file
MAQ_CONFIG=/etc/maqetta.conf
test -r $MAQ_CONFIG || { echo "$MAQ_CONFIG not found";
if [ "$1" = "stop" ]; then exit 0;
else exit 2; fi; }
# read config
. $MAQ_CONFIG
# setup Java arguments
if [ -z $port ]; then
port="50000"
fi
JAVA_ARGS="${JAVA_ARGS} -Dorg.eclipse.equinox.http.jetty.http.port=${port}"
if [ -z $user_dir ]; then
user_dir="/var/lib/maqetta/users"
mkdir -p ${user_dir}
fi
JAVA_ARGS="${JAVA_ARGS} -Dmaqetta.baseDirectory=${user_dir}"
if [ -z $login_url ]; then
login_url="/maqetta/welcome"
fi
JAVA_ARGS="${JAVA_ARGS} -DloginUrl=${login_url}"
if [ -z $smtp_server ]; then
smtp_server="localhost"
fi
JAVA_ARGS="${JAVA_ARGS} -Dsmtp.mailServer=${smtp_server}"
# get jar path
jarFilePath=`ls "$MAQ_BASE"/plugins/org.eclipse.equinox.launcher*.jar`
JAR_FILE="-jar ${jarFilePath}"
}
#
# Function that starts the daemon/service
#
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
check_java
read_conf
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $JAVA --test > /dev/null \
|| return 1
# XXX using `--background`, which should be used for last resort
start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background \
--chuid $user --exec $JAVA -- $JAVA_ARGS ${extra_java_args} $JAR_FILE $APP_ARGS \
|| return 2
}
#
# Function that stops the daemon/service
#
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return "$RETVAL"
}
case "$1" in
start)
log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) log_end_msg 0 ;;
2) log_end_msg 1 ;;
esac
;;
stop)
log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) log_end_msg 0 ;;
2) log_end_msg 1 ;;
esac
;;
restart|force-reload)
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
status)
# XXX need better test. port sniffer?
read_conf
maqpid=`pgrep -u $user -f ".*java.*equinox.*"`
if [ $maqpid ]; then
log_action_msg "Maqetta server is running"
else
log_action_msg "Maqetta server is stopped."
exit 3
fi
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status}" >&2
exit 3
;;
esac
:
@paulD1968
Copy link

My use is to have Maqetta started when I start my linux box. Installing the service is nice but for some reason on my Mageia flavor it's not working. Therefore I used an alternative way. It doesn't provide logging or restart but it launch it at start up nicely and it's what I want.

My solution:

crontab -e

in editor insert :

@reboot /opt/maqetta/maqetta.server.sh

save it. When you reboot/ restart your box it will launch maqetta at start.

my version is :
Version: 10
Date: May 2, 2013, 10:12:13 AM
Build: f1554971890cef6...
running Mageia 4 64 bits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment