Changeset - 3184c6fd8713
[Not reviewed]
0 1 1
Lance Edgar - 9 years ago 2015-10-17 20:30:40
ledgar@sacfoodcoop.com
Add contrib init.d script for datasync daemon.
2 files changed with 145 insertions and 1 deletions:
0 comments (0 inline, 0 general)
MANIFEST.in
Show inline comments
 
# -*- mode: conf -*-
 

	
 
include *.txt
 
include *.rst
 

	
 
recursive-include data *
 

	
 
recursive-include rattail/data *
 

	
 
include rattail/contrib/init.d/*
 

	
 
include rattail/db/alembic/README
 
recursive-include rattail/db/alembic *.mako
 
recursive-include rattail/db/alembic *.py
rattail/contrib/init.d/datasync
Show inline comments
 
new file 100644
 
#!/bin/sh
 
# -*- coding: utf-8  -*-
 
################################################################################
 
#
 
#  Rattail -- Retail Software Framework
 
#  Copyright © 2010-2015 Lance Edgar
 
#
 
#  This file is part of Rattail.
 
#
 
#  Rattail is free software: you can redistribute it and/or modify it under the
 
#  terms of the GNU Affero General Public License as published by the Free
 
#  Software Foundation, either version 3 of the License, or (at your option)
 
#  any later version.
 
#
 
#  Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
 
#  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
#  FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for
 
#  more details.
 
#
 
#  You should have received a copy of the GNU Affero General Public License
 
#  along with Rattail.  If not, see <http://www.gnu.org/licenses/>.
 
#
 
################################################################################
 

	
 

	
 
# This script is mostly based on the ``/etc/init.d/skeleton`` file from a
 
# Debian 6 system.
 

	
 

	
 
DESC=${DESC:-"Rattail Data Synchronizer"}
 
NAME=${NAME:-"rattail-datasync"}
 
SCRIPTNAME=${SCRIPTNAME:-"/etc/init.d/$NAME"}
 
PIDFILE=${PIDFILE:-"/var/run/rattail/$NAME.pid"}
 

	
 
PYTHON=${PYTHON:-"/usr/bin/python"}
 
RATTAIL=${RATTAIL:-"/usr/local/bin/rattail"}
 
RATTAIL_ARGS=${RATTAIL_ARGS:-""}
 
DATASYNC_ARGS=${DATASYNC_ARGS:-"--pidfile=$PIDFILE"}
 

	
 
USER=${USER:-"rattail"}
 
GROUP=${GROUP:-"rattail"}
 

	
 

	
 
# Read configuration variable files if present.
 
[ -r /etc/default/rattail ] && . /etc/default/rattail
 
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
 

	
 
# Load the VERBOSE setting and other rcS variables.
 
. /lib/init/vars.sh
 

	
 
# Define LSB log_* functions.
 
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
 
# and status_of_proc is working.
 
. /lib/lsb/init-functions
 

	
 

	
 
create_pid_dir() {
 
    PIDDIR=`dirname "$PIDFILE"`
 
    if [ ! -d "$PIDDIR" ]; then
 
        mkdir --parents "$PIDDIR"
 
    fi
 
    chown $USER:$GROUP "$PIDDIR"
 
}
 

	
 

	
 
#
 
# 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
 
    create_pid_dir
 
    start-stop-daemon --start --pidfile $PIDFILE --exec $PYTHON --user $USER --test --quiet > /dev/null \
 
        || return 1
 
    start-stop-daemon --start --pidfile $PIDFILE --exec $PYTHON --startas $RATTAIL --chuid $USER --group $GROUP --quiet -- \
 
        $RATTAIL_ARGS datasync $DATASYNC_ARGS start \
 
        || 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
 
    sudo -u $USER $RATTAIL $RATTAIL_ARGS datasync $DATASYNC_ARGS stop > /dev/null 2>&1
 
}
 

	
 

	
 
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
 
        ;;
 
    status)
 
        status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
 
        ;;
 
    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
 
        ;;
 
    *)
 
        echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
 
        exit 3
 
        ;;
 
esac
 

	
 
:
0 comments (0 inline, 0 general)