Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #168816

Re: Linux startup, Wheezy -- a required script won't run on startup, but can run manually without any trouble

From Andrew McGlashan <andrew.mcglashan@affinityvision.com.au>
Newsgroups linux.debian.user
Subject Re: Linux startup, Wheezy -- a required script won't run on startup, but can run manually without any trouble
Date 2016-06-11 06:10 +0200
Message-ID <rIIpb-6Cf-5@gated-at.bofh.it> (permalink)
References <rIcfD-18x-3@gated-at.bofh.it> <rIfQf-3Cu-77@gated-at.bofh.it> <rInE5-Cy-11@gated-at.bofh.it> <rIoTw-1zi-9@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

All good now:

# cat /etc/init.d/archive-system-mail
#! /bin/sh
### BEGIN INIT INFO
# Provides:          mailarchive
# Required-Start:    $local_fs $remote_fs $syslog
# Required-Stop:     $local_fs $remote_fs $syslog
# X-Start-Before:    exim4 dovecot
# X-Stop-After:      exim4 dovecot
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Save exim4 system_filter archive
# Description:       This file should be ran at boot time before either
#                    exim4 or dovecot is started.  It saves mail that is
#                    created via rules within the /etc/system_filter and
#                    it's related log file.
### END INIT INFO

# Author: Andrew McGlashan <andrew.mcglashan@affinityvision.com.au>

# set -x

#
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
DESC="Save exim4 system_filter archive"
NAME=archive-system-mail
DAEMON=/usr/local/sbin/$NAME
SCRIPTNAME=/etc/init.d/$NAME

# Exit if the package is not installed
[ -x "$DAEMON" ] || 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
. /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

case "$1" in
        start)
                # Run the required script
                $DAEMON
                ;;
        stop|status|restart|force-reload)
                exit 0
                ;;
        *)
                echo "Usage: $SCRIPTNAME {start}" >&2
                exit 3
                ;;
esac

:



And the script itself:
# cat /usr/local/sbin/archive-system-mail
#! /bin/sh

do_cleanup()
{
        # Cleanup
        echo -e "\a\a\aPerforming cleanup"
        exit $1
}

do_error_exit()
{
        # Display error message and exit
        echo "${PROGNAME}: ${1:-"Unknown Error"}" 1>&2
        do_cleanup 1
}

do_get_archivedir()
{
        for VER in a b c d e f g h i j k l m n o p q r s t u v w x y z
        do

ARCHIVE_DIR=/backup/mail/system_filter_all_mail/archive/${DATEX}${VER}
                [ ! -d ${ARCHIVE_DIR} ] && return 0
        done
        return 1
}

# main
trap "do_cleanup 99" HUP INT TERM

# Global Variables
ARCHIVE_DIR=
DATEX=$(/bin/date +%Y%m%d)
PROGNAME=$(/usr/bin/basename $0)

[ -r /backup/mail/system_filter_all_mail/log--lots ] || do_error_exit
"Missing or unreadable SOURCE log--lots file"

