File rc.apport of Package apport

#!/bin/sh

### BEGIN INIT INFO
# Provides:          apport
# Required-Start:    $local_fs $remote_fs
# Required-Stop:     $local_fs $remote_fs
# Default-Start:     2 3 5
# Default-Stop:      0 1 6
# Short-Description: Apport crash handling
# Description:       Starts and stops apport crash handling
### END INIT INFO

# Source LSB init functions
. /lib/lsb/init-functions

DESC="apport crash handling"
# The location of the apport binary
AGENT=/usr/share/apport/apport
# The location of the core pattern file
PATFILE=/proc/sys/kernel/core_pattern
# Location to save the old core_pattern
OLDPAT=/var/run/apport.old-core_pattern

set -o noclobber

# Check for missing binaries (stale symlinks should not happen)
# Note: Special treatment of stop for LSB conformance
[ -x $AGENT ] || { log_failure_msg "$AGENT not installed";
	if [ "$1" = "stop" ]; then exit 0;
	else exit 5; fi; }

# Return success if apport is already enabled
apport_is_enabled() {
    grep -q "^|.*apport" $PATFILE
}

#
# Function that starts the daemon/service
#
start_apport()
{
    if ! apport_is_enabled; then 
        [ -e /var/crash ] || {
            log_failure_msg "There is /var/crash directory missing in your system";
            exit 2; }
        cat $PATFILE > $OLDPAT
        echo "|$AGENT %p %s %c" >| /proc/sys/kernel/core_pattern
    fi
}

#
# Function that stops the daemon/service
#
stop_apport()
{
    if apport_is_enabled; then
        cat $OLDPAT >| $PATFILE
        rm -f $OLDPAT
    fi
}

case "$1" in
    start)
	  start_apport
	  touch /var/lock/subsys/apport
	  log_success_msg "Starting $DESC"
	;;
	
    stop)
	  stop_apport
	  rm -f /var/lock/subsys/apport
  	  log_success_msg "Stopping $DESC"
	;;
    restart|reload)
	  ## Stop the service and regardless of whether it was
	  ## running or not, start it again.
	  $0 stop
	  $0 start
	;;
    status)
  	  # Return value is slightly different for the status command:
	  # 0 - service up and running
	  # 1 - service dead, but /var/run/  pid  file exists
	  # 2 - service dead, but /var/lock/ lock file exists
	  # 3 - service not running (unused)
	  # 4 - service status unknown :-(
	  # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.)
	
      if grep -q 'apport' $PATFILE; then
		echo "Apport is enabled"
        exit 0
	  else
		echo "Apport is disabled"
        exit 3
	  fi
	  rc_status -v
	;;
    try-restart|condrestart)
      if [ -f /var/lock/subsys/apport ]; then
	    $0 stop
	    $0 start
      fi
    ;;	
    *)
	  echo "Usage: $0 {start|stop|status|restart|reload|try-restart|condrestart}"
	  exit 1
	;;
esac

exit 0