Hi,
I think it was about a year ago when I first proposed this, there was
some feedback and I reworked the code but looking back I don't think I
ever resubmitted - so here's a second go!
Basically if you make use of usb storage devices and specifically if
you want to have services make use of the storage from service start
time (for example, collectd or syslog-ng etc.) then you have a problem
... the usb device is mounted much too late in the boot sequence and
you'll find the services writing "underneath" the mount point.
Also, you may want to only start the service once the device is plugged
in (well after the boot sequence) ... can't think of a good example
here, but it's probably better to do the right thing with hotplug rather
than to hack around with the startup sequence.
So the basic idea is that in the fstab config you can specify that
specific services are started once the filesystem is mounted, this is
then handled by the hotplug system. There's also a menuconfig option to
allow you to specific services that aren't started at boot time (since
that's the default.)
This is made up of a patch to package/Makefile to handle the
non-auto-starting of services, and then a new package which I've called
block-hotplug-svcs.
An example /etc/config/fstab entry:
config mount
option target /site
option device /dev/sda1
option fstype ext4
option options rw,sync,noatime
list service syslog-ng
option enabled 1
option enabled_fsck 1
The code below is probably space mangled, but it's really there for
comment for now
Index: package/Makefile
===================================================================
--- package/Makefile (revision 30306)
+++ package/Makefile (working copy)
@@ -79,6 +79,7 @@
cd $(TARGET_DIR); \
for script in ./etc/init.d/*; do \
grep '#!/bin/sh /etc/rc.common' $$script
>/dev/null || continue; \
+ echo $(CONFIG_NO_AUTO_ENABLE_SERVICES) | grep
-v -w `basename $$script` > /dev/null || continue; \
IPKG_INSTROOT=$(TARGET_DIR) $$(which bash)
./etc/rc.common $$script enable; \
done || true \
)
Then the new package....
Config.in
===================================================================
config NO_AUTO_ENABLE_SERVICES
string
prompt "Services to not auto enable in the image"
depends on PACKAGE_block-hotplug-svcs
default ""
help
All packages are enabled in the image by default. If we need
to start services using this service then we need
to list the ones we dont want enabled.
Makefile
===================================================================
#
# Copyright (C) 2006-2009 OpenWrt.org
# Copyright 2010 Vertical Communications
# This is free software, licensed under the GNU General Public License
v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=block-hotplug-svcs
PKG_VERSION:=0.1.0
PKG_RELEASE:=1
include $(INCLUDE_DIR)/package.mk
define Package/block-hotplug-svcs
SECTION:=ob
CATEGORY:=Owls Barn
TITLE:=Start services after block hotplug event
DEPENDS:=+block-mount +hotplug2
endef
define Package/block-hotplug-svcs/config
source "$(SOURCE)/Config.in"
endef
define Package/block-hotplug-svcs/description
Scripts used to automatically start services after a hotplug event
(filesystem mount)
endef
define Build/Compile
endef
define Package/block-hotplug-svcs/install
$(INSTALL_DIR) $(1)/etc/hotplug.d/block
$(INSTALL_DATA) ./files/60-services $(1)/etc/hotplug.d/block/
endef
$(eval $(call BuildPackage,block-hotplug-svcs))
files/60-services
===================================================================
#!/bin/sh
. /etc/functions.sh
start_service() {
/etc/init.d/$1 $2
}
find_device() {
local cfg="$1"
local hotdev="$2"
local action="$3"
local enabled
local device
config_get device "$cfg" device
config_get_bool enabled "$cfg" enabled 0
[ $enabled -lt 1 ] && return
[ $action = "start" ] && {
grep -q "$hotdev" /proc/mounts || return
}
[ "$device" = "$hotdev" ] && {
config_get target "$1" target
config_list_foreach "$1" "service" start_service
$action
}
}
config_load fstab
case "$ACTION" in
add)
config_foreach find_device mount "/dev/$DEVNAME"
"start"
;;
remove)
config_foreach find_device mount "/dev/$DEVNAME" "stop"
;;
esac
_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel