Samba fails to start at boot when not connected to network (and specific interfaces are configured)

Bug #374589 reported by David Harel
48
This bug affects 9 people
Affects Status Importance Assigned to Milestone
samba (Ubuntu)
Triaged
Wishlist
Unassigned

Bug Description

Binary package hint: samba

When my laptop boots network is not yet configured since NM didn´t start it yet. Samba however tries to start since it is in S20 on rc2-5.d but it fails immediately because no network is configured yet. Running - sudo /etc/init.d/samba restart - is fine.
In the log file I can find the following pair of errors:
[2009/04/18 11:22:48, 0] lib/interface.c:load_interfaces(540)
  WARNING: no network interfaces found
[2009/04/18 11:22:49, 0] smbd/server.c:open_sockets_smbd(548)
  open_sockets_smbd: No sockets available to bind to.

Trying to resolve the problem, I wrote an updown script in /etc/NetworkManager/dispatcher.d naming it 02samba:
$ ls -l /etc/NetworkManager/dispatcher.d
total 12K
-rwxr-xr-x 1 root root 1.3K 2008-10-21 05:17 01ifupdown
-rwxr-xr-x 1 root root 1.9K 2009-05-08 11:35 02samba

If this solution makes sense I would recommend that it would be added to Ubuntu samba server package.
Here is the script I wrote:
#!/bin/sh -e
# Script to dispatch NetworkManager events
#
# Runs ifupdown scripts when NetworkManager fiddles with interfaces.

if [ -z "$1" ]; then
    echo "$0: called with no interface" 1>&2
    exit 1;
fi

# Fake ifupdown environment
export IFACE="$1"
export LOGICAL="$1"
export ADDRFAM="NetworkManager"
export METHOD="NetworkManager"
export VERBOSITY="0"
notRunningCont=`/etc/init.d/samba status | grep -c not` # count "not running"

# Run the right scripts
case "$2" in
    up)
        export MODE="start"
        export PHASE="up"
        if [ -e /var/run/network/ifstate ]
        then
                if grep --silent eth /var/run/network/ifstate
                then
                        case $notRunningCont in # count "not running"
                        2) # both smbd and nmbd are down. start them
                                exec /etc/init.d/samba start
                                ;;
                        1) # probably smbd faild.
                                exec /etc/init.d/samba restart
                                ;;
                        0) # samba seems running
                                ;;
                        *) # unknown situation. try to restart anyways
                                exec /etc/init.d/samba restart
                        esac
                fi
        fi
        ;;
    down)
        export MODE="stop"
        export PHASE="down"
        if [ -e /var/run/network/ifstate ]
        then
                if grep --silent eth /var/run/network/ifstate
                then # network is still up. Make sure samba is also up.
                        case $notRunningCont in
                        2) # both smbd and nmbd are down. start them
                                exec /etc/init.d/samba start
                                ;;
                        1) # probably smbd faild.
                                exec /etc/init.d/samba restart
                                ;;
                        0) # samba seems running
                                ;;
                        *) # unknown situation. try to restart anyways
                                exec /etc/init.d/samba restart
                        esac
                else # shut samba down
                        exec /etc/init.d/samba stop
                fi
        else # same here. Shut it down
                exec /etc/init.d/samba stop
        fi
        ;;
   pre-up)
        export MODE="start"
        export PHASE="pre-up"
        exec run-parts /etc/network/if-pre-up.d
        ;;
    post-down)
        export MODE="stop"
        export PHASE="post-down"
        exec run-parts /etc/network/if-post-down.d
        ;;
    *)
        echo "$0: called with unknown action \`$2'" 1>&2
        exit 1
        ;;
esac

Revision history for this message
Thierry Carrez (ttx) wrote :

Can't reproduce that on Jaunty. On my laptop, switching to VC1 before logging into Gnome (and having NM connect to my wireless) smbd and nmbd (default smb.conf) are running, listening to *.*

