#!/bin/sh

do_tmpfiles() {
    local type path mode user group

    TMPFILES=/usr/lib/tmpfiles.d/$1.conf

    if [ -r "$TMPFILES" ]; then
	while read type path mode user group; do
            if [ "$type" = "d" ]; then
                mkdir -p "$path"
		chmod "$mode" "$path"
                chown "$user:$group" "$path"
            fi
        done
    fi
}

do_start_prepare() {
    do_tmpfiles $(basename $0)
}

do_start_override() {
    if [ "$DO_START" != "yes" ]; then
	return 2
    fi

    if call do_status >/dev/null 2>&1; then
	return 1
    fi
    
    
    if $DAEMON start $DAEMON_ARGS; then
	return 0
    else
	return 2
    fi
}

do_stop_override() {
    if ! call do_status >/dev/null 2>&1; then
	return 1
    fi
    
    if $DAEMON stop $DAEMON_ARGS; then
	return 0;
    else
	return 2;
    fi
}
