#!/bin/sh -e
@%@UCRWARNING=# @%@
#
# Univention Samba
#  init script
#
# SPDX-FileCopyrightText: 2017-2025 Univention GmbH
# SPDX-License-Identifier: AGPL-3.0-only
#
#
# samba         start/stop samba services
#
### BEGIN INIT INFO
# Provides:          samba
# Required-Start:    $network $local_fs $remote_fs
# Required-Stop:     $network $local_fs $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Should-Start:      slapd cups
# Should-Stop:       slapd cups
# Short-Description: ensure Samba daemons are started (nmbd and smbd)
### END INIT INFO

## This is a convenience script, not a real init script,
## so don't load /lib/lsb/init-functions.d/40-systemd
# . /lib/lsb/init-functions

# start nmbd and smbd unconditionally
# the init scripts themselves check if they are needed or not
case $1 in
	start)
		/etc/init.d/nmbd start
		/etc/init.d/smbd start
		;;
	stop)
		/etc/init.d/smbd stop
		/etc/init.d/nmbd stop
		;;
	reload)
		echo "Reloading smbd."
		/etc/init.d/smbd reload
		;;
	restart|force-reload)
		$0 stop
		sleep 1
		$0 start
		;;
	status)
		status=0
		NMBD_DISABLED=`testparm -s --parameter-name='disable netbios' 2>/dev/null || true`
		if [ "$NMBD_DISABLED" != "Yes" ]; then
			/etc/init.d/nmbd status || status=$?
		fi
		/etc/init.d/smbd status || status=$?
		exit $status
		;;
	*)
		echo "Usage: /etc/init.d/samba {start|stop|reload|restart|force-reload|status}"
		exit 1
		;;
esac
