diff -urN openplacos.orig/setup_files/openplacos openplacos/setup_files/openplacos --- openplacos.orig/setup_files/openplacos 2011-12-07 08:31:51.000000000 +0100 +++ openplacos/setup_files/openplacos 2012-02-21 16:21:47.000000000 +0100 @@ -1,31 +1,53 @@ -#!/bin/bash +#!/sbin/runscript +# Copyright 1999-2011 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Header: $ -case "$1" in - start) - echo "Starting OpenplacOS" - su -l openplacos -s /bin/sh -c "/usr/bin/openplacos-server /etc/default/openplacos > /tmp/openplacos.log &" - if [ $? -gt 0 ]; then - exit 1 - else - exit 0 - fi - ;; - stop) - echo "Stopping OpenplacOS" - pkill openplacos -u openplacos - if [ $? -gt 0 ]; then - exit 1 - else - exit 0 - fi - - ;; - restart) - $0 stop - sleep 1 - $0 start - ;; - *) - echo "usage: $0 {start|stop|restart}" -esac -exit 0 +DESCRIPTION="This utility is used to create a low cost home automation system controlled by computer" +HOMEPAGE="http://openplacos.tuxfamily.org" + +SVCNAME="openplacos-server" +USER=openplacos +DAEMON=$(which ${SVCNAME}) +PIDFILE=/var/run/openplacos.pid +CONFIGFILE=/etc/default/openplacos +LOGFILE=/tmp/openplacos.log + +depend() { + need dbus mysql + after logger +} + +checkconfig() { + if [ ! -r ${CONFIGFILE} ]; then + eerror "ERROR: Unable to read configuration file: ${CONFIGFILE}" + return 1 + fi +} + +checkprocess() { + if [ $(ps ax | grep ${SVCNAME} | grep -v grep | wc -l) -eq 0 ]; then + eerror "ERROR: Please, check logfile: ${LOGFILE}" + return 1 + fi +} + +start() { + checkconfig || return $? + + ebegin "Starting openplacos" + export OPOS_DEBUG=1 + start-stop-daemon --start --user ${USER} --exec ${DAEMON} \ + --pidfile ${PIDFILE} --make-pidfile --background --stdout ${LOGFILE} + + sleep 3 + checkprocess || return $? + + eend $? "Failed to start openplacos !" +} + +stop() { + ebegin "Stopping openplacos" + start-stop-daemon --stop --quiet --user ${USER} --exec ${DAEMON} --pidfile ${PIDFILE} + eend $? "Failed to stop openplacos !" +}