Could you tell me what version of Ubuntu you're running and attach your smb.conf ?

Changed in samba (Ubuntu):
status: New → Incomplete
Revision history for this message
David Harel (hareldvd) wrote :

I reverted the solution so you could see for yourself how to reproduce the problem.
1st, the current state:
$ find /etc -lname '*samba*'
/etc/rc4.d/S20samba
/etc/rc1.d/K20samba
/etc/rc3.d/S20samba
/etc/rc0.d/K20samba
/etc/rc6.d/K20samba
/etc/rc2.d/S20samba
/etc/rc5.d/S20samba
harel@harel-laptop 2009-03-06 $ /etc/init.d/samba status
 * nmbd is running
 * smbd is not running
2nd, attached my /etc/samba/smb.conf.
3rd, I typically do not configure samba to listen to *.* (too afraid of misuse) so I typically limit samba on specific network. This can be viewd in the smb.conf file.

Revision history for this message
Thierry Carrez (ttx) wrote :

OK, that makes sense. If it is started to listen to specific interfaces that don't exist when it starts, it won't run.

Changed in samba (Ubuntu):
importance: Undecided → Wishlist
status: Incomplete → Confirmed
summary: - samba server fails to start on boot time when laptop is not connected to
- any network.
+ Samba fails to start at boot when not connected to network (and specific
+ interfaces are configured)
Revision history for this message
Pavol Klačanský (pavolzetor-deactivatedaccount) wrote :

I have similar problem, but samba stops boot process and I cannot boot to system, I move samba folder in etc and problem does not occur, please fix it

dist: karmic

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

Confirmed, this is a problem for me too.
Unexpected failure of a system service in supported configurations is a bug, not a feature request...so perhaps we should change this back to being a bug not a wishlist item?

Revision history for this message
Thierry Carrez (ttx) wrote :

This has been set to wishlist since the reporter explicitely adds "interfaces = eth0 eth1" to his smb.conf, so in a way he tells samba that it should not start if eth0/eth1 isn't up. My understanding (and my testing) showed that without this line the reporter added, samba is starting alright. Hence the wishlist : "I want samba to start even if I specifically ask it to start on a

Revision history for this message
Thierry Carrez (ttx) wrote :

non-existing interface only"

Chuck Short (zulcss)
Changed in samba (Ubuntu):
status: Confirmed → Triaged
Revision history for this message
Hendrik Saly (phps) wrote :
Download full text (5.2 KiB)

same for me but samba exits with a core dump, so i think its not wishlist, its a bug

I configured in smb.conf

interfaces = vmnet8 vmnet1
bind interfaces only = yes

so that samba is only accessable by the vmware guest.
BTW: In /etc/rc2.d vmware (S19) starts prior to samba (S20), thats the next strange thing

grep -ri smb /var/log/daemon.log

