Page MenuHomePhorge

Create a SysVInit script for guam
Closed, ResolvedPublic

Description

Guam needs a sysvinit script for Trusty and Santiago, or needs to be started manually.

Details

Ticket Type
Task

Event Timeline

I've tried to create an init script, but as I don't really understand how erlang things are started / stopped, I have to give up here. That's what I achieved so far:

#!/bin/sh

### BEGIN INIT INFO
# Provides:	  guam
# Required-Start:    $local_fs $remote_fs $network $syslog $named
# Required-Stop:     $local_fs $remote_fs $network $syslog $named
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the guam imap proxy
# Description:       starts guam using start-stop-daemon
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/guam
DAEMON_OPTS="foreground"
NAME=guam
DESC=guam
PID=/run/guam.pid
HOME=/opt/kolab_guam/

# Include guam defaults if available
if [ -r /etc/default/guam ]; then
	. /etc/default/guam
fi

test -x $DAEMON || exit 0

. /lib/init/vars.sh
. /lib/lsb/init-functions

#
# 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
	start-stop-daemon --start --quiet --pidfile $PID --exec $DAEMON --background -- \
		$DAEMON_OPTS 2>/dev/null \
		|| 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 $PID --name $NAME
	RETVAL="$?"

	sleep 1
	return "$RETVAL"
}

case "$1" in
	start)
		[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
		do_start
		case "$?" in
			0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
			2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
		esac
		;;
	stop)
		[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
		do_stop
		case "$?" in
			0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
			2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
		esac
		;;
	restart)
		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)
		status_of_proc -p $PID "$DAEMON" "$NAME" && exit 0 || exit $?
		;;
	*)
		echo "Usage: $NAME {start|stop|restart|reload|force-reload|status|configtest|rotate|upgrade}" >&2
		exit 3
		;;
esac
:

The problem is that the script is not able to track the process PID. Starting works, but then Guam seems to fork and the start-stop-daemon looses track of it. What would be the right (tm) way to do it?
This missing init script is a blocker on our side to upgrade to the latest Kolab release =(

petersen added a project: Restricted Project.May 2 2016, 2:49 PM
petersen raised the priority of this task from 60 to High.May 11 2016, 9:25 AM

@toru Can you please sugget this as a differential: https://docs.kolab.org/contributor-guide/peer-review.html

Then we can get it reviewed.

We installed new guam version guam.x86_64 0:0.7.3-4.1.el6.kolab_14 and get an init script but this is not executable by default. After chmod 555 it's executable but complains about some "erlexec: HOME must be set".

Is it correct that the init script is "rw"-max permission and that HOME is not set/defined after simple "yum install guam"?

/opt/kolab_guam/log/erlang.log.1:

LOGGING STARTED Fri Jun 17 12:41:39 CEST 2016

Exec: /opt/kolab_guam/erts-6.3/bin/erlexec -boot /opt/kolab_guam/releases/0.7.3/kolab_guam -mode embedded -config /opt/kolab_guam/releases/0.7.3/sys.config -args_file /opt/kolab_guam/releases/0.7.3/vm.args -- console
Root: /opt/kolab_guam
erlexec: HOME must be set

bash history:
~ # ll /etc/init.d/guam
-rw-r--r-- 1 root root 1896 Jun 8 14:19 /etc/init.d/guam

~ # ll /etc/init.d/guam
-r-xr-xr-x 1 root root 1896 Jun 8 14:19 /etc/init.d/guam

~ # service guam start
Starting guam
erlexec: HOME must be set
..........Unable to start

seigo claimed this task.