Samba does not start on boot.

Bug #125687 reported by Adam
46
This bug affects 3 people
Affects Status Importance Assigned to Milestone
samba (Ubuntu)
Fix Released
Medium
Unassigned

Bug Description

I am running Kubuntu Feisty Fawn with kernel 2.6.20-16-generic.
Current Samba package version is 3.0.24-2ubuntu1.2.

Samba does not start on boot. I have to manually enter sudo /etc/init.d/samba start in order for anyone to browse my machine. A workaround, although I find this unacceptable, seems to be to add a "sleep 30" or similar line under "start)" in the init.d script.

Revision history for this message
Alvin Cura (alvinc) wrote :

This problem is persisting in Gutsy as well.

I am suspecting race conditions with upstart as root cause. I will run test cases with sysvinit and see what the results are.

Revision history for this message
Alvin Cura (alvinc) wrote :

Did some searching. Possible similarities to Bug #84537. Also, mlind has a comment in Bug #25931 that sounds somewhat similar. I will run a couple of use tests by tomorrow.

Revision history for this message
Alvin Cura (alvinc) wrote :

Confirmed that replacing upstart with sysvinit eliminates the problem. This is no fix, but it does seem to point at upstart.

HOST INFO:
# uname -a
Linux mpk-acura1 2.6.22-14-generic #1 SMP Sun Oct 14 23:05:12 GMT 2007 i686 GNU/Linux
root@mpk-acura1:/var/log/apt# cat /etc/issue
Ubuntu 7.10 \n \l

//*** BEGIN APTITUDE LOG

[REMOVE, DEPENDENCIES] apparmor
[REMOVE, DEPENDENCIES] apparmor-utils
[REMOVE, DEPENDENCIES] startup-tasks
[REMOVE, DEPENDENCIES] system-services
[REMOVE, DEPENDENCIES] ubuntu-minimal
[REMOVE, DEPENDENCIES] ubuntu-standard
[REMOVE, DEPENDENCIES] upstart
[REMOVE, DEPENDENCIES] upstart-compat-sysv
[REMOVE, DEPENDENCIES] upstart-logd
[HOLD] firefox
[HOLD] firefox-gnome-support
[HOLD] libc6
[HOLD] libc6-i686
[HOLD] libssl0.9.8
[HOLD] nscd
[HOLD] samba
[HOLD] tzdata
[HOLD] ubufox
[HOLD] winbind
[INSTALL] sysvinit

//*** END APTITUDE LOG

//*** BEGIN APT LOG
Log started: 2007-11-19 18:28:39
(Reading database ... 169744 files and directories currently installed.)
Removing apparmor-utils ...
Removing apparmor ...
Unloading AppArmor profiles : done.
update-initramfs: deferring update (trigger activated)
Removing iputils-arping ...
Removing librpc-xml-perl ...
Removing libterm-readkey-perl ...
Removing ubuntu-minimal ...
Removing startup-tasks ...
Removing system-services ...
Removing ubuntu-standard ...
Removing upstart-logd ...
Removing upstart-compat-sysv ...
Removing upstart ...
Processing triggers for initramfs-tools ...
update-initramfs: Generating /boot/initrd.img-2.6.22-14-rt
Selecting previously deselected package sysvinit.
(Reading database ... 169539 files and directories currently installed.)
Unpacking sysvinit (from .../sysvinit_2.86.ds1-14.1ubuntu31_i386.deb) ...
Setting up sysvinit (2.86.ds1-14.1ubuntu31) ...

//*** END APT LOG

Revision history for this message
Alvin Cura (alvinc) wrote :

My second test did not fare so well. Even with sysvinit, there seems to be a race condition with samba.

I believe the right course it to put logic into the startup script to wait for the network. In my first test case, spanning-tree portfast was set on the switch in question, which leads to faster negotiation times at layer 2 on the network.

My second test case did a full auto-negotiate, leading me to believe that having samba wait for network state may be the right thing to do.

Revision history for this message
Peter Cordes (peter-cordes) wrote :

