#!/bin/sh
#
# service-restart -- Wrapper for /etc/init.d/service restart discarding noise.
#
# Written by Russ Allbery <rra@stanford.edu>
# Copyright 2008 Board of Trustees, Leland Stanford Jr. University

# Exit on any error.
set -e

# Our one and only argument is the name of the service.
service="$1"
if [ -z "$service" ] || [ -n "$2" ] ; then
    echo 'Usage: service-restart <service>' >&2
    exit 1
fi

# Make sure it exists.
if [ ! -x "/etc/init.d/$service" ] ; then
    echo "/etc/init.d/$service not found" >&2
    exit 1
fi

# Run it.
exec "/etc/init.d/$service" restart >/dev/null


# Documentation.  Use a hack to hide this from the shell.  Because of the
# above exec line, this should never be executed.
DOCS=<<__END_OF_DOCS__

=for stopwords
Allbery init newsyslog

=head1 NAME

service-restart - Wrapper for /etc/init.d/service restart, discarding noise

=head1 SYNOPSIS

B<service-restart> I<service>

=head1 DESCRIPTION

B<service-restart> runs the F</etc/init.d> script for I<service> with the
restart option and redirects all standard output to F</dev/null>.  It's
intended for use with B<newsyslog> when the init script is the best way to
restart a service during log rotation, since B<newsyslog> has no way to
throw away standard output currently.

=head1 SEE ALSO

newsyslog(8)

=head1 AUTHOR

Russ Allbery <rra@stanford.edu>

=cut

__END_OF_DOCS__
