christgau / wsdd

A Web Service Discovery host daemon.
MIT License
814 stars 98 forks source link

Need help with OpenWrt start up script #92

Closed FlexMcMurphy closed 3 years ago

FlexMcMurphy commented 3 years ago

I have been setting up wsdd in /usr/bin/wsdd on my Raspberry Pis using systemd and it's working great.

I have one Pi running OpenWrt.. this doesn't have systemd. I made the script executable and if I run it from the command line the Samba share appears in my Windows 10 Network Neighborhood and I can then browse the files in the share.

However, I can't get the script to work properly at boot up. I tried putting this in a crontab... @reboot /usr/bin/wsdd

I also put /usr/bin/wsdd in the OpenWrt /etc/rc.local script. This is also made executable and is working already to mount a drive connected to OpenWrt at reboot.

In both cases... the Samba share appears in Win 10 network neighborhood but when I click on it the files in that share won't load in the file explorer. When I go into the terminal I can do ps | grep wsdd and see that the script is running... just not working properly for me!

I don't know how to modify the example rc.d/wsdd file to suit my system. Also, there is no /usr/sbin/daemon in OpenWrt. Not sure where wsdd logs to.

Does anyone know how to make this run at boot up without systemd on OpenWrt?

Thank you.

christgau commented 3 years ago

In both cases... the Samba share appears in Win 10 network neighborhood but when I click on it the files in that share won't load in the file explorer. When I go into the terminal I can do ps | grep wsdd and see that the script is running... just not working properly for me!

If the host appears in the "network neighborhood", wsdd has done everything it is designed for. If you can't connect to the host or the share to not appear, this is either a DNS/name resolution issue or a problem with Samba.

A quick and educated guess from my side is that the name you provide to wsdd (if any) does not match the hostname of the machine it runs on, or the hostname used by wsdd is not resolvable. You could try to ping the host with the name shown in the network neighborhood from the command line on the Windows host. If that does not work, name resolution on your network should be fixed.

I don't know how to modify the example rc.d/wsdd file to suit my system. Also, there is no /usr/sbin/daemon in OpenWrt. Not sure where wsdd logs to.

The rc.d scripts are actually designed for FreeBSD. AFAIK, OpenWrt runs a Linux with procd as init system. You may refer to the OpenWrt documentation on procd scripts for writing a proper script for this OS. This might also be a nice contribution to the wsdd community.

FlexMcMurphy commented 3 years ago

I can ping the hostname ok. It works fine if I just run /usr/bin/wsdd from a terminal. Maybe wsdd needs other info to set up the connection and can gather that when run manually but a startup script needs a way to supply that..

For now I realize, as pointed out in the readme, that OpenWRT includes an implementation that can be installed with opkg update && opkg install wsdd2 It creates this very complicated procd startup script that tries to gather things like Workgroup name and hostname. Apologies but for now I will stick with this solution!

#!/bin/sh /etc/rc.common

START=99
USE_PROCD=1

SMB_CONF=""
BIND_IF_PARM=""
NB_PARM="$(cat /proc/sys/kernel/hostname)"
WG_PARM="WORKGROUP"
BI_PARM=""