(
        # Exit if the we cannot get a suitable archive directory
        do_get_archivedir       || do_error_exit "Cannot get archive dir"

        [ ! -d ${ARCHIVE_DIR} ] && /bin/mkdir ${ARCHIVE_DIR}
        [   -d ${ARCHIVE_DIR} ] || do_error_exit "The required archive
directory wasn't created as expected"

        (
        # Exit if the we cannot cd in to the archive directory
        cd ${ARCHIVE_DIR}       || do_error_exit "Cannot cd in to the
archive directory"

        /bin/mv /backup/mail/system_filter_all_mail/log--lots .
        [ -r log--lots ]        || do_error_exit "Missing or unreadable
archive copy of log--lots file"

        /bin/mv /backup/mail/system_filter_all_mail/Maildir   .
        [ -d Maildir ]          || do_error_exit "Missing archive of
Maildir folder"

        # Fix log--lots file to have only ONE line per record, in cases
where system_filter wrote multi-lines
        TMP_LOG_LOTS=${ARCHIVE_DIR}/log--lots.$$
        /usr/bin/touch -r log--lots $TMP_LOG_LOTS
        echo '' >> log--lots
        sed -i -e ':a' -e 'N' -e '$!ba' -e 's/\n[\t\ *]/\ /g' log--lots
        sed -i -e '/^$/d' log--lots
        /usr/bin/touch -r $TMP_LOG_LOTS log--lots

        /bin/ls -ladrt /backup/mail/system_filter_all_mail/log--lots
${ARCHIVE_DIR}/*
        )
)  2>&1 | /usr/bin/tee /var/log/${PROGNAME}--$(date +%Y%m%d%H%M%S).log



Cheers
AndrewM

Back to linux.debian.user | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Linux startup, Wheezy -- a required script won't run on startup, but  can run manually without any trouble Andrew McGlashan <andrew.mcglashan@affinityvision.com.au> - 2016-06-09 19:50 +0200
  Re: Linux startup, Wheezy -- a required script won't run on  startup, but  can run manually without any trouble Dan Purgert <dan@djph.net> - 2016-06-09 21:20 +0200
    Re: Linux startup, Wheezy -- a required script won't run on startup,  but can run manually without any trouble Andrew McGlashan <andrew.mcglashan@affinityvision.com.au> - 2016-06-09 21:30 +0200
      Re: Linux startup, Wheezy -- a required script won't run on  startup,  but can run manually without any trouble Dan Purgert <dan@djph.net> - 2016-06-09 22:30 +0200
        Re: Linux startup, Wheezy -- a required script won't run on startup,  but can run manually without any trouble Andrew McGlashan <andrew.mcglashan@affinityvision.com.au> - 2016-06-09 22:40 +0200
          Re: Linux startup, Wheezy -- a required script won't run on  startup,  but can run manually without any trouble Dan Purgert <dan@djph.net> - 2016-06-09 23:10 +0200
            Re: Linux startup, Wheezy -- a required script won't run on startup,  but can run manually without any trouble Nicholas Geovanis <nickgeovanis@gmail.com> - 2016-06-09 23:30 +0200
        Re: Linux startup, Wheezy -- a required script won't run on startup,  but can run manually without any trouble Mark Neyhart <Mark.Neyhart@akleg.gov> - 2016-06-09 23:30 +0200
  Re: Linux startup, Wheezy -- a required script won't run on startup,  but can run manually without any trouble Brian <ad44@cityscape.co.uk> - 2016-06-09 21:30 +0200
    Re: Linux startup, Wheezy -- a required script won't run on startup,  but can run manually without any trouble Andrew McGlashan <andrew.mcglashan@affinityvision.com.au> - 2016-06-09 21:40 +0200
      Re: Linux startup, Wheezy -- a required script won't run on startup,  but can run manually without any trouble Brian <ad44@cityscape.co.uk> - 2016-06-09 22:10 +0200
        Re: Linux startup, Wheezy -- a required script won't run on startup,  but can run manually without any trouble Andrew McGlashan <andrew.mcglashan@affinityvision.com.au> - 2016-06-09 22:20 +0200
          Re: Linux startup, Wheezy -- a required script won't run on startup,  but can run manually without any trouble Christian Seiler <christian@iwakd.de> - 2016-06-10 00:40 +0200
            Re: Linux startup, Wheezy -- a required script won't run on startup,  but can run manually without any trouble Mart van de Wege <mvdwege@gmail.com> - 2016-06-10 10:20 +0200
  Re: Linux startup, Wheezy -- a required script won't run on startup,  but can run manually without any trouble Christian Seiler <christian@iwakd.de> - 2016-06-09 23:40 +0200
    Re: Linux startup, Wheezy -- a required script won't run on startup,  but can run manually without any trouble Andrew McGlashan <andrew.mcglashan@affinityvision.com.au> - 2016-06-10 08:00 +0200
      Re: Linux startup, Wheezy -- a required script won't run on startup,  but can run manually without any trouble Christian Seiler <christian@iwakd.de> - 2016-06-10 09:20 +0200
        Re: Linux startup, Wheezy -- a required script won't run on startup,  but can run manually without any trouble Andrew McGlashan <andrew.mcglashan@affinityvision.com.au> - 2016-06-11 06:10 +0200

csiph-web