I was just going to report the same bug. I've seen this on Ubuntu Feisty, and I still see it on Gutsy. The problem I've seen seems to be that on DHCP client machines, it can take some time for network interfaces other than loopback to come up. The networking init script (which runs ifup -a) doesn't seem to wait for DHCP to finish getting an IP before letting later stuff run.

 This is a problem for programs which depend on specific interfaces existing. I have e.g. samba configured with
   interfaces = 127.0.0.1/8 10.255.255.255/8
   bind interfaces only = true

 so if those interfaces aren't up, nmbd doesn't start at all. smbd can start but only be listening on loopback because eth0 didn't have an IP when it started.

I hacked around it in the past once on a desktop I installed for a colleague with a script that waited for the network to come up:

--------
#!/bin/sh
# sleep long enough for networking to come up before ntp, firestarter, etc.

# /sbin/ifconfig

echo "waiting for network"
timeout=20
while ! /sbin/ifconfig | grep -q '129\.173';do
        sleep 1
        timeout=$(( $timeout - 1 ))
        if [ $timeout -lt 1 ];then
                echo "timeout waiting for network"
                return 1
        fi
done
echo "done waiting for network"
---------------

 I think I sourced it from some other init script, hence the return instead of exit.

 On my home server/desktop, which gets an IP via DHCP from my firewall/other server, I use /etc/rc.local as a convenient place to put
(sleep 60 && /etc/init.d/samba restart)&
 I have to say restart, not just start, because smbd can start bound to the loopback interface only, and "start" will just leave it running.

 Obviously these are not proper solutions, but I hope this helps understand the problem.

 I don't think I've seen the problem when I've changed /etc/network/interfaces to use a static IP for the machine.

Revision history for this message
Alexander Jones (alex-weej) wrote :

Same in Hardy. (Also had it in Gutsy.)

Revision history for this message
Emmet Caulfield (emmetcaulfield) wrote :

Me too (Gutsy/amd64). This is a real PITA.

Revision history for this message
Alexander Jones (alex-weej) wrote :

This problem has fixed itself for me lately in Hardy. Try seeing if your local loopback interface is up.

ifconfig lo

Revision history for this message
Emmet Caulfield (emmetcaulfield) wrote :

Alex,

Thanks for that. Yes, I had that problem a while back (it caused me problems with hddtemp daemon), so it's not that this time around, I'm pretty sure.

Now, FWIW, I've written a quick'n'dirty script that makes samba wait at startup until the interfaces listed in "interfaces = " in smb.conf are all up.

I've written this as a separate script that I keep in /usr/local/sbin/samba-netif-wait (attached) and I just stick a call to it into /etc/init.d/samba (as per the diff below). I've done it this way so I can easily re-use it if/when /etc/init.d/samba gets clobbered by an update.

It works for me, causes no noticeable delay at boot-time, and might help someone else before this is fixed properly... if that ever happens.

Emmet.

--==[ BEGIN PATCH ]==--------------------------------------------------
--- /etc/init.d/samba~ 2007-11-16 22:23:59.000000000 +0100
+++ /etc/init.d/samba 2007-12-13 17:52:23.000000000 +0100
@@ -31,6 +31,10 @@
 case "$1" in
        start)
                log_daemon_msg "Starting Samba daemons"
+ if ! /usr/local/sbin/samba-netif-wait; then
+ log_failure_msg "Network interfaces implied by smb.conf are not up"
+ exit 1
+ fi
                # Make sure we have our PIDDIR, even if it's on a tmpfs
                 install -o root -g root -m 755 -d $PIDDIR

--==[ END PATCH ]==------------------------------------------------------

Revision history for this message
Steve Langasek (vorlon) wrote :

Upstream has made some adjustments to nmbd in samba 3.0.28a so that it will wait when the interfaces have gone away, but I don't know if this affects the behavior on startup.

If it doesn't, then I think what we want here is an if-up.d script to try to start nmbd whenever the network comes back.

Changed in samba:
importance: Undecided → Medium
status: New → Confirmed
Steve Langasek (vorlon)
Changed in samba:
assignee: nobody → ubuntu-server
Revision history for this message
Peter Cordes (peter-cordes) wrote :