start_service() {

    . /lib/functions/network.sh

    if [ -e /etc/ksmbd/smb.conf ] && [ -e /etc/init.d/ksmbd ] && /etc/init.d/ksmbd running; then
        SMB_CONF="/etc/ksmbd/smb.conf"
    fi

    [ -e /etc/samba/smb.conf ] && {
        if [ -e /etc/init.d/samba4 ] && /etc/init.d/samba4 running; then
            SMB_CONF="/etc/samba/smb.conf"
        elif [ -e /etc/init.d/samba ] && /etc/init.d/samba running; then
            SMB_CONF="/etc/samba/smb.conf"
        fi
    }

    [ -z "$SMB_CONF" ] && {
        logger -p daemon.error -t 'wsdd2' "samba36/4 or ksmbd is not running, can't start wsdd2!"
        exit 1
    }

    # cleanup comments
    local smb_conf
    smb_conf="$(grep '^[[:blank:]]*[^[:blank:]#;]' $SMB_CONF)"

    local nb_name
    nb_name="$(echo "$smb_conf" | grep -i 'netbios name' | awk -F'=' '{print $2}' | tr -d ' \n')"
    [ -n "$nb_name" ] && NB_PARM="$nb_name"

    # use uppercase for none mdns option
    local nb_option
    nb_option="$(echo "$smb_conf" | grep -i 'mdns name' | awk -F'=' '{print $2}' | tr -d ' \n')"
    [ "$nb_option" != "mdns" ] && NB_PARM="$(echo "$nb_name" | awk '{print toupper($0)}')"

    local wg_name
    wg_name="$(echo "$smb_conf" | grep -i 'workgroup' | awk -F'=' '{print $2}' | tr -d ' \n')"
    [ -n "$wg_name" ] && WG_PARM="$wg_name"

    # resolve lan interface (BUG: No multi-interface binds atm)
    local ifname
    network_get_device ifname lan

    local board_vendor
    local board_model
    local board_sku

    [ -e /tmp/sysinfo/board_name ] && {
        board_vendor="$(awk -F',' '{print $1}' /tmp/sysinfo/board_name | tr ' ' '_' | tr -d ' \n')"
        board_sku="$(awk -F',' '{print $2}' /tmp/sysinfo/board_name | tr ' ' '_' | tr -d ' \n')"
    }

    [ -e /tmp/sysinfo/model ] && {
        board_model="$(awk -F':' '{print $1}' /tmp/sysinfo/model | tr ' ' '_' | tr -d ' \n')"
    }

    [ -n "$board_vendor" ] && [ -n "$board_model" ] && {
        if [ -n "$board_sku" ]; then
            BI_PARM="vendor:$board_vendor,model:$board_model,sku:$board_sku"
        else
            BI_PARM="vendor:$board_vendor,model:$board_model"
        fi
    }

    procd_open_instance
    procd_set_param command /usr/bin/wsdd2
    [ -n "$ifname" ] && procd_append_param command -i "$ifname"
    procd_append_param command -N "$NB_PARM"
    procd_append_param command -G "$WG_PARM"
    [ "x${BI_PARM}" = "x" ] || procd_append_param command -b "$BI_PARM"
    procd_set_param respawn
    procd_set_param file "$SMB_CONF"
    procd_close_instance
}

service_triggers() {
    PROCD_RELOAD_DELAY=1000
    procd_add_reload_trigger "dhcp" "system" "samba" "samba4" "ksmbd"
}

Thank you for this awesome software Steffen :)

christgau commented 3 years ago

It works fine if I just run /usr/bin/wsdd from a terminal. Maybe wsdd needs other info to set up the connection and can gather that when run manually but a startup script needs a way to supply that..

In that case it might be that the systems hostname is not yet set or is changed later in the boot process such that wsdd uses a different one. You can override the hostname with the -n/--hostname command line option.

For now I realize, as pointed out in the readme, that OpenWRT includes an implementation that can be installed with opkg update && opkg install wsdd2 [...] Thank you for this awesome software Steffen :)

Thanks, but for the records and to be clear: wsdd2 is actually a different implementation and is not mine. Wsdd2 is also mentioned in wsdd's readme... along with OpenWRT as I recall now 😉

btw: feel free to close the issue if you think it is solved.

FlexMcMurphy commented 3 years ago

I ending up having the same problem with wsdd2. The Samba share would appear in the Win 10 network neighborhood but when I click on it the files in that share would not load.

Well tonight, without changing anything else, I again tried turning off SMBv1 from Powershell and disabling Netbios in my Laptops Network adapter. I'm pleased to say, thanks to wsdd2 and WS-Discovery my shares are auto populating in the Network "Neighbourhood" and when I click on them they reveal their files. Probably wsdd would work as well, it must have been something cached possibly in my Windows config that was confusing things?!

I asked over in the OpenWrt forums and was advised to first remove all the currently connected shares with net use * /d and then remove all cached Kerberos tickets with klist purge. This will force Windows to request new Kerberos tickets when a network share is connected. I did that but not until after it started working anyway so I'm not sure if those commands really made any difference but those steps may be useful if this is a problem again.

Can close this now I think. Thank you.