Package: trickle
Version: 1.07-10
Followup-For: Bug #609724

Dear Maintainer,

I've created and have been using the attached init-script with the 
corresponding config file for a while with success.

Not sure if it can be added to the package, but at least they could be added to 
an "examples" directory under the package's doc one.

Regards,

-- System Information:
Debian Release: 8.0
  APT prefers testing
  APT policy: (900, 'testing'), (300, 'unstable'), (100, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 3.16.0-4-amd64 (SMP w/8 CPU cores)
Locale: LANG=en_US.utf8, LC_CTYPE=en_US.utf8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages trickle depends on:
ii  libbsd0         0.7.0-2
ii  libc6           2.19-13
ii  libevent-2.0-5  2.0.21-stable-1.1

trickle recommends no packages.

trickle suggests no packages.

-- no debconf information
#! /bin/sh
# kFreeBSD do not accept scripts as interpreters, using #!/bin/sh and sourcing.
if [ true != "$INIT_D_SCRIPT_SOURCED" ] ; then
    set "$0" "$@"; INIT_D_SCRIPT_SOURCED=true . /lib/init/init-d-script
fi
### BEGIN INIT INFO
# Provides:          trickled
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $syslog
# Should-Start:      $named $syslog
# Should-Stop:       $syslog network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Userspace bandwidth shaper
# Description:       trickled enables multiple trickle sessions in
#                    collaborative mode.
### END INIT INFO

# Author: Sebastian Cruz <defaul...@gmail.com>

# Do NOT "set -e"

# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
DESC="Userspace bandwidth shaper"
NAME=trickled
DAEMON=/usr/bin/$NAME
# The following values can be overridden in /etc/default/trickled
SOCKET=/var/run/$NAME/$NAME.socket
TRICKLED_CONF=/etc/trickled.conf
DAEMON_USER=nobody
DAEMON_GROUP=nogroup

# 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
DAEMON_ARGS="-s -n $SOCKET -c $TRICKLED_CONF $TRICKLED_OPTS"

# 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

if [ "$TRICKLED_ENABLED" != "true" ] ; then
        [ "$VERBOSE" != no ] && log_warning_msg "$NAME disabled in /etc/default/$NAME"
        exit 0
fi

create_socket_dir() {
	SOCKET_DIR="$(dirname "$SOCKET")"
	# Don't create if the directory already exists but always chown
	[ ! -d "$SOCKET_DIR" ] && mkdir -p "$SOCKET_DIR"
	chown ${DAEMON_USER}:${DAEMON_GROUP} "$SOCKET_DIR"

}

# Function that starts the daemon/service
do_start()
{
  create_socket_dir
  # Return
  #   0 if daemon has been started
  #   1 if daemon was already running
  #   2 if daemon could not be started
  start-stop-daemon --start --chuid $DAEMON_USER:$DAEMON_GROUP --chdir / --exec $DAEMON --test > /dev/null \
    || return 1
  start-stop-daemon --start --chuid $DAEMON_USER:$DAEMON_GROUP --chdir / --exec $DAEMON -- $DAEMON_ARGS \
    || return 2
  # Add code here, if necessary, that waits for the process to be ready
  # to handle requests from services started subsequently which depend
  # on this one.  As a last resort, sleep for some time.
}

# 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
  start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --exec $DAEMON
  RETVAL="$?"
  [ "$RETVAL" = 2 ] && return 2
  # Wait for children to finish too if this is a daemon that forks
  # and if the daemon is only ever run from this initscript.
  # If the above conditions are not satisfied then add some other code
  # that waits for the process to drop all resources that could be
  # needed by services started subsequently.  A last resort is to
  # sleep for some time.
  #start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
  #[ "$?" = 2 ] && return 2
  rm -Rf $SOCKET
  return "$RETVAL"
}

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)
    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}" >&2
  exit 3
  ;;
esac

exit 0
# The settings in this file are used by the program trickled as it is
# packaged for Debian. It is not used by the upstream program trickled.

# Uncomment if you want to run trickled upon bootup.
# BEWARE: you should change TRICKLED_USER and TRICKLED_GROUP below.
TRICKLED_ENABLED=true

# Choose the user id running the daemon process.
#DAEMON_USER=nobody

# Choose the group id running the daemon process.
#DAEMON_GROUP=nogroup

# Configure a non-default location of the trickled's configuration file.
#TRICKLED_CONF=/etc/trickled.conf

# The trickled socket is used by all instances of 'trickle' that are not
# running in standalone mode. You will need to specify this special location
# with the "-n" parameter of trickle.
#SOCKET=/var/run/trickled/trickled.socket

# Additional options to pass to trickled
TRICKLED_OPTS="-d 200 -u 200"

Reply via email to