Apr 26 14:10:07 fringe init: smbd main process (1222) killed by ABRT signal
Apr 26 14:10:07 fringe init: smbd main process ended, respawning
Apr 26 14:10:07 fringe smbd[1233]: [2010/04/26 14:10:07, 0] printing/print_cups.c:103(cups_connect)
Apr 26 14:10:07 fringe smbd[1233]: Unable to connect to CUPS server localhost:631 - Connection refused
Apr 26 14:10:07 fringe smbd[1234]: [2010/04/26 14:10:07, 0] printing/print_cups.c:103(cups_connect)
Apr 26 14:10:07 fringe smbd[1234]: Unable to connect to CUPS server localhost:631 - Connection refused
Apr 26 14:10:07 fringe smbd[1232]: [2010/04/26 14:10:07, 0] lib/interface.c:550(load_interfaces)
Apr 26 14:10:07 fringe smbd[1232]: WARNING: no network interfaces found
Apr 26 14:10:07 fringe smbd[1232]: [2010/04/26 14:10:07, 0] smbd/server.c:1115(main)
Apr 26 14:10:07 fringe smbd[1232]: standard input is not a socket, assuming -D option
Apr 26 14:10:07 fringe smbd[1232]: [2010/04/26 14:10:07, 0] smbd/server.c:616(open_sockets_smbd)
Apr 26 14:10:07 fringe smbd[1232]: open_sockets_smbd: No sockets available to bind to.
Apr 26 14:10:07 fringe smbd[1232]: [2010/04/26 14:10:07, 0] smbd/server.c:837(exit_server_common)
Apr 26 14:10:07 fringe smbd[1232]: ===============================================================
Apr 26 14:10:07 fringe smbd[1232]: [2010/04/26 14:10:07, 0] smbd/server.c:839(exit_server_common)
Apr 26 14:10:07 fringe smbd[1232]: Abnormal server exit: open_sockets_smbd() failed
Apr 26 14:10:07 fringe smbd[1232]: [2010/04/26 14:10:07, 0] smbd/server.c:840(exit_server_common)
Apr 26 14:10:07 fringe smbd[1232]: ===============================================================
Apr 26 14:10:07 fringe smbd[1232]: [2010/04/26 14:10:07, 0] lib/util.c:1584(log_stack_trace)
Apr 26 14:10:07 fringe smbd[1232]: BACKTRACE: 6 stack frames:
Apr 26 14:10:07 fringe smbd[1232]: #0 smbd(log_stack_trace+0x1a) [0x7f7c7d2de7aa]
Apr 26 14:10:07 fringe smbd[1232]: #1 smbd(+0x5a9cc0) [0x7f7c7d56dcc0]
Apr 26 14:10:07 fringe smbd[1232]: #2 smbd(+0x5a9e91) [0x7f7c7d56de91]
Apr 26 14:10:07 fringe smbd[1232]: #3 smbd(main+0x90d) [0x7f7c7d56ebed]
Apr 26 14:10:07 fringe smbd[1232]: #4 /lib/libc.so.6(__libc_start_main+0xfd) [0x7f7c79a6cc4d]
Apr 26 14:10:07 fringe smbd[1232]: #5 smbd(+0xc0a49) [0x7f7c7d084a49]
Apr 26 14:10:07 fringe smbd[1232]: [2010/04/26 14:10:07, 0] lib/fault.c:326(dump_core)
Apr 26 14:10:07 fringe smbd[1232]: dumping core in /var/log/samba/cores/smbd
Apr 26 14:10:07 fringe smbd[1232]:
Apr 26 14:10:07 fringe init: smbd main process (1232) killed by ABRT signal
Apr 26 14:10:07 fringe init: smbd main process ended, respawning
Apr 26 14:10:07 fringe smbd[1240]: [2010/04/26 14:10:07, 0] printing/print_cups.c:103(cups_connect)
Apr 26 14:10:07 fringe smbd[1240]: Unable to connect to CUPS server localhost:631 - Connection r...

Read more...

Revision history for this message
alainpannetier (alain-pannetier) wrote :

I've adapted and tried the workaround developed by David Harel (the initial bug reporter) but that does not work with interfaces that are beyond NetworkManager's jurisdiction (e.g. vboxnet0).

So we're left with two equally undesirable options
  - remove any interface binding condition (i.e. poor security).
  - develop a job polling for any interface status change with the task of systematically restarting smbd.

when you bind on vboxnet0, wlan0 and eth0 interface status changes can be a pretty frequent event.

So +1 for the wishlist.

Why could smbd not simply listen (as in listener design pattern) to net interface changes and bind/unbind on any interface configured in smb.conf an when-available basis ?

Revision history for this message
camden lindsay (camden-lindsay+launchpad) wrote :

It appears this and https://bugs.launchpad.net/ubuntu/+source/samba/+bug/836849 are one in the same, although the bug listed here is because the static ip assignments are done through networkmanager...

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

Bug attachments

Remote bug watches

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