From 7beaacfefff0180f11e3f9cfd71a283aca1f594d Mon Sep 17 00:00:00 2001 From: Stephan Raue Date: Tue, 6 Aug 2013 23:44:43 +0200 Subject: [PATCH] samba: add systemd support Signed-off-by: Stephan Raue --- packages/network/samba/package.mk | 39 ++++---- packages/network/samba/scripts/52_samba | 93 ------------------- packages/network/samba/scripts/samba-config | 70 ++++++++++++++ .../network/samba/system.d.opt/nmbd.service | 16 ++++ .../samba/system.d.opt/samba-config.service | 10 ++ .../samba/system.d.opt/smbd-monitor.path | 9 ++ .../samba/system.d.opt/smbd-monitor.service | 12 +++ .../network/samba/system.d.opt/smbd.service | 17 ++++ 8 files changed, 157 insertions(+), 109 deletions(-) delete mode 100644 packages/network/samba/scripts/52_samba create mode 100755 packages/network/samba/scripts/samba-config create mode 100644 packages/network/samba/system.d.opt/nmbd.service create mode 100644 packages/network/samba/system.d.opt/samba-config.service create mode 100644 packages/network/samba/system.d.opt/smbd-monitor.path create mode 100644 packages/network/samba/system.d.opt/smbd-monitor.service create mode 100644 packages/network/samba/system.d.opt/smbd.service diff --git a/packages/network/samba/package.mk b/packages/network/samba/package.mk index 95d22882da..e88ae26f5d 100644 --- a/packages/network/samba/package.mk +++ b/packages/network/samba/package.mk @@ -166,23 +166,30 @@ makeinstall_target() { ln -sf samba_multicall $INSTALL/usr/bin/nmbd ln -sf samba_multicall $INSTALL/usr/bin/smbpasswd + mkdir -p $INSTALL/etc/samba + cp ../codepages/lowcase.dat $INSTALL/etc/samba + cp ../codepages/upcase.dat $INSTALL/etc/samba + cp ../codepages/valid.dat $INSTALL/etc/samba + + mkdir -p $INSTALL/lib/systemd/system + cp $PKG_DIR/system.d.opt/* $INSTALL/lib/systemd/system + + enable_service smbd-monitor.path + enable_service nmbd.service + enable_service smbd.service + + mkdir -p $INSTALL/usr/lib/samba + cp $PKG_DIR/scripts/samba-config $INSTALL/usr/lib/samba + + if [ -f $PROJECT_DIR/$PROJECT/config/smb.conf ]; then mkdir -p $INSTALL/etc/samba - cp ../codepages/lowcase.dat $INSTALL/etc/samba - cp ../codepages/upcase.dat $INSTALL/etc/samba - cp ../codepages/valid.dat $INSTALL/etc/samba + cp $PROJECT_DIR/$PROJECT/config/smb.conf $INSTALL/etc/samba + else + mkdir -p $INSTALL/etc/samba + cp $PKG_DIR/config/smb.conf $INSTALL/etc/samba + mkdir -p $INSTALL/usr/config + cp $PKG_DIR/config/smb.conf $INSTALL/usr/config/samba.conf.sample + fi - mkdir -p $INSTALL/etc/init.d - cp $PKG_DIR/scripts/52_samba $INSTALL/etc/init.d - - if [ -f $PROJECT_DIR/$PROJECT/config/smb.conf ]; then - mkdir -p $INSTALL/etc/samba - cp $PROJECT_DIR/$PROJECT/config/smb.conf $INSTALL/etc/samba - else - mkdir -p $INSTALL/etc/samba - cp $PKG_DIR/config/smb.conf $INSTALL/etc/samba - mkdir -p $INSTALL/usr/config - cp $PKG_DIR/config/smb.conf $INSTALL/usr/config/samba.conf.sample - fi fi } - diff --git a/packages/network/samba/scripts/52_samba b/packages/network/samba/scripts/52_samba deleted file mode 100644 index 47c8a06edb..0000000000 --- a/packages/network/samba/scripts/52_samba +++ /dev/null @@ -1,93 +0,0 @@ -################################################################################ -# Copyright (C) 2009-2010 OpenELEC.tv -# http://www.openelec.tv -# -# This Program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. -# -# This Program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with OpenELEC.tv; see the file COPYING. If not, write to -# the Free Software Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110, USA. -# http://www.gnu.org/copyleft/gpl.html -################################################################################ - -# start Samba Server -# -# runlevels: openelec, textmode - -( - # can be called from openelec addon. - # ensure that environment is sane - . /etc/profile - - SAMBA_ENABLED=true - if [ -f $CONFIG_CACHE/service_samba.conf ]; then - . $CONFIG_CACHE/service_samba.conf - fi - - if [ "$SAMBA_ENABLED" = "true" ]; then - - # wait for network - wait_for_inet_addr force - - progress "Starting Samba server" - - SMB_USERCONF="/storage/.config/samba.conf" - SMB_DEFCONF="/etc/samba/smb.conf" - SMB_CONF="/var/run/smb.conf" - - mkdir -p /var/run - if [ -f $SMB_USERCONF ]; then - cp $SMB_USERCONF $SMB_CONF - else - cp $SMB_DEFCONF $SMB_CONF - fi - - # only letters & numbers permitted for username & password - SAMBA_USERNAME=`echo $SAMBA_USERNAME | sed "s/[^a-zA-Z0-9]//g;"` - SAMBA_PASSWORD=`echo $SAMBA_PASSWORD | sed "s/[^a-zA-Z0-9]//g;"` - - if [ "$SAMBA_SECURE" == "true" -a ! "$SAMBA_USERNAME" == "" -a ! "$SAMBA_PASSWORD" == "" ] ; then - # username map: first line makes sure plain root does not work all the time - # processing continues, so if user chooses root as username, second line overrides the first - # this is done always in case user uses passwords in userconf. - # many thanks to viljoviitanen for this - echo -e "$SAMBA_PASSWORD\n$SAMBA_PASSWORD" | smbpasswd -s -a root >/dev/null 2>&1 - echo -e "nobody = root\nroot = $SAMBA_USERNAME" > /var/run/samba.map - - # set public = no - sed -e 's|^.[ \t]*.public.=.*| public = no |' $SMB_CONF > $SMB_CONF.tmp && \ - mv $SMB_CONF.tmp $SMB_CONF - # remove username map (if any in userconfig) - sed -e 's|^.[ \t]*.username map.=.*||' $SMB_CONF > $SMB_CONF.tmp && \ - mv $SMB_CONF.tmp $SMB_CONF - # set security = share, add username map - sed -e 's|^.[ \t]*.security.=.*| security = user\n username map = /var/run/samba.map|' $SMB_CONF > $SMB_CONF.tmp && \ - mv $SMB_CONF.tmp $SMB_CONF - else - # set public = yes - sed -e 's|^.[ \t]*.public.=.*| public = yes |' $SMB_CONF > $SMB_CONF.tmp && \ - mv $SMB_CONF.tmp $SMB_CONF - # remove username map (if any in userconfig) - sed -e 's|^.[ \t]*.username map.=.*||' $SMB_CONF > $SMB_CONF.tmp && \ - mv $SMB_CONF.tmp $SMB_CONF - # set security = share - sed -e 's|^.[ \t]*.security.=.*| security = share|' $SMB_CONF > $SMB_CONF.tmp && \ - mv $SMB_CONF.tmp $SMB_CONF - fi - - SMB_ARG="--configfile=$SMB_CONF" - mkdir -p /var/log/samba - rm /var/run/smbd-smb.conf.pid &>/dev/null - rm /var/run/nmbd-smb.conf.pid &>/dev/null - nmbd --daemon $SMB_ARG > /dev/null 2>&1 - smbd --daemon $SMB_ARG > /dev/null 2>&1 - fi -)& diff --git a/packages/network/samba/scripts/samba-config b/packages/network/samba/scripts/samba-config new file mode 100755 index 0000000000..63187d1fcc --- /dev/null +++ b/packages/network/samba/scripts/samba-config @@ -0,0 +1,70 @@ +#!/bin/sh +################################################################################ +# This file is part of OpenELEC - http://www.openelec.tv +# Copyright (C) 2009-2012 Stephan Raue (stephan@openelec.tv) +# +# This Program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This Program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with OpenELEC.tv; see the file COPYING. If not, write to +# the Free Software Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110, USA. +# http://www.gnu.org/copyleft/gpl.html +################################################################################ + +. /etc/profile + +SMB_USERCONF="/storage/.config/samba.conf" +SMB_DEFCONF="/etc/samba/smb.conf" +SMB_CONF="/run/samba/smb.conf" + +if [ -f $CONFIG_CACHE/services/samba.conf ]; then + . $CONFIG_CACHE/services/samba.conf + + mkdir -p /run/samba + if [ -f $SMB_USERCONF ]; then + cp $SMB_USERCONF $SMB_CONF + else + cp $SMB_DEFCONF $SMB_CONF + fi + + # only letters & numbers permitted for username & password + SAMBA_USERNAME=`echo $SAMBA_USERNAME | sed "s/[^a-zA-Z0-9]//g;"` + SAMBA_PASSWORD=`echo $SAMBA_PASSWORD | sed "s/[^a-zA-Z0-9]//g;"` + + if [ "$SAMBA_SECURE" == "true" -a ! "$SAMBA_USERNAME" == "" -a ! "$SAMBA_PASSWORD" == "" ] ; then + # username map: first line makes sure plain root does not work all the time + # processing continues, so if user chooses root as username, second line overrides the first + # this is done always in case user uses passwords in userconf. + # many thanks to viljoviitanen for this + echo -e "$SAMBA_PASSWORD\n$SAMBA_PASSWORD" | smbpasswd -s -a root >/dev/null 2>&1 + echo -e "nobody = root\nroot = $SAMBA_USERNAME" > /var/run/samba.map + + # set public = no + sed -e 's|^.[ \t]*.public.=.*| public = no |' $SMB_CONF > $SMB_CONF.tmp && \ + mv $SMB_CONF.tmp $SMB_CONF + # remove username map (if any in userconfig) + sed -e 's|^.[ \t]*.username map.=.*||' $SMB_CONF > $SMB_CONF.tmp && \ + mv $SMB_CONF.tmp $SMB_CONF + # set security = share, add username map + sed -e 's|^.[ \t]*.security.=.*| security = user\n username map = /var/run/samba.map|' $SMB_CONF > $SMB_CONF.tmp && \ + mv $SMB_CONF.tmp $SMB_CONF + else + # set public = yes + sed -e 's|^.[ \t]*.public.=.*| public = yes |' $SMB_CONF > $SMB_CONF.tmp && \ + mv $SMB_CONF.tmp $SMB_CONF + # remove username map (if any in userconfig) + sed -e 's|^.[ \t]*.username map.=.*||' $SMB_CONF > $SMB_CONF.tmp && \ + mv $SMB_CONF.tmp $SMB_CONF + # set security = share + sed -e 's|^.[ \t]*.security.=.*| security = share|' $SMB_CONF > $SMB_CONF.tmp && \ + mv $SMB_CONF.tmp $SMB_CONF + fi +fi diff --git a/packages/network/samba/system.d.opt/nmbd.service b/packages/network/samba/system.d.opt/nmbd.service new file mode 100644 index 0000000000..a4a48261d2 --- /dev/null +++ b/packages/network/samba/system.d.opt/nmbd.service @@ -0,0 +1,16 @@ +[Unit] +Description=Samba NMB Daemon +After=network.target samba-config.service +Requires=samba-config.service + +ConditionPathExists=/storage/.cache/services/samba.conf +ConditionPathExists=/run/samba/smb.conf + +[Service] +Type=forking +PIDFile=/var/run/nmbd-smb.conf.pid +ExecStart=/usr/bin/nmbd --configfile=/run/samba/smb.conf +ExecReload=/bin/kill -HUP $MAINPID + +[Install] +WantedBy=multi-user.target diff --git a/packages/network/samba/system.d.opt/samba-config.service b/packages/network/samba/system.d.opt/samba-config.service new file mode 100644 index 0000000000..23dc1ef28c --- /dev/null +++ b/packages/network/samba/system.d.opt/samba-config.service @@ -0,0 +1,10 @@ +[Unit] +Description=Samba configfile writer +After=local-fs.target + +ConditionPathExists=/storage/.cache/services/samba.conf + +[Service] +Type=oneshot +ExecStart=/usr/lib/samba/samba-config + diff --git a/packages/network/samba/system.d.opt/smbd-monitor.path b/packages/network/samba/system.d.opt/smbd-monitor.path new file mode 100644 index 0000000000..3169ab7c51 --- /dev/null +++ b/packages/network/samba/system.d.opt/smbd-monitor.path @@ -0,0 +1,9 @@ +[Unit] +Description=Samba configfile monitor + +[Path] +PathModified=/storage/.cache/services/samba.conf +PathModified=/storage/.config/samba.conf + +[Install] +WantedBy=multi-user.target diff --git a/packages/network/samba/system.d.opt/smbd-monitor.service b/packages/network/samba/system.d.opt/smbd-monitor.service new file mode 100644 index 0000000000..6a4da5620b --- /dev/null +++ b/packages/network/samba/system.d.opt/smbd-monitor.service @@ -0,0 +1,12 @@ +[Unit] +Description=Samba configfile monitor +After=network.target + +[Service] +Type=oneshot +ExecStartPre=/bin/systemctl restart samba-config.service +ExecStartPre=/bin/systemctl restart nmbd.service +ExecStart=/bin/systemctl restart smbd.service + +[Install] +WantedBy=multi-user.target diff --git a/packages/network/samba/system.d.opt/smbd.service b/packages/network/samba/system.d.opt/smbd.service new file mode 100644 index 0000000000..9343265bb7 --- /dev/null +++ b/packages/network/samba/system.d.opt/smbd.service @@ -0,0 +1,17 @@ +[Unit] +Description=Samba SMB Daemon +After=network.target samba-config.service nmb.service +Requires=samba-config.service + +ConditionPathExists=/storage/.cache/services/samba.conf +ConditionPathExists=/run/samba/smb.conf + +[Service] +Type=forking +PIDFile=/var/run/smbd-smb.conf.pid +LimitNOFILE=16384 +ExecStart=/usr/bin/smbd --configfile=/run/samba/smb.conf +ExecReload=/bin/kill -HUP $MAINPID + +[Install] +WantedBy=multi-user.target