The officially official Devuan Forum!

You are not logged in.

#1 2017-11-12 22:07:32

bouke
Member
Registered: 2017-11-12
Posts: 2

init.d: process ID samba

Hello,

I managed to compile and install samba 4 on Devuan. I am not that good with bash/sh scripts - I am hoping someone could help.

The problem is that the PID written to the PID file is 1 digit lower than expected. For some reason I have to increase the PID with 1.

I have found a init.d file which did not work. I had to change some bits and commented some chunks out. The problematic part is the following.

                if ! start-stop-daemon --start --quiet --pidfile $SAMBAPID --make-pidfile --oknodo --exec /opt/samba/sbin/samba -- -D; then
                        log_end_msg 1
                        exit 1
                fi
                log_end_msg 0
                ;;

The pidfile is created but when I run "ps ax | grep samba" the first process ID does not represent the number found in the pidfile. This means that the "status", "stop" and "restart" functions do not work.

However, when I increment the process ID in the pidfile with 1, I am able to print the status and stop Samba (somewhat) gracefully.

I would like to know how I could fix this issue. Should I just increment the number found in the pidfile (and how) or should I choose for a different approach?

I have copied the full init.d file below.

Many thanks for your help.

#!/bin/sh

### BEGIN INIT INFO
# Provides:          samba
# Required-Start:    $network
# Required-Stop:     $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: start Samba daemons for the AD DC
### END INIT INFO

#
# Start/stops the Samba daemon (samba).
# Adapted from the Samba 3 packages.
#

PIDDIR=/var/run/samba
SAMBAPID=$PIDDIR/samba.pid

# clear conflicting settings from the environment
unset TMPDIR

# See if the daemon and the config file are there
test -x /opt/samba/sbin/samba -a -r /opt/samba/etc/smb.conf || exit 0

. /lib/lsb/init-functions

case "$1" in
        start)
#               SERVER_ROLE=`samba-tool testparm --parameter-name="server role"  2>/dev/null | tail -1`
#               if [ "$SERVER_ROLE" != "active directory domain controller" ]; then
#                   exit 0
#               fi
#
#               if init_is_upstart; then
#                       exit 1
#               fi

#               # CVE-2013-4475
#               KEYFILE=/opt/samba/private/tls/key.pem
#               if [ -e $KEYFILE ]
#               then
#                               KEYPERMS=`stat -c %a $KEYFILE`
#                               if [ "$KEYPERMS" != "600" ]
#                               then
#                                               echo "wrong permission on $KEYFILE, must be 600"
#                                               echo "samba will not start (CVE-2013-4475)"
#                                               echo "Removing all tls .pem files will cause an auto-regeneration with the correct permissions."
#                                               exit 1
#                               fi
#               fi

                log_daemon_msg "Starting Samba AD DC daemon" "samba"
                # Make sure we have our PIDDIR, even if it's on a tmpfs
                install -o root -g root -m 755 -d $PIDDIR

                if ! start-stop-daemon --start --quiet --pidfile $SAMBAPID --make-pidfile --oknodo --exec /opt/samba/sbin/samba -- -D; then
                        log_end_msg 1
                        exit 1
                fi
                log_end_msg 0
                ;;
        stop)
                if init_is_upstart; then
                        exit 0
                fi
                log_daemon_msg "Stopping Samba AD DC daemon" "samba"

                start-stop-daemon --stop --quiet --pidfile $SAMBAPID
                #sometimes samba does not stop...
                 sleep 3
                 pkill samba
                # Wait a little and remove stale PID file
                sleep 1
                if [ -f $SAMBAPID ] && ! ps h `cat $SAMBAPID` > /dev/null
                then
                        # Stale PID file (samba was succesfully stopped),
                        # remove it (should be removed by samba itself IMHO.)
                        rm -f $SAMBAPID
                fi

                log_end_msg 0

                ;;
        restart|force-reload)
                if init_is_upstart; then
                        exit 1
                fi
                $0 stop
                sleep 1
                $0 start
                ;;
        status)
                status_of_proc -p $SAMBAPID /opt/samba/sbin/samba samba
                exit $?
                ;;
        *)
                echo "Usage: /etc/init.d/samba {start|stop|restart|force-reload|status}"
                exit 1
                ;;
esac

exit 0

Last edited by bouke (2017-11-12 22:10:57)

Offline

#2 2017-11-13 20:02:53

bouke
Member
Registered: 2017-11-12
Posts: 2

Re: init.d: process ID samba

Resolved ;-)

#!/bin/sh

### BEGIN INIT INFO
# Provides:          samba
# Required-Start:    $network
# Required-Stop:     $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: start Samba daemons for the AD DC
### END INIT INFO

#
# Start/stops the Samba daemon (samba).
# Adapted from the Samba 3 packages.
#

# clear conflicting settings from the environment
unset TMPDIR

# See if the daemon and the config file are there
test -x /opt/samba/sbin/samba -a -r /opt/samba/etc/smb.conf || exit 0

. /lib/lsb/init-functions

case "$1" in
        start)
                SERVER_ROLE=`/opt/samba/bin/samba-tool testparm --parameter-name="server role"  2>/dev/null | tail -1`
                if [ "$SERVER_ROLE" != "active directory domain controller" ]; then
                    exit 0
                fi

                if init_is_upstart; then
                        exit 1
                fi

                # CVE-2013-4475
                KEYFILE=/opt/samba/private/tls/key.pem
                if [ -e $KEYFILE ]
                then
                                KEYPERMS=`stat -c %a $KEYFILE`
                                if [ "$KEYPERMS" != "600" ]
                                then
                                                echo "wrong permission on $KEYFILE, must be 600"
                                                echo "samba will not start (CVE-2013-4475)"
                                                echo "Removing all tls .pem files will cause an auto-regeneration with the correct permissions."
                                                exit 1
                                fi
                fi

                log_daemon_msg "Starting Samba AD DC daemon" "samba"

                if ! start-stop-daemon --start --quiet --oknodo --exec /opt/samba/sbin/samba -- -D; then
                        log_end_msg 1
                        exit 1
                fi
                log_end_msg 0
                ;;
        stop)
                if init_is_upstart; then
                        exit 0
                fi
                log_daemon_msg "Stopping Samba AD DC daemon" "samba"

                start-stop-daemon --stop --quiet --pidfile /opt/samba/var/run/samba.pid

                log_end_msg 0

                ;;
        restart|force-reload)
                if init_is_upstart; then
                        exit 1
                fi
                $0 stop
                sleep 1
                $0 start
                ;;
        status)
                status_of_proc -p /opt/samba/var/run/samba.pid /opt/samba/sbin/samba samba
                exit $?
                ;;
        *)
                echo "Usage: /etc/init.d/samba {start|stop|restart|force-reload|status}"
                exit 1
                ;;
esac

exit 0

Offline

Board footer