Optware / Optware-ng

279 stars 52 forks source link

Dbus startup script behaves incorretcly while "orphan" /opt/var/run/dbus/pid file exists #162

Closed PiotrC1 closed 8 years ago

PiotrC1 commented 8 years ago

Dbus startup script cannot start dbus while orphan /opt/var/run/dbus/pid file exists. Also it tres to stop nonexisting process. Solution is adding in the beginning of S20dbus following lines:

if ! pidof dbus-daemon 1>/dev/null 2>&1; then
   rm -f ${PIDDIR}/pid
fi

Also, script tries to killall /opt/bin/dbus-daemon what is incorrect is should be killall dbus-daemon

PiotrC1 commented 8 years ago

I propose following modified file

#! /bin/sh
OPTWARE_TARGET=buildroot-armeabi-ng
# -*- coding: utf-8 -*-
# Debian init.d script for D-BUS
# Copyright © 2003 Colin Walters <walters@debian.org>

PATH=$PATH:/opt/bin:/opt/sbin

#if grep -q ^messagebus: /etc/group; then
#   # echo There already is an messagebus group on the system.
#   ADDUSER_OPT="-G messagebus"
#fi

#if grep -q ^messagebus: /etc/passwd; then
#   # echo There already is an messagebus user on the system.
#   true
#else
#   echo -n "No messagebus user found, creating it... "
#   adduser -h /opt/var/run/dbus -g "messagebus daemon" -s /bin/false -D -H $ADDUSER_OPT messagebus > /dev/null 2>&1
#   echo done
#fi

set -e

DADIR=/opt/bin
DAEMON=dbus-daemon
NAME=dbus
DAEMONUSER=nobody
PIDDIR=/opt/var/run/dbus
PIDFILE=$PIDDIR/pid
DESC="system message bus"

test -x $DADIR/$DAEMON || exit 0

if ! pidof $DAEMON 1>/dev/null 2>&1; then
    rm -f ${PIDFILE}
fi

# Source defaults file; edit that file to configure this script.
ENABLED=1
PARAMS=""
if [ -e /opt/etc/default/dbus ]; then
  . /opt/etc/default/dbus
fi

test "$ENABLED" != "0" || exit 0

start_it_up()
{
  if [ ! -d $PIDDIR ]; then
    mkdir -p $PIDDIR
    chown $DAEMONUSER $PIDDIR
    chgrp $DAEMONUSER $PIDDIR
  fi
  if [ -e $PIDFILE ]; then
    echo "$DESC already started; not starting."
  else
    echo -n "Starting $DESC: "
    ${DAEMON} --system $PARAMS
    echo "$NAME."
  fi
}

shut_it_down()
{
  echo -n "Stopping $DESC: "
  if [ -e $PIDFILE ]; then
    kill `cat $PIDFILE`
  else
    killall ${DAEMON}
  fi
  echo "$NAME."
  rm -f $PIDFILE
}

case "$1" in
  start)
    start_it_up
  ;;
  stop)
    shut_it_down
  ;;
  restart|force-reload)
    shut_it_down
    sleep 1
    start_it_up
  ;;
  *)
    echo "Usage: $0 {start|stop|restart|force-reload}" >&2
    exit 1
  ;;
esac

exit 0
alllexx88 commented 8 years ago

@PiotrC1 Current rc.script is indeed flawed. However, I think it's better to use start-stop-daemon, like with cups init script.

PiotrC1 commented 8 years ago

OK, up to you.

alllexx88 commented 8 years ago

Please test recent upgrade

PiotrC1 commented 8 years ago

Hi! I got following messages during upgrade:

root@Tomato:/tmp/home/root# ipkg update Downloading http://ipkg.nslu2-linux.org/optware-ng/buildroot-armeabi-ng/Packages.gz. Inflating http://ipkg.nslu2-linux.org/optware-ng/buildroot-armeabi-ng/Packages.gz. Updated list of available packages in /opt/lib/ipkg/lists/optware-ng. root@Tomato:/tmp/home/root# ipkg upgrade Upgrading libdbus from 1.11.4-2 to 1.11.4-3 on /opt/. Downloading http://ipkg.nslu2-linux.org/optware-ng/buildroot-armeabi-ng/libdbus_1.11.4-3_arm.ipk. Upgrading dbus from 1.11.4-2 to 1.11.4-3 on /opt/. Downloading http://ipkg.nslu2-linux.org/optware-ng/buildroot-armeabi-ng/dbus_1.11.4-3_arm.ipk. adduser was autoinstalled and is now orphaned, removing. Removing package adduser from /opt/... update-alternatives: removing //opt/bin/chpasswd as no more alternatives exist for it update-alternatives: removing //opt/bin/cryptpw as no more alternatives exist for it update-alternatives: removing //opt/bin/getty as no more alternatives exist for it update-alternatives: removing //opt/bin/login as no more alternatives exist for it update-alternatives: removing //opt/bin/mkpasswd as no more alternatives exist for it update-alternatives: removing //opt/bin/passwd as no more alternatives exist for it update-alternatives: removing //opt/bin/su as no more alternatives exist for it update-alternatives: removing //opt/bin/sulogin as no more alternatives exist for it update-alternatives: removing //opt/bin/vlock as no more alternatives exist for it Not upgrading package adduser which is marked replace (flags=0x84). Configuring libdbus. Configuring dbus. Generating /opt/etc/machine-id system message bus already started; not starting. Collected errors:

  • resolve_conffiles: Existing conffile /opt/etc/init.d/S20dbus is different from the conffile in the new package. The new conffile will be placed at /opt/etc/init.d/S20dbus-opkg.

Is it OK?

PiotrC1 commented 8 years ago

I confirm that after new install adduser is missing as well.

alllexx88 commented 8 years ago

@PiotrC1

adduser was autoinstalled and is now orphaned, removing. Removing package adduser from /opt/... update-alternatives: removing //opt/bin/chpasswd as no more alternatives exist for it update-alternatives: removing //opt/bin/cryptpw as no more alternatives exist for it update-alternatives: removing //opt/bin/getty as no more alternatives exist for it update-alternatives: removing //opt/bin/login as no more alternatives exist for it update-alternatives: removing //opt/bin/mkpasswd as no more alternatives exist for it update-alternatives: removing //opt/bin/passwd as no more alternatives exist for it update-alternatives: removing //opt/bin/su as no more alternatives exist for it update-alternatives: removing //opt/bin/sulogin as no more alternatives exist for it update-alternatives: removing //opt/bin/vlock as no more alternatives exist for it

Since I changed default dbus user/group to 'nobody', adduser dependency isn't needed any more.

  • resolve_conffiles: Existing conffile /opt/etc/init.d/S20dbus is different from the conffile in the new package. The new conffile will be placed at /opt/etc/init.d/S20dbus-opkg.

That's because you manually edited /opt/etc/init.d/S20dbus, which is marked as config file. To restore package provided, run mv -f /opt/etc/init.d/S20dbus-opkg /opt/etc/init.d/S20dbus