> Upstream has made some adjustments to nmbd in samba 3.0.28a so that it will wait when the interfaces have gone away, but I don't know if this affects the behavior on startup.

 This doesn't solve the problem for the ntpdate init script, for example. There's a general problem that numbering scripts with numbers higher than rcS.d/S40networking doesn't mean that dhcp will have an IP by the time they run.

 That's why I wrote that little init script that waits until it can ping something before it returns, so the firestarter and ntp init scripts could work properly. If this problem goes away for samba because of something samba-specific way, this bug should be duplicated or a new one reported.

Revision history for this message
Chuck Short (zulcss) wrote :

This should be already fixed in hardy. Thanks for the bug report.

Regards
chuck

Changed in samba:
status: Confirmed → Fix Released
Revision history for this message
Peter Cordes (peter-cordes) wrote :

> This should be already fixed in hardy.

 It isn't totally fixed, unless samba is supposed to start before interfaces are configured by DHCP, and that doesn't count as a bug.

my smb.conf has
   interfaces = 127.0.0.1/8 10.255.255.255/8
   bind interfaces only = true

 so eth0 _has_ to be up and configured by DHCP before smbd starts, or it will end up listening only on the loopback interface. I put this hack at the end of my /etc/rc.local
(sleep 60 && /etc/init.d/samba restart)&

 After every boot, one of smbd and nmbd has already exitted by the time the restart happens. Sorry I don't remember which. My hack does get both started properly, though, since networking is always up by then.

debsums -a samba shows that my /etc/init.d/samba is the Ubuntu package version (3.0.28a-1ubuntu4.4).

Changed in samba:
status: Fix Released → In Progress
Thierry Carrez (ttx)
Changed in samba:
assignee: ubuntu-server → nobody
status: In Progress → Confirmed
Revision history for this message
Michael Terry (mterry) wrote :

I fixed this in Hardy with the attached if-up.d script.

I can't reproduce in Jaunty though. Can anyone else? If not, I suspect this should be closed.

Revision history for this message
Alexander Jones (alex-weej) wrote : Re: [Bug 125687] Re: Samba does not start on boot.

No, this is good to close.

Thierry Carrez (ttx)
Changed in samba (Ubuntu):
status: Confirmed → Fix Released
Revision history for this message
BikeHelmet (bikehelmet) wrote :

Hi. I experienced this exact problem in Ubuntu 9.04, today.

While attempting to try to fix it I killed my network connection somehow and had to remove & purge package network-manager.

All is well now, though. For anyone that's a newbie like me, here's how I fixed it.

These three terminal commands were necessary:

sudo /etc/init.d/networking restart
sudo gedit /etc/resolv.conf
sudo gedit /etc/network/interfaces

1) Restarts networking. Saves you a reboot after changing settings and trying to get it to work. Also spat out helpful debug messages - helpful in the sense I could google them, and ended up here. ;)
2) Opens config file, where you can enter your router IP. I entered this:

nameserver 192.168.1.1

3) Opens a config file, where you can set up static IP stuff. Note that I have two gigabit ethernet ports. Internet won't work unless you add "auto eth#" for the port you have plugged in. Also, according to an article I read, if your connection ever breaks after a kernel update, the kernel may have flipped how it orders interfaces, so you should try plugging the cable into the other port. I entered this:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 192.168.1.116
netmask 255.255.255.0
gateway 192.168.1.1

iface eth1 inet static
address 192.168.1.115
netmask 255.255.255.0
gateway 192.168.1.1

Works like a charm now, and Samba starts correctly at boot.

Revision history for this message
the_vorpal_blade (the-vorpal-blade) wrote :

The problem still exists in jaunty for me. Switching to using /etc/network/interfaces over Network Manager would work to fix it, but its still broken by default.

Changed in samba (Ubuntu):
status: Fix Released → Confirmed
Revision history for this message
Thierry Carrez (ttx) wrote :

This bug was confirmed fixed, the issue in Jaunty is a new issue. Maybe a duplicate of bug 462169. In doubt please open a new bug.

Changed in samba (Ubuntu):
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.