Last active
June 25, 2022 17:46
-
-
Save touhonoob/5784297 to your computer and use it in GitHub Desktop.
Samba4 Configuration & init script
https://wiki.samba.org/index.php/Samba4/InitScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://wiki.samba.org/index.php/Samba_4/OS_Requirements#Debian_or_Ubuntu | |
http://www.samba.org/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
### 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 | |
# Should-Stop: slapd | |
# Short-Description: start Samba daemons (nmbd and smbd) | |
### END INIT INFO | |
# Description of this script: | |
# | |
# This script comes initially from a Debian Squeeze machine on | |
# which samba 3.x was installed with "apt-get install samba". The script | |
# was modified/adjusted so it points to the correct paths of a default | |
# samba4 installation (/usr/local/samba). | |
# | |
# Installation instructions: | |
# (1) copy the content of this script into your clipboard or download it | |
# (2) save the content into /etc/init.d/samba of your samba4 host. | |
# (3) execute "chmod +x /etc/init.d/samba" to have the script executable | |
# (4) execute "update-rc.d samba defaults" to install auto-start function. | |
# smbd+nmbd will automatically being started after earch system start/reboot | |
# | |
# Modified by local@#samba~irc.freenode.net at 06th March 2013 | |
# The script was successfully tested on Debian GNU/Linux Squeeze+Wheezy | |
# Defaults | |
RUN_MODE="daemons" | |
# Reads config file (will override defaults above) | |
[ -r /etc/default/samba ] && . /etc/default/samba | |
PIDDIR=/usr/local/samba/var/run | |
NMBDPID=$PIDDIR/nmbd.pid | |
SMBDPID=$PIDDIR/smbd.pid | |
# clear conflicting settings from the environment | |
unset TMPDIR | |
# See if the daemons are there | |
test -x /usr/local/samba/sbin/nmbd -a -x /usr/local/samba/sbin/smbd || exit 0 | |
. /lib/lsb/init-functions | |
case "$1" in | |
start) | |
log_daemon_msg "Starting Samba daemons" | |
# Make sure we have our PIDDIR, even if it's on a tmpfs | |
install -o root -g root -m 755 -d $PIDDIR | |
NMBD_DISABLED=`testparm -s --parameter-name='disable netbios' 2>/dev/null` | |
if [ "$NMBD_DISABLED" != 'Yes' ]; then | |
log_progress_msg "nmbd" | |
if ! start-stop-daemon --start --quiet --oknodo --exec /usr/local/samba/sbin/nmbd -- -D | |
then | |
log_end_msg 1 | |
exit 1 | |
fi | |
fi | |
if [ "$RUN_MODE" != "inetd" ]; then | |
log_progress_msg "smbd" | |
if ! start-stop-daemon --start --quiet --oknodo --exec /usr/local/samba/sbin/smbd -- -D; then | |
log_end_msg 1 | |
exit 1 | |
fi | |
fi | |
log_end_msg 0 | |
;; | |
stop) | |
log_daemon_msg "Stopping Samba daemons" | |
log_progress_msg "nmbd" | |
start-stop-daemon --stop --quiet --pidfile $NMBDPID | |
# Wait a little and remove stale PID file | |
sleep 1 | |
if [ -f $NMBDPID ] && ! ps h `cat $NMBDPID` > /dev/null | |
then | |
# Stale PID file (nmbd was succesfully stopped), | |
# remove it (should be removed by nmbd itself IMHO.) | |
rm -f $NMBDPID | |
fi | |
if [ "$RUN_MODE" != "inetd" ]; then | |
log_progress_msg "smbd" | |
start-stop-daemon --stop --quiet --pidfile $SMBDPID | |
# Wait a little and remove stale PID file | |
sleep 1 | |
if [ -f $SMBDPID ] && ! ps h `cat $SMBDPID` > /dev/null | |
then | |
# Stale PID file (nmbd was succesfully stopped), | |
# remove it (should be removed by smbd itself IMHO.) | |
rm -f $SMBDPID | |
fi | |
fi | |
log_end_msg 0 | |
;; | |
reload) | |
log_daemon_msg "Reloading /usr/local/samba/etc/smb.conf" "smbd only" | |
start-stop-daemon --stop --signal HUP --pidfile $SMBDPID | |
log_end_msg 0 | |
;; | |
restart|force-reload) | |
$0 stop | |
sleep 1 | |
$0 start | |
;; | |
status) | |
status="0" | |
NMBD_DISABLED=`testparm -s --parameter-name='disable netbios' 2>/dev/null` | |
if [ "$NMBD_DISABLED" != "Yes" ]; then | |
status_of_proc -p $NMBDPID /usr/local/samba/sbin/nmbd nmbd || status=$? | |
fi | |
if [ "$RUN_MODE" != "inetd" ]; then | |
status_of_proc -p $SMBDPID /usr/local/samba/sbin/smbd smbd || status=$? | |
fi | |
if [ "$NMBD_DISABLED" = "Yes" -a "$RUN_MODE" = "inetd" ]; then | |
status="4" | |
fi | |
exit $status | |
;; | |
*) | |
echo "Usage: /etc/init.d/samba {start|stop|reload|restart|force-reload|status}" | |
exit 1 | |
;; | |
esac | |
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Global parameters | |
[global] | |
workgroup = WORKGROUP | |
netbios name = UBUNTU | |
wins support = yes | |
client lanman auth = yes | |
security = user | |
passdb backend = tdbsam | |
# http://0x00.sinaapp.com/post/118 | |
oplocks = no | |
level2 oplocks = no | |
[www] | |
valid users = www | |
browseable = yes | |
writable = yes | |
hosts allow = 192.168.1.0/24 | |
public = yes | |
guest ok = yes | |
read only = no | |
create mask = 0775 | |
directory mask = 0775 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment