#!/bin/busybox ash
#
# init.d script with LSB support.
#
# Copyright (c) 2007 Javier Fernandez-Sanguino <jfs@debian.org>
# Copyright (c) 2008 Axel Beckert <abe@deuxchevaux.org>
# Copyright (c) 2023 Michael Tokarev <mjt@tls.msk.ru>
#
# This is free software; you may redistribute it and/or modify
# it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2,
# or (at your option) any later version.
#
# This is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License with
# the Debian operating system, in /usr/share/common-licenses/GPL;  if
# not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA
#
### BEGIN INIT INFO
# Provides:          busybox-syslogd syslogd
# Required-Start:    $remote_fs
# Required-Stop:     $remote_fs
# Should-Start:      
# Should-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Starts syslogd
# Description:       Starts the busybox syslogd
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

NAME=syslogd
DAEMON=/sbin/$NAME
DESC="busybox' $NAME implementation"

test -x $DAEMON || exit 0

. /lib/lsb/init-functions

SYSLOG_OPTS=	# Additional options given to the server
# Include defaults if available
if [ -f /etc/default/busybox-syslogd ] ; then
	. /etc/default/busybox-syslogd
fi
PIDFILE=/var/run/$NAME.pid

server() {
	case "$1" in
		(start) args="-S -o -c root:adm" ;;
		(stop)  args="-K -o -q" ;;
		(check) args="-K -t -q" ;;
	esac
	umask 0026
	busybox start-stop-daemon $args -p $PIDFILE \
		-x $DAEMON -- $SYSLOG_OPTS
}

case "$1" in
    start)
	log_daemon_msg "Starting $DESC " "$NAME"
	if server start ; then
		log_end_msg 0
	else
		log_end_msg 1
		exit 1
	fi
	# undo umask
	chmod 0644 $PIDFILE 2>/dev/null || :
	;;
    stop)
	log_daemon_msg "Stopping $DESC" "$NAME"
	if server stop ; then
		log_end_msg 0
	else
		log_end_msg 1
		exit 1
	fi
	;;
    restart|force-reload)
	"$0" stop
	exec "$0" start
	;;
    status)
	log_daemon_msg "Checking status of $DESC" "$NAME"
	if server check ; then
		log_progress_msg "running"
		log_end_msg 0
	else
		log_progress_msg "apparently not running"
		log_end_msg 1
		exit 1
	fi
	;;
    # daemon cannot reload
    reload)
	log_warning_msg "Reloading $NAME daemon: not implemented, as the daemon"
	log_warning_msg "cannot re-read the config file (use restart)."
	;;
    *)
	echo "Usage: /etc/init.d/busybox-$NAME {start|stop|restart|force-reload|status}" >&2
	exit 1
	;;
esac

exit 0
