* [Buildroot] [RFC v2 0/5] common service startup files
@ 2015-04-05 22:01 Alex Suykov
2015-04-05 22:01 ` [Buildroot] [RFC v2 1/6] " Alex Suykov
` (7 more replies)
0 siblings, 8 replies; 13+ messages in thread
From: Alex Suykov @ 2015-04-05 22:01 UTC (permalink / raw)
To: buildroot
This series is intended to simplify and clean up installation routine
for daemon-like applications, merging sysv and systemd startup files
and moving much of the common code out of per-package .mk files.
Currently buildroot requires pre-crafted sysv and/or systemd startup
files to be supplied for each package that needs its daemon-like
processes started at system boot. In many cases, this is redundant.
Only a small part of the startup scripts is package-specific.
A single command, the one that starts the process in foreground mode,
is typically enough to generate usable sysv and systemd startup files.
Separating package-specific data and removing the rest from package
directories allows changing common code without the need to patch
several dozen packages, ensures more or less even support for sysv
and systemd, and potentially simplifies introduction of alternative
system startup schemes.
The first patch in the series contains the common code, and the rest
show how it affects individual packages. I'm only posting a few
interesting ones with comments; the full set (~50 patches) is available
here: https://github.com/arsv/br/ branch run-1.
---
v2 changes: this part of the v1 series is now standalone, the script
got simplified a lot, and it now requires explicit variables instead
of just picking up files from the package directory.
Run files format reverted to "key: value" with explicit keys.
It is still somewhat custom, and the script is still in python however.
Non-daemon script support dropped completely, and some rare complex
cases like postgres dropped as well.
Hard-coded paths removed, TARGET_DIR is used when appropriate.
Variable substitution and special cases are now handled in package
makefiles, not in the script.
--
2.0.3
^ permalink raw reply [flat|nested] 13+ messages in thread* [Buildroot] [RFC v2 1/6] common service startup files 2015-04-05 22:01 [Buildroot] [RFC v2 0/5] common service startup files Alex Suykov @ 2015-04-05 22:01 ` Alex Suykov 2015-04-05 22:02 ` [Buildroot] [RFC v2 2/6] squid: common service startup Alex Suykov ` (6 subsequent siblings) 7 siblings, 0 replies; 13+ messages in thread From: Alex Suykov @ 2015-04-05 22:01 UTC (permalink / raw) To: buildroot This patch introduces support infrastructure for per-project .run files containing the information needed to generate either sysv intiscripts or systemd services in a common format. Packages are expected to set $(PKG)_INIT_RUN = list of .run files to install in their .mk files, allowing pkg-generic to call support/init/install with appropriate arguments. Alternatively, packages may define $(PKG)_INSTALL_INIT, calling support/init/install themselves or doing something more elaborate. Packages may also define $(PKG)_INSTALL_INIT_SYSV or _SYSTEMD, overriding non-specific _INSTALL_INIT. The format of the .run files is simple set of "key: value" lines, reflecting the structure of the data while also being somewhat readable. Explicit $(PKG)_INIT_RUN in every .mk file provides clues for unaware users regarding the purpose of otherwise unremarkable .run files. INIT_RUN string is grepable. Signed-off-by: Alex Suykov <alex.suykov@gmail.com> --- package/pkg-generic.mk | 26 +++- package/pkg-utils.mk | 4 + support/init/install | 349 +++++++++++++++++++++++++++++++++++++++++++++++++ system/Config.in | 6 + 4 files changed, 381 insertions(+), 4 deletions(-) create mode 100755 support/init/install diff --git a/package/pkg-generic.mk b/package/pkg-generic.mk index 0d95541..833f9b5 100644 --- a/package/pkg-generic.mk +++ b/package/pkg-generic.mk @@ -235,10 +235,7 @@ $(BUILD_DIR)/%/.stamp_target_installed: @$(call MESSAGE,"Installing to target") $(foreach hook,$($(PKG)_PRE_INSTALL_TARGET_HOOKS),$(call $(hook))$(sep)) +$($(PKG)_INSTALL_TARGET_CMDS) - $(if $(BR2_INIT_SYSTEMD),\ - $($(PKG)_INSTALL_INIT_SYSTEMD)) - $(if $(BR2_INIT_SYSV)$(BR2_INIT_BUSYBOX),\ - $($(PKG)_INSTALL_INIT_SYSV)) + +$($(PKG)_INSTALL_INIT_$(INIT)) $(foreach hook,$($(PKG)_POST_INSTALL_TARGET_HOOKS),$(call $(hook))$(sep)) $(Q)if test -n "$($(PKG)_CONFIG_SCRIPTS)" ; then \ $(RM) -f $(addprefix $(TARGET_DIR)/usr/bin/,$($(PKG)_CONFIG_SCRIPTS)) ; \ @@ -763,6 +760,27 @@ ifneq ($$(call suitable-extractor,$$($(2)_SOURCE)),$$(XZCAT)) DL_TOOLS_DEPENDENCIES += $$(firstword $$(call suitable-extractor,$$($(2)_SOURCE))) endif +ifeq ($(4),target) + +ifndef $(3)_INSTALL_INIT + ifdef $(3)_INIT_RUN + define $(3)_INSTALL_INIT + support/init/install $(BR2_INIT) $(TARGET_DIR) \ + $$(addprefix $(pkgdir),$$($(3)_INIT_RUN)) + endef + endif +endif + +# Init-specific rules override generic INSTALL_INIT +ifndef $(3)_INSTALL_INIT_$(INIT) + ifdef $(3)_INSTALL_INIT + $(3)_INSTALL_INIT_$(INIT) = $$($(3)_INSTALL_INIT) + endif +endif + +endif # $(4) == target + + endif # $(2)_KCONFIG_VAR endef # inner-generic-package diff --git a/package/pkg-utils.mk b/package/pkg-utils.mk index 7eddc47..057a693 100644 --- a/package/pkg-utils.mk +++ b/package/pkg-utils.mk @@ -76,6 +76,10 @@ INFLATE.tar = cat # suitable-extractor(filename): returns extractor based on suffix suitable-extractor = $(INFLATE$(suffix $(1))) +# Uppercase init name suitable for use in variables +# BR2_INIT="sysv" INIT=SYSV +INIT = $(call UPPERCASE,$(call qstrip,$(BR2_INIT))) + # MESSAGE Macro -- display a message in bold type MESSAGE = echo "$(TERM_BOLD)>>> $($(PKG)_NAME) $($(PKG)_VERSION) $(call qstrip,$(1))$(TERM_RESET)" TERM_BOLD := $(shell tput smso) diff --git a/support/init/install b/support/init/install new file mode 100755 index 0000000..f5f21de --- /dev/null +++ b/support/init/install @@ -0,0 +1,349 @@ +#!/usr/bin/env python + +# Usage: +# +# support/init/install init-system target-directory file1.run file2.run ... +# +# Each .run file describes a single daemon to be spawned on system startup. +# This script turns .run into relevant files for init-system and writes +# those to target-directory. +# +# Expected format of the .run files: +# +# # comment +# description: Some sample daemon +# umask: 077 +# foreground: /sbin/daemon -A -b 7000 +# +# The first word is the key, the rest is value. See Run.__init__ below +# for the list of possible keys. +# +# Most daemons should only need foreground: line, which is the command +# to start it in foreground (non-forking) mode. + +# Typical test run: +# +# .../support/init/install sysv . foo.run +# +# that should create ./etc/init.d/S50foo or something similar. + +# Bundling all init systems into a single script, vs having install-init-(system) +# scripts for each system, may look strange, but it turns out large parts of the +# code below are common for all init systems. + +import re +import os +import sys + +class Run: + class ParseError(Exception): pass + class KeywordError(Exception): pass + class ConfigError(Exception): pass + + def __init__(self, path): + self.name = None + self.path = None + + # possible keywords in the .run file + self.attr = { + # process properties + 'pidfile': None, # if set, assume the daemon writes it + 'umask': None, + 'user': None, # effective uid to run the daemon as + 'group': None, # effecitve gid + # non-process info + 'description': None, # systemd, and comment in initscripts + 'after': None, # systemd only + 'priority': None, # sysv only + # commands to run + 'prestart': [ ], # commands to run before starting the daemon + 'foreground': None, # command to start the daemon in fg mode + 'background': None, # same, in background mode + # (the daemon is assumed to fork) + + 'start': None, # sysv-specific, skips start-stop-daemon + 'stop': None, # sysv-specific, skips start-stop-daemon + 'reload': None # both sysv and systemd can use this + } + + # constructing Run from a file means parsing that file + if path: self.parse(path) + + # [] to access .attr dictionary + def __setitem__(self, key, val): + if key not in self.attr: + raise Run.KeywordError(key) + if type(self.attr[key]) is list: + self.attr[key].append(val) + else: + self.attr[key] = val + + def __getitem__(self, key): + return self.attr[key] + + # Input file has simple "key any-string-value" structure + # for all significant lines, possibly also comments and empty + # lines. This reads it into attr[]. + def parse(self, path): + self.path = path + self.name = re.sub(r'\..*', '', os.path.basename(path)) + with open(path) as fh: + for lnum, line in enumerate(fh, 1): + line = line.strip() + + # skip comments and empty lines + if line[0] == '#' or not re.match(r'\S', line): + continue + + m = re.match(r'^([a-z]+):\s+(.*)', line) + if not m: + raise Run.ParseError(path, lnum, 'bad line format') + try: + self[m.group(1)] = m.group(2) + except Run.KeywordError as e: + raise Run.ParseError(path, lnum, 'unknown keyword %s' % e.args[0]) + +def die(message, *args): + sys.stderr.write((message+"\n") % tuple(args)) + exit(-1) + +# Directory structure under $TARGET_DIR is init-specific +# and may not be there by the time init/install gets called. +# mode is 0644 for systemd services but 0755 for initscripts. +def openmode(path, mode): + pathdir = os.path.dirname(path) + if not os.path.isdir(pathdir): + os.makedirs(pathdir) + fd = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC) + os.fchmod(fd, mode) + return os.fdopen(fd, 'w') + +# ------------------------------------------------------------------------------ + +# Sysv initscripts are expected to spawn background daemons, tracking them +# via pid files. In case background line was supplied, it will be used, +# otherwise start-stop-daemon will use foreground command and fork/daemonize +# the process itself. +# +# Pre-start commands naturally go to the start) block. + +class Initscript(Run): + ssd = '/sbin/start-stop-daemon' + + def write(self, targetdir): + scriptname = '%s/etc/init.d/S%s%s' % (targetdir, self.priority(), self.name) + script = openmode(scriptname, 0o755) + + def caseblock(patt, lines): + script.write("\t%s)\n" % patt) + for line in lines: + if not line is None: + script.write("\t\t%s\n" % line) + script.write("\t\t;;\n") + + script.write("#!/bin/sh\n\n") + if self['description']: + script.write("# %s\n\n" % self['description']) + script.write("case \"$1\" in\n") + caseblock('start', self.start()) + caseblock('stop', self.stop()) + # XXX: is it needed / does anyone use this? + if self['reload']: + caseblock('reload', [self['reload']]) + caseblock('restart', ['$0 stop', 'sleep 1', '$0 start']) + else: + caseblock('reload|restart', ['$0 stop', 'sleep 1', '$0 start']) + script.write("esac\n") + + script.close() + + # Priority field (that 50 in S50foo) gets almost no use in buildroot + # since the stuff that needs strict order (mounts, swap and such) + # happens directly in inittab. For the services installed via .run files, + # the idea is to do sysinit first, then start daemons. + # For (rare) case that do not fit, allow specifying it explicitly. + def priority(self): + if self['priority']: + return self['priority'] + else: + return '50' + + def pidfile(self): + if self['pidfile']: + return self['pidfile'] + else: + return'/var/run/%s' % self.name + + def start(self): + if self['start']: + return [self['start']] + + start = [ self.ssd, '-S' ] + if self['user']: + start.extend(['-c', self['user']]) + if self['group']: + start.extend(['-g', self['group']]) + + start.extend(['-p', self.pidfile()]) + + if self['umask']: + start.extend(['-k', self['umask']]) + + # start-stop-daemon requires -- before command args + def dashdashargs(cmd): + return re.sub(r'\s+', ' -- ', cmd, 1) + + # When running services in background mode, prefer background + # commands since they tend to be simplier (as in, an option + # required to prevent forking) + if self['background']: + start.append(dashdashargs(self['background'])) + elif self['foreground']: + start.extend(['-m', '-b', dashdashargs(self['foreground'])]) + else: + raise Run.ConfigError(self.path, "no process to start") + + cmds = self['prestart'][:] + cmds.append(" ".join(start)) + + return cmds + + def stop(self): + if self['stop']: + return [self['stop']] + else: + # do not bother checking executable name, + # it does not improve things much + return ["%s -K -p %s" % (self.ssd, self.pidfile())] + +# ------------------------------------------------------------------------------ + +# Systemd .service files are essentially .run files with slightly different +# key names and completely pointless sections. +# Foreground command is preferred, but background can be used as well. + +class Service(Run): + sysdir = '/usr/lib/systemd/system' + + def write(self, targetdir): + filename = '%s%s/%s.service' % (targetdir, self.sysdir, self.name) + service = openmode(filename, 0o644) + + def writefield(tag, key = None): + if key is None: + key = tag.lower() + if(self[key]): + service.write("%s=%s\n" % (tag, self[key])) + + service.write("[Unit]\n") + writefield('Description') + if self['after']: + service.write("After=%s\n" % self.after()) + + service.write("\n") + service.write("[Service]\n") + writefield('UMask') + writefield('User') + writefield('Group') + + # not needed to control foreground services + if not self['foreground']: + writefield('PIDFile') + + for cmd in self['prestart']: + service.write("ExecStartPre=%s\n" % cmd) + + if self['foreground']: + # Type=simple is the default + service.write("ExecStart=%s\n" % self['foreground']) + elif self['background']: + service.write("Type=forking\n") + service.write("ExecStart=%s\n" % self['background']) + else: + raise Run.ConfigError(self.path, "no process to start") + + writefield('ExecStop', 'stop') + writefield('ExecReload', 'reload') + + # systemd does not object against including this with + # Type=forking and can apparently restart forking daemons + # in some cases. + service.write("Restart=always\n") + + # systemd default is to setuid/setgid for prestart entries. + # That's the opposite of what initscripts do. For now, just + # force initscripts behavior and do not bother with possible + # su invocactions. + if self['prestart']: + service.write("PermissionsStartOnly=true\n") + + # Buildroot does not use targets. Just boot into the default multi-user. + service.write("\n") + service.write("[Install]\n") + service.write("WantedBy=%s\n" % 'multi-user.target') + + Service.enable(filename, 'multi-user.target') + + # systemd needs dependency specification to order entries, + # and just throwing "syslog network audit" on every single + # entry does not look like a good solution (though it would + # likely work). + # + # To simplify things a bit, and to allow possible use for + # non-systemd inits, allow using short-hand notation like + # "syslog network" instead of "syslog.target network.target". + # + # Non-suffixed entries in After make no sense, so there is no + # problem in mixing shorthands and raw unit names. + + shorthand = { + 'network': 'network.target', + 'syslog': 'syslog.target', + 'auditd': 'auditd.service' } + + def after(self): + after = [ ] + for unit in self['after'].split(): + if unit in self.shorthand: + unit = self.shorthand[unit] + after.append(unit) + return " ".join(after) + + # Mimic current BR systemd installation routines and create + # relevant symlinks to make the service "enabled". + # + # XXX: this should be in support/init/finalize, not here. + + def enable(filename, wantedby): + base = os.path.basename(filename) + link = "%s/%s.wants/%s" % (os.path.dirname(filename), wantedby, base) + ldir = os.path.dirname(link) + if os.path.islink(link): + os.unlink(link) + if not os.path.isdir(ldir): + os.makedirs(ldir) + os.symlink("../" + base, link) + + +# ------------------------------------------------------------------------------ + +if len(sys.argv) < 2: + die("Usage: support/init/install init-system target-dir file.run file.run ...") + +try: + init = { + # init-system: parser-class + 'sysv': Initscript, + 'systemd': Service + }[sys.argv[1]] +except KeyError: + die("Unknown init system %s", sys.argv[1]) + +try: + for f in sys.argv[3:]: + if f.endswith('.run'): + init(f).write(sys.argv[2]) +except Run.ParseError as e: + die("%s:%s: %s", *e.args) +except Run.ConfigError as e: + die("%s: %s", *e.args) diff --git a/system/Config.in b/system/Config.in index 935f7a1..b654e39 100644 --- a/system/Config.in +++ b/system/Config.in @@ -107,6 +107,12 @@ config BR2_INIT_NONE endchoice +config BR2_INIT + string + default "sysv" if BR2_INIT_SYSV || BR2_INIT_BUSYBOX + default "systemd" if BR2_INIT_SYSTEMD + default "none" + choice prompt "/dev management" if !BR2_INIT_SYSTEMD default BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_DEVTMPFS -- 2.0.3 ^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Buildroot] [RFC v2 2/6] squid: common service startup 2015-04-05 22:01 [Buildroot] [RFC v2 0/5] common service startup files Alex Suykov 2015-04-05 22:01 ` [Buildroot] [RFC v2 1/6] " Alex Suykov @ 2015-04-05 22:02 ` Alex Suykov 2015-04-05 22:02 ` [Buildroot] [RFC v2 3/6] dropbear: " Alex Suykov ` (5 subsequent siblings) 7 siblings, 0 replies; 13+ messages in thread From: Alex Suykov @ 2015-04-05 22:02 UTC (permalink / raw) To: buildroot A typical simple daemon. Signed-off-by: Alex Suykov <alex.suykov@gmail.com> --- package/squid/S97squid | 40 ---------------------------------------- package/squid/squid.mk | 5 +---- package/squid/squid.run | 3 +++ 3 files changed, 4 insertions(+), 44 deletions(-) delete mode 100755 package/squid/S97squid create mode 100644 package/squid/squid.run diff --git a/package/squid/S97squid b/package/squid/S97squid deleted file mode 100755 index b30af5b..0000000 --- a/package/squid/S97squid +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/sh - -[ -x /usr/sbin/squid ] || exit 0 -[ -f /etc/squid.conf ] || exit 0 - -case "$1" in - start) - echo -n "Starting squid: " - if [ ! -d /var/log/squid ]; then - mkdir -p /var/log/squid - chown squid:squid /var/log/squid - fi - start-stop-daemon -S -x /usr/sbin/squid - [ $? = 0 ] && echo "OK" || echo "FAIL" - ;; - - stop) - echo -n "Stopping squid: " - /usr/sbin/squid -k shutdown - [ $? = 0 ] && echo "OK" || echo "FAIL" - ;; - - reload) - echo -n "Reloading squid configuration: " - /usr/sbin/squid -k reconfigure - [ $? = 0 ] && echo "OK" || echo "FAIL" - ;; - - restart) - echo -n "Restarting squid: " - /usr/sbin/squid -k restart - [ $? = 0 ] && echo "OK" || echo "FAIL" - ;; - - *) - echo "Usage: $0 {start|stop|reload|restart}" - exit 1 -esac - -exit 0 diff --git a/package/squid/squid.mk b/package/squid/squid.mk index f4d6ae3..52209bd 100644 --- a/package/squid/squid.mk +++ b/package/squid/squid.mk @@ -76,9 +76,6 @@ define SQUID_USERS squid -1 squid -1 * - - - Squid proxy cache endef -define SQUID_INSTALL_INIT_SYSV - $(INSTALL) -m 755 -D package/squid/S97squid \ - $(TARGET_DIR)/etc/init.d/S97squid -endef +SQUID_INIT_RUN = squid.run $(eval $(autotools-package)) diff --git a/package/squid/squid.run b/package/squid/squid.run new file mode 100644 index 0000000..12c2a52 --- /dev/null +++ b/package/squid/squid.run @@ -0,0 +1,3 @@ +description: Squid proxy server +prestart: mkdir -p /var/log/squid +foreground: /usr/sbin/squid -N -- 2.0.3 ^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Buildroot] [RFC v2 3/6] dropbear: common service startup 2015-04-05 22:01 [Buildroot] [RFC v2 0/5] common service startup files Alex Suykov 2015-04-05 22:01 ` [Buildroot] [RFC v2 1/6] " Alex Suykov 2015-04-05 22:02 ` [Buildroot] [RFC v2 2/6] squid: common service startup Alex Suykov @ 2015-04-05 22:02 ` Alex Suykov 2015-04-05 22:03 ` [Buildroot] [RFC v2 4/6] samba4: " Alex Suykov ` (4 subsequent siblings) 7 siblings, 0 replies; 13+ messages in thread From: Alex Suykov @ 2015-04-05 22:02 UTC (permalink / raw) To: buildroot Relatively complex case, with umask and autid dependency. Signed-off-by: Alex Suykov <alex.suykov@gmail.com> --- package/dropbear/S50dropbear | 43 --------------------------------------- package/dropbear/dropbear.mk | 13 +----------- package/dropbear/dropbear.run | 6 ++++++ package/dropbear/dropbear.service | 10 --------- 4 files changed, 7 insertions(+), 65 deletions(-) delete mode 100644 package/dropbear/S50dropbear create mode 100644 package/dropbear/dropbear.run delete mode 100644 package/dropbear/dropbear.service diff --git a/package/dropbear/S50dropbear b/package/dropbear/S50dropbear deleted file mode 100644 index 2694931..0000000 --- a/package/dropbear/S50dropbear +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/sh -# -# Starts dropbear sshd. -# - -# Allow a few customizations from a config file -test -r /etc/default/dropbear && . /etc/default/dropbear - -start() { - DROPBEAR_ARGS="$DROPBEAR_ARGS -R" - - echo -n "Starting dropbear sshd: " - umask 077 - start-stop-daemon -S -q -p /var/run/dropbear.pid \ - --exec /usr/sbin/dropbear -- $DROPBEAR_ARGS - [ $? = 0 ] && echo "OK" || echo "FAIL" -} -stop() { - echo -n "Stopping dropbear sshd: " - start-stop-daemon -K -q -p /var/run/dropbear.pid - [ $? = 0 ] && echo "OK" || echo "FAIL" -} -restart() { - stop - start -} - -case "$1" in - start) - start - ;; - stop) - stop - ;; - restart|reload) - restart - ;; - *) - echo "Usage: $0 {start|stop|restart}" - exit 1 -esac - -exit $? diff --git a/package/dropbear/dropbear.mk b/package/dropbear/dropbear.mk index bc65d69..fdd83f4 100644 --- a/package/dropbear/dropbear.mk +++ b/package/dropbear/dropbear.mk @@ -51,19 +51,8 @@ define DROPBEAR_DISABLE_STANDALONE $(SED) 's:\(#define NON_INETD_MODE\):/*\1 */:' $(@D)/options.h endef -define DROPBEAR_INSTALL_INIT_SYSTEMD - $(INSTALL) -D -m 644 package/dropbear/dropbear.service \ - $(TARGET_DIR)/usr/lib/systemd/system/dropbear.service - mkdir -p $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants - ln -fs ../../../../usr/lib/systemd/system/dropbear.service \ - $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants/dropbear.service -endef - ifeq ($(BR2_USE_MMU),y) -define DROPBEAR_INSTALL_INIT_SYSV - $(INSTALL) -D -m 755 package/dropbear/S50dropbear \ - $(TARGET_DIR)/etc/init.d/S50dropbear -endef +DROPBEAR_INIT_RUN = dropbear.run else DROPBEAR_POST_EXTRACT_HOOKS += DROPBEAR_DISABLE_STANDALONE endif diff --git a/package/dropbear/dropbear.run b/package/dropbear/dropbear.run new file mode 100644 index 0000000..f50153d --- /dev/null +++ b/package/dropbear/dropbear.run @@ -0,0 +1,6 @@ +description: Dropbear SSH daemon +umask: 077 +pidfile: /var/run/dropbear.pid +after: syslog network auditd +background: /usr/sbin/dropbear -R +foreground: /usr/sbin/dropbear -F -R diff --git a/package/dropbear/dropbear.service b/package/dropbear/dropbear.service deleted file mode 100644 index 4e6c879..0000000 --- a/package/dropbear/dropbear.service +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=Dropbear SSH daemon -After=syslog.target network.target auditd.service - -[Service] -ExecStart=/usr/sbin/dropbear -F -R -ExecReload=/bin/kill -HUP $MAINPID - -[Install] -WantedBy=multi-user.target -- 2.0.3 ^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Buildroot] [RFC v2 4/6] samba4: common service startup 2015-04-05 22:01 [Buildroot] [RFC v2 0/5] common service startup files Alex Suykov ` (2 preceding siblings ...) 2015-04-05 22:02 ` [Buildroot] [RFC v2 3/6] dropbear: " Alex Suykov @ 2015-04-05 22:03 ` Alex Suykov 2015-04-05 22:04 ` [Buildroot] [RFC v2 5/6] gpsd: " Alex Suykov ` (3 subsequent siblings) 7 siblings, 0 replies; 13+ messages in thread From: Alex Suykov @ 2015-04-05 22:03 UTC (permalink / raw) To: buildroot Two daemons per package, each gets it own .run file. This will result in two .service files (which is the only way with systemd) and two initscripts. Signed-off-by: Alex Suykov <alex.suykov@gmail.com> --- package/samba4/S91smb | 56 ------------------------------------------------ package/samba4/nmbd.run | 3 +++ package/samba4/samba4.mk | 6 +----- package/samba4/smbd.run | 3 +++ 4 files changed, 7 insertions(+), 61 deletions(-) delete mode 100644 package/samba4/S91smb create mode 100644 package/samba4/nmbd.run create mode 100644 package/samba4/smbd.run diff --git a/package/samba4/S91smb b/package/samba4/S91smb deleted file mode 100644 index ce14e19..0000000 --- a/package/samba4/S91smb +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/sh - -[ -f /etc/samba/smb.conf ] || exit 0 - -mkdir -p /var/log/samba - -start() { - echo -n "Starting SMB services: " - smbd -D - [ $? = 0 ] && echo "OK" || echo "FAIL" - - echo -n "Starting NMB services: " - nmbd -D - [ $? = 0 ] && echo "OK" || echo "FAIL" -} - -stop() { - echo -n "Shutting down SMB services: " - kill -9 `pidof smbd` - [ $? = 0 ] && echo "OK" || echo "FAIL" - - echo -n "Shutting down NMB services: " - kill -9 `pidof nmbd` - [ $? = 0 ] && echo "OK" || echo "FAIL" -} - -restart() { - stop - start -} - -reload() { - echo -n "Reloading smb.conf file: " - kill -HUP `pidof smbd` - [ $? = 0 ] && echo "OK" || echo "FAIL" -} - -case "$1" in - start) - start - ;; - stop) - stop - ;; - restart) - restart - ;; - reload) - reload - ;; - *) - echo "Usage: $0 {start|stop|restart|reload}" - exit 1 -esac - -exit $? diff --git a/package/samba4/nmbd.run b/package/samba4/nmbd.run new file mode 100644 index 0000000..225cc4c --- /dev/null +++ b/package/samba4/nmbd.run @@ -0,0 +1,3 @@ +description: Samba NMB daemon +prestart: mkdir -p /var/log/samba +foreground: /usr/sbin/nmbd -F diff --git a/package/samba4/samba4.mk b/package/samba4/samba4.mk index 78d92ef..bf424c2 100644 --- a/package/samba4/samba4.mk +++ b/package/samba4/samba4.mk @@ -13,6 +13,7 @@ SAMBA4_LICENSE_FILES = COPYING SAMBA4_DEPENDENCIES = host-e2fsprogs host-heimdal e2fsprogs popt python zlib \ $(if $(BR2_PACKAGE_LIBCAP),libcap) \ $(if $(BR2_PACKAGE_READLINE),readline) +SAMBA4_INIT_RUN = smbd.run nmbd.run ifeq ($(BR2_PACKAGE_ACL),y) SAMBA4_CONF_OPTS += --with-acl-support @@ -150,9 +151,4 @@ endef SAMBA4_POST_INSTALL_TARGET_HOOKS += SAMBA4_REMOVE_SMBTORTURE endif -define SAMBA4_INSTALL_INIT_SYSV - $(INSTALL) -m 0755 -D package/samba4/S91smb \ - $(TARGET_DIR)/etc/init.d/S91smb -endef - $(eval $(generic-package)) diff --git a/package/samba4/smbd.run b/package/samba4/smbd.run new file mode 100644 index 0000000..ae2f7ca --- /dev/null +++ b/package/samba4/smbd.run @@ -0,0 +1,3 @@ +description: Samba SMB daemon +prestart: mkdir -p /var/log/samba +foreground: /usr/sbin/smbd -F -- 2.0.3 ^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Buildroot] [RFC v2 5/6] gpsd: common service startup 2015-04-05 22:01 [Buildroot] [RFC v2 0/5] common service startup files Alex Suykov ` (3 preceding siblings ...) 2015-04-05 22:03 ` [Buildroot] [RFC v2 4/6] samba4: " Alex Suykov @ 2015-04-05 22:04 ` Alex Suykov 2015-04-05 22:04 ` [Buildroot] [RFC v2 6/6] acpid: " Alex Suykov ` (2 subsequent siblings) 7 siblings, 0 replies; 13+ messages in thread From: Alex Suykov @ 2015-04-05 22:04 UTC (permalink / raw) To: buildroot This package needs variable substitution in its .run file. Signed-off-by: Alex Suykov <alex.suykov@gmail.com> --- package/gpsd/S50gpsd | 40 ---------------------------------------- package/gpsd/gpsd.mk | 9 ++++++--- package/gpsd/gpsd.run | 3 +++ 3 files changed, 9 insertions(+), 43 deletions(-) delete mode 100644 package/gpsd/S50gpsd create mode 100644 package/gpsd/gpsd.run diff --git a/package/gpsd/S50gpsd b/package/gpsd/S50gpsd deleted file mode 100644 index 6e5ce88..0000000 --- a/package/gpsd/S50gpsd +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/sh -# -# Starts the gps daemon. -# - -NAME=gpsd -DAEMON=/usr/sbin/$NAME -DEVICES=/dev/ttyS1 -PIDFILE=/var/run/$NAME.pid - -start() { - echo -n "Starting $NAME: " - start-stop-daemon -S -q -p $PIDFILE --exec $DAEMON -- -P $PIDFILE $DEVICES && echo "OK" || echo "Failed" -} -stop() { - echo -n "Stopping $NAME: " - start-stop-daemon -K -q -p $PIDFILE && echo "OK" || echo "Failed" - rm -f $PIDFILE -} -restart() { - stop - start -} - -case "$1" in - start) - start - ;; - stop) - stop - ;; - restart|reload) - restart - ;; - *) - echo "Usage: $0 {start|stop|restart}" - exit 1 -esac - -exit $? diff --git a/package/gpsd/gpsd.mk b/package/gpsd/gpsd.mk index 9623d75..de0aec9 100644 --- a/package/gpsd/gpsd.mk +++ b/package/gpsd/gpsd.mk @@ -208,10 +208,13 @@ define GPSD_INSTALL_TARGET_CMDS install) endef -define GPSD_INSTALL_INIT_SYSV - $(INSTALL) -m 0755 -D package/gpsd/S50gpsd $(TARGET_DIR)/etc/init.d/S50gpsd - $(SED) 's,^DEVICES=.*,DEVICES=$(BR2_PACKAGE_GPSD_DEVICES),' $(TARGET_DIR)/etc/init.d/S50gpsd +ifdef BR2_PACKAGE_GPSD_DEVICES +define GPSD_INSTALL_INIT + cp package/gpsd/gpsd.run $(@D)/gpsd.run + $(SED) "s!DEVICES!$(call qstrip,$(BR2_PACKAGE_GPSD_DEVICES))!" $(@D)/gpsd.run + support/init/install $(BR2_INIT) $(TARGET_DIR) $(@D)/gpsd.run endef +endif define GPSD_INSTALL_STAGING_CMDS (cd $(@D); \ diff --git a/package/gpsd/gpsd.run b/package/gpsd/gpsd.run new file mode 100644 index 0000000..2cb8f4e --- /dev/null +++ b/package/gpsd/gpsd.run @@ -0,0 +1,3 @@ +description: GPS daemon +foreground: /usr/sbin/gpsd -N DEVICES +background: /usr/sbin/gpsd DEVICES -- 2.0.3 ^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Buildroot] [RFC v2 6/6] acpid: common service startup 2015-04-05 22:01 [Buildroot] [RFC v2 0/5] common service startup files Alex Suykov ` (4 preceding siblings ...) 2015-04-05 22:04 ` [Buildroot] [RFC v2 5/6] gpsd: " Alex Suykov @ 2015-04-05 22:04 ` Alex Suykov 2015-04-06 8:51 ` [Buildroot] [RFC v2 0/5] common service startup files Thomas Petazzoni 2015-04-22 21:11 ` Thomas Petazzoni 7 siblings, 0 replies; 13+ messages in thread From: Alex Suykov @ 2015-04-05 22:04 UTC (permalink / raw) To: buildroot Skipping systemd installation. Signed-off-by: Alex Suykov <alex.suykov@gmail.com> --- package/acpid/S02acpid | 22 ---------------------- package/acpid/acpid.mk | 8 +++----- package/acpid/acpid.run | 3 +++ 3 files changed, 6 insertions(+), 27 deletions(-) delete mode 100755 package/acpid/S02acpid create mode 100644 package/acpid/acpid.run diff --git a/package/acpid/S02acpid b/package/acpid/S02acpid deleted file mode 100755 index 0840305..0000000 --- a/package/acpid/S02acpid +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh - -case "$1" in - start) - echo -n "Starting acpid: " - start-stop-daemon -S -q -m -b -p /var/run/acpid.pid --exec /usr/sbin/acpid -- -n - [ $? = 0 ] && echo "OK" || echo "FAIL" - ;; - stop) - echo -n "Stopping acpid: " - start-stop-daemon -K -q -p /var/run/acpid.pid - [ $? = 0 ] && echo "OK" || echo "FAIL" - ;; - restart) - "$0" stop - sleep 1 - "$0" start - ;; - *) - echo "Usage: $0 {start|stop|restart}" - ;; -esac diff --git a/package/acpid/acpid.mk b/package/acpid/acpid.mk index 7a6a478..44acb3d 100644 --- a/package/acpid/acpid.mk +++ b/package/acpid/acpid.mk @@ -9,11 +9,9 @@ ACPID_SOURCE = acpid-$(ACPID_VERSION).tar.xz ACPID_SITE = http://downloads.sourceforge.net/project/acpid2 ACPID_LICENSE = GPLv2+ ACPID_LICENSE_FILES = COPYING - -define ACPID_INSTALL_INIT_SYSV - $(INSTALL) -D -m 0755 package/acpid/S02acpid \ - $(TARGET_DIR)/etc/init.d/S02acpid -endef +ifndef BR2_INIT_SYSTEMD +ACPID_INIT_RUN = acpid.run +endif define ACPID_SET_EVENTS mkdir -p $(TARGET_DIR)/etc/acpi/events diff --git a/package/acpid/acpid.run b/package/acpid/acpid.run new file mode 100644 index 0000000..056e5e5 --- /dev/null +++ b/package/acpid/acpid.run @@ -0,0 +1,3 @@ +description: ACPI daemon +foreground: /usr/sbin/acpid -f -n +background: /usr/sbin/acpid -n -- 2.0.3 ^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Buildroot] [RFC v2 0/5] common service startup files 2015-04-05 22:01 [Buildroot] [RFC v2 0/5] common service startup files Alex Suykov ` (5 preceding siblings ...) 2015-04-05 22:04 ` [Buildroot] [RFC v2 6/6] acpid: " Alex Suykov @ 2015-04-06 8:51 ` Thomas Petazzoni 2015-04-21 22:00 ` Yann E. MORIN 2015-04-22 12:44 ` Mike Williams 2015-04-22 21:11 ` Thomas Petazzoni 7 siblings, 2 replies; 13+ messages in thread From: Thomas Petazzoni @ 2015-04-06 8:51 UTC (permalink / raw) To: buildroot Dear Alex Suykov, On Mon, 6 Apr 2015 01:01:19 +0300, Alex Suykov wrote: > This series is intended to simplify and clean up installation routine > for daemon-like applications, merging sysv and systemd startup files > and moving much of the common code out of per-package .mk files. Thanks a lot for working on this. To be honest, my feeling is that I don't really like Buildroot to invent its own "abstract" language to describe the initialization of services, then used to generate SysV and Systemd unit files. There are two main reasons for this feeling. First of all, because the philosophy of Buildroot is to not invent new language, or add layers on top of what exists: we use Kconfig for the configuration, make for the package building logic, shell and Python scripts in some situations. This is all standard, and generally well known by most Linux developers. Even though the language you propose for describing the initialization of services is certainly not very complicated, it remains a layer on top of what really happens. Second, such abstract languages usually appear simple initially. But then, some corner cases show up, with cases that can easily be solved in shell scripts or systemd unit files, but were not planned in this small abstract language. So it has to be extended. Again, and again. To finally become as complicated as the shell scripts or systemd unit files. Of course, my opinion is just one amongst many other Buildroot developers, and if all other Buildroot developers are convinced that this is the way to go, then we'll do it. But since not many people gave their opinion about this, I thought I would simply give mine. Best regards, Thomas -- Thomas Petazzoni, CTO, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com ^ permalink raw reply [flat|nested] 13+ messages in thread
* [Buildroot] [RFC v2 0/5] common service startup files 2015-04-06 8:51 ` [Buildroot] [RFC v2 0/5] common service startup files Thomas Petazzoni @ 2015-04-21 22:00 ` Yann E. MORIN 2015-04-22 12:44 ` Mike Williams 1 sibling, 0 replies; 13+ messages in thread From: Yann E. MORIN @ 2015-04-21 22:00 UTC (permalink / raw) To: buildroot Alex, Thomas, All, On 2015-04-06 10:51 +0200, Thomas Petazzoni spake thusly: > On Mon, 6 Apr 2015 01:01:19 +0300, Alex Suykov wrote: > > This series is intended to simplify and clean up installation routine > > for daemon-like applications, merging sysv and systemd startup files > > and moving much of the common code out of per-package .mk files. > > Thanks a lot for working on this. > > To be honest, my feeling is that I don't really like Buildroot to > invent its own "abstract" language to describe the initialization of > services, then used to generate SysV and Systemd unit files. Totally agreed on my side. > There are two main reasons for this feeling. > > First of all, because the philosophy of Buildroot is to not invent new > language, or add layers on top of what exists: we use Kconfig for the > configuration, make for the package building logic, shell and Python > scripts in some situations. This is all standard, and generally well > known by most Linux developers. Even though the language you propose > for describing the initialization of services is certainly not very > complicated, it remains a layer on top of what really happens. > > Second, such abstract languages usually appear simple initially. But > then, some corner cases show up, with cases that can easily be solved > in shell scripts or systemd unit files, but were not planned in this > small abstract language. So it has to be extended. Again, and again. To > finally become as complicated as the shell scripts or systemd unit > files. Been there, done that. Indeed. > Of course, my opinion is just one amongst many other Buildroot > developers, and if all other Buildroot developers are convinced that > this is the way to go, then we'll do it. But since not many people > gave their opinion about this, I thought I would simply give mine. Well, it's always difficult to state an opinion on such a series. I have the gut-feeling that it is "not good", but just stating so is not sufficient to coment on it. You've expressed quite nicely my feelings bout this. Thanks! Regards, Yann E. MORIN. -- .-----------------.--------------------.------------------.--------------------. | Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 223 225 172 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. | '------------------------------^-------^------------------^--------------------' ^ permalink raw reply [flat|nested] 13+ messages in thread
* [Buildroot] [RFC v2 0/5] common service startup files 2015-04-06 8:51 ` [Buildroot] [RFC v2 0/5] common service startup files Thomas Petazzoni 2015-04-21 22:00 ` Yann E. MORIN @ 2015-04-22 12:44 ` Mike Williams 1 sibling, 0 replies; 13+ messages in thread From: Mike Williams @ 2015-04-22 12:44 UTC (permalink / raw) To: buildroot > To be honest, my feeling is that I don't really like Buildroot to > invent its own "abstract" language to describe the initialization of > services, then used to generate SysV and Systemd unit files. Seconded, from the currently-using-systemd camp. One of the nice things about systemd is getting to use upstream service files as much as possible, rather than having to maintain our own. ^ permalink raw reply [flat|nested] 13+ messages in thread
* [Buildroot] [RFC v2 0/5] common service startup files 2015-04-05 22:01 [Buildroot] [RFC v2 0/5] common service startup files Alex Suykov ` (6 preceding siblings ...) 2015-04-06 8:51 ` [Buildroot] [RFC v2 0/5] common service startup files Thomas Petazzoni @ 2015-04-22 21:11 ` Thomas Petazzoni 2015-04-22 22:02 ` Alex Suykov 7 siblings, 1 reply; 13+ messages in thread From: Thomas Petazzoni @ 2015-04-22 21:11 UTC (permalink / raw) To: buildroot Dear Alex Suykov, On Mon, 6 Apr 2015 01:01:19 +0300, Alex Suykov wrote: > This series is intended to simplify and clean up installation routine > for daemon-like applications, merging sysv and systemd startup files > and moving much of the common code out of per-package .mk files. > > Currently buildroot requires pre-crafted sysv and/or systemd startup > files to be supplied for each package that needs its daemon-like > processes started at system boot. In many cases, this is redundant. > > Only a small part of the startup scripts is package-specific. > A single command, the one that starts the process in foreground mode, > is typically enough to generate usable sysv and systemd startup files. > > Separating package-specific data and removing the rest from package > directories allows changing common code without the need to patch > several dozen packages, ensures more or less even support for sysv > and systemd, and potentially simplifies introduction of alternative > system startup schemes. > > The first patch in the series contains the common code, and the rest > show how it affects individual packages. I'm only posting a few > interesting ones with comments; the full set (~50 patches) is available > here: https://github.com/arsv/br/ branch run-1. Thanks for this proposal. However, as you have seen, the general feedback was not very positive. We don't really like having a specialized language being created for Buildroot, so the overall approach doesn't really match the "spirit" of how things are done in Buildroot. I've marked the corresponding patches as rejected in our patch tracking system. Thanks for your contribution! Thomas -- Thomas Petazzoni, CTO, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com ^ permalink raw reply [flat|nested] 13+ messages in thread
* [Buildroot] [RFC v2 0/5] common service startup files 2015-04-22 21:11 ` Thomas Petazzoni @ 2015-04-22 22:02 ` Alex Suykov 2015-04-22 22:28 ` Arnout Vandecappelle 0 siblings, 1 reply; 13+ messages in thread From: Alex Suykov @ 2015-04-22 22:02 UTC (permalink / raw) To: buildroot Wed, Apr 22, 2015 at 11:11:43PM +0200, Thomas Petazzoni wrote: > Thanks for this proposal. However, as you have seen, the general > feedback was not very positive. We don't really like having a > specialized language being created for Buildroot, so the overall > approach doesn't really match the "spirit" of how things are done in > Buildroot. > > I've marked the corresponding patches as rejected in our patch tracking > system. Ok, yeah, the initial reaction was pretty clear and I thought it has been marked as rejected for several weeks already. Looks like it wasn't, so people got those patch reminders and started replying. -*-- And a kind of follow-up: I've got a bunch of systemd service files as a by-product of this effort, some of them for packages that have no systemd hooks at present. If you're interested, I could either upload them somewhere for you to pick up, or alternatively start sending patches myself. One package at a time, without any global infrastructure changes. ^ permalink raw reply [flat|nested] 13+ messages in thread
* [Buildroot] [RFC v2 0/5] common service startup files 2015-04-22 22:02 ` Alex Suykov @ 2015-04-22 22:28 ` Arnout Vandecappelle 0 siblings, 0 replies; 13+ messages in thread From: Arnout Vandecappelle @ 2015-04-22 22:28 UTC (permalink / raw) To: buildroot On 04/23/15 00:02, Alex Suykov wrote: > Wed, Apr 22, 2015 at 11:11:43PM +0200, Thomas Petazzoni wrote: > >> Thanks for this proposal. However, as you have seen, the general >> feedback was not very positive. We don't really like having a >> specialized language being created for Buildroot, so the overall >> approach doesn't really match the "spirit" of how things are done in >> Buildroot. >> >> I've marked the corresponding patches as rejected in our patch tracking >> system. > > Ok, yeah, the initial reaction was pretty clear and I thought it has been > marked as rejected for several weeks already. Looks like it wasn't, > so people got those patch reminders and started replying. > > -*-- > > And a kind of follow-up: I've got a bunch of systemd service files > as a by-product of this effort, some of them for packages that > have no systemd hooks at present. > > If you're interested, I could either upload them somewhere > for you to pick up, or alternatively start sending patches myself. > One package at a time, without any global infrastructure changes. That would be great! Regards, Arnout -- Arnout Vandecappelle arnout at mind be Senior Embedded Software Architect +32-16-286500 Essensium/Mind http://www.mind.be G.Geenslaan 9, 3001 Leuven, Belgium BE 872 984 063 RPR Leuven LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle GPG fingerprint: 7CB5 E4CC 6C2E EFD4 6E3D A754 F963 ECAB 2450 2F1F ^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2015-04-22 22:28 UTC | newest] Thread overview: 13+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2015-04-05 22:01 [Buildroot] [RFC v2 0/5] common service startup files Alex Suykov 2015-04-05 22:01 ` [Buildroot] [RFC v2 1/6] " Alex Suykov 2015-04-05 22:02 ` [Buildroot] [RFC v2 2/6] squid: common service startup Alex Suykov 2015-04-05 22:02 ` [Buildroot] [RFC v2 3/6] dropbear: " Alex Suykov 2015-04-05 22:03 ` [Buildroot] [RFC v2 4/6] samba4: " Alex Suykov 2015-04-05 22:04 ` [Buildroot] [RFC v2 5/6] gpsd: " Alex Suykov 2015-04-05 22:04 ` [Buildroot] [RFC v2 6/6] acpid: " Alex Suykov 2015-04-06 8:51 ` [Buildroot] [RFC v2 0/5] common service startup files Thomas Petazzoni 2015-04-21 22:00 ` Yann E. MORIN 2015-04-22 12:44 ` Mike Williams 2015-04-22 21:11 ` Thomas Petazzoni 2015-04-22 22:02 ` Alex Suykov 2015-04-22 22:28 ` Arnout Vandecappelle
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox