Bug#809405: systemd: Backport systemctl is-enabled support for SysV init scripts to Debian Jessie

2017-02-15 Thread Michael Biebl
Control: tags -1 + patch

Am 27.03.2016 um 22:57 schrieb Branko Majic:
> Sorry for the super-late reply on this one. I haven't dug into it any
> further at the moment. I'm afraid I might have wiped-out the patches I
> had in the meantime (it was still a very dirty hack), but will need to
> check it.

Attached is a patch for v215 which adds support for is-enabled for SysV
init scripts. It uses the same heuristics/logic as systemd-sysv-install.

Feedback welcome. I'd appreciate it if you could test the patch.

Michael


-- 
Why is it that all of the instruments seeking intelligent life in the
universe are pointed away from Earth?
From 74a55eee2e4fdc15d4b7857e2f2454dd00730fc0 Mon Sep 17 00:00:00 2001
From: Michael Biebl 
Date: Wed, 15 Feb 2017 10:03:37 +0100
Subject: [PATCH] Support is-enabled for SysV init scripts

As update-rc.d does not provide is-enabled, we implement it ourselves in
systemctl. It uses the same logic as in systemd-sysv-install, see
commit b5aa768d8108b294c1187a0728f5b13c033b3d47

Closes: #809405
---
 src/systemctl/systemctl.c | 38 --
 1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index c67b86d..efce97f 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -4998,9 +4998,8 @@ static int enable_sysv_units(const char *verb, char **args) {
 return 0;
 
 if (!streq(verb, "enable") &&
-!streq(verb, "disable"))
-// update-rc.d currently does not provide is-enabled
-//!streq(verb, "is-enabled"))
+!streq(verb, "disable") &&
+!streq(verb, "is-enabled"))
 return 0;
 
 /* Processes all SysV units, and reshuffles the array so that
@@ -5045,6 +5044,12 @@ static int enable_sysv_units(const char *verb, char **args) {
 break;
 }
 
+/* If we have both a native unit and a SysV script,
+ * enable/disable them both (below); for is-enabled,
+ * prefer the native unit */
+if (found_native && streq(verb, "is-enabled"))
+continue;
+
 if (!isempty(arg_root))
 asprintf(, "%s/" SYSTEM_SYSVINIT_PATH "/%s", arg_root, name);
 else
@@ -5065,6 +5070,21 @@ static int enable_sysv_units(const char *verb, char **args) {
 args[f] = (char*) "";
 }
 
+if (streq(verb, "is-enabled")) {
+_cleanup_free_ char *g = NULL;
+asprintf(, "%s%s", "/etc/rc[S5].d/S??", basename(p));
+if (glob_exists(g)) {
+if (!arg_quiet)
+puts("enabled");
+r = 1;
+continue;
+} else {
+if (!arg_quiet)
+puts("disabled");
+continue;
+}
+}
+
 log_info("Synchronizing state for %s with sysvinit using update-rc.d...", name);
 
 if (!isempty(arg_root) && !streq(arg_root, "/")) {
@@ -5149,17 +5169,7 @@ static int enable_sysv_units(const char *verb, char **args) {
 }
 
 if (status.si_code == CLD_EXITED) {
-if (streq(verb, "is-enabled")) {
-if (status.si_status == 0) {
-if (!arg_quiet)
-puts("enabled");
-r = 1;
-} else {
-if (!arg_quiet)
-puts("disabled");
-}
-
-} else if (status.si_status != 0) {
+if (status.si_status != 0) {
 r = -EINVAL;
 goto finish;
 }
-- 
2.11.0



signature.asc
Description: OpenPGP digital signature


Bug#809405: systemd: Backport systemctl is-enabled support for SysV init scripts to Debian Jessie

2016-03-27 Thread Branko Majic
On Sat, 27 Feb 2016 18:30:16 +0100
Michael Biebl  wrote:

> Am 30.12.2015 um 13:54 schrieb Branko Majic:
> > On Wed, 30 Dec 2015 12:17:13 +0100
> > Michael Biebl  wrote:
> > 
> >> Unfortunately this won't be a simple backport.
> >> The SysV integration wrt update-rc.d has been reworked completely in v220.
> >> If we want to add support for "is-enabled" for v215 this has to be
> >> implemented quite differently.
> > 
> > Hm... Would it be hard to implement a different patch for the v215? Is
> > there any gotchas?
> > 
> > I could try giving it a go perhaps (although my C is somewhat rusty). I
> > think I managed to get something going last time I had a look at it,
> > although it was a bit hack-ish. In such a case, what would be the best
> > way to discuss the proposed patches - issue tracker or there is some
> > sort of mailing list?
> 
> Using this bug report for discussion is fine. Simply attach any patches
> you have.
> Did you investigate any further and make any progress?
> 
> Michael

Sorry for the super-late reply on this one. I haven't dug into it any
further at the moment. I'm afraid I might have wiped-out the patches I
had in the meantime (it was still a very dirty hack), but will need to
check it.

Last thing I recall when checking the systemd sources for Debian
package was that Debian had made somewhat complicated checks around the
init.d scripts (via patches) that kind of extended the logic systemd
had been employing.

Provided I find some more time, I'll start looking into this issue
again (no promises yet).

I am guessing I would be able to obtain useful info here for anything
that might not be clear to me in terms of existing patches (since the
new patch would need to be deployed on top of those)?

I should probably look some more into Debian's instructions on how to
work properly with patches etc.

Best regards

-- 
Branko Majic
Jabber: bra...@majic.rs
Please use only Free formats when sending attachments to me.

Бранко Мајић
Џабер: bra...@majic.rs
Молим вас да додатке шаљете искључиво у слободним форматима.



Bug#809405: systemd: Backport systemctl is-enabled support for SysV init scripts to Debian Jessie

2016-02-27 Thread Michael Biebl
Am 30.12.2015 um 13:54 schrieb Branko Majic:
> On Wed, 30 Dec 2015 12:17:13 +0100
> Michael Biebl  wrote:
> 
>> Unfortunately this won't be a simple backport.
>> The SysV integration wrt update-rc.d has been reworked completely in v220.
>> If we want to add support for "is-enabled" for v215 this has to be
>> implemented quite differently.
> 
> Hm... Would it be hard to implement a different patch for the v215? Is
> there any gotchas?
> 
> I could try giving it a go perhaps (although my C is somewhat rusty). I
> think I managed to get something going last time I had a look at it,
> although it was a bit hack-ish. In such a case, what would be the best
> way to discuss the proposed patches - issue tracker or there is some
> sort of mailing list?

Using this bug report for discussion is fine. Simply attach any patches
you have.
Did you investigate any further and make any progress?

Michael


-- 
Why is it that all of the instruments seeking intelligent life in the
universe are pointed away from Earth?



signature.asc
Description: OpenPGP digital signature


Bug#809405: systemd: Backport systemctl is-enabled support for SysV init scripts to Debian Jessie

2015-12-30 Thread Michael Biebl
Am 30.12.2015 um 11:46 schrieb Branko Majic:
> Package: systemd
> Version: 215-17+deb8u2
> Severity: normal
> 
> Dear Maintainer,
> 
> At the moment in Debian Jessie (stable) it is not possible to use
> systemctl is-enabled command with SysV-style init scripts.
> 
> A large portion of Debian Jessie packages unfortunately still provide
> only the SysV-style init scripts.
> 
> When using certain automation tools, such as Ansible, the systemctl
> is-enabled command is used for validating whether the service has been
> started already or not. Unfortunately, since this does not work,
> automation tools always report the service status as changed. This can
> be an issue when checking for idempotency of implemented automation
> tool.
> 
> This bug has already been reported and resolved (see #760616), but only
> in Debian unstable. It would be highly appreciated if this bug were
> backported to Debian Jessie as well, especially given the relatively
> long release cycles.

Unfortunately this won't be a simple backport.
The SysV integration wrt update-rc.d has been reworked completely in v220.
If we want to add support for "is-enabled" for v215 this has to be
implemented quite differently.



-- 
Why is it that all of the instruments seeking intelligent life in the
universe are pointed away from Earth?




signature.asc
Description: OpenPGP digital signature


Bug#809405: systemd: Backport systemctl is-enabled support for SysV init scripts to Debian Jessie

2015-12-30 Thread Branko Majic
Package: systemd
Version: 215-17+deb8u2
Severity: normal

Dear Maintainer,

At the moment in Debian Jessie (stable) it is not possible to use
systemctl is-enabled command with SysV-style init scripts.

A large portion of Debian Jessie packages unfortunately still provide
only the SysV-style init scripts.

When using certain automation tools, such as Ansible, the systemctl
is-enabled command is used for validating whether the service has been
started already or not. Unfortunately, since this does not work,
automation tools always report the service status as changed. This can
be an issue when checking for idempotency of implemented automation
tool.

This bug has already been reported and resolved (see #760616), but only
in Debian unstable. It would be highly appreciated if this bug were
backported to Debian Jessie as well, especially given the relatively
long release cycles.


-- Package-specific info:

-- System Information:
Debian Release: 8.2
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 3.16.0-4-amd64 (SMP w/1 CPU core)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages systemd depends on:
ii  acl 2.2.52-2
ii  adduser 3.113+nmu3
ii  initscripts 2.88dsf-59
ii  libacl1 2.2.52-2
ii  libaudit1   1:2.4-1+b1
ii  libblkid1   2.25.2-6
ii  libc6   2.19-18+deb8u1
ii  libcap2 1:2.24-8
ii  libcap2-bin 1:2.24-8
ii  libcryptsetup4  2:1.6.6-5
ii  libgcrypt20 1.6.3-2
ii  libkmod218-3
ii  liblzma55.1.1alpha+20120614-2+b3
ii  libpam0g1.1.8-3.1
ii  libselinux1 2.3-2
ii  libsystemd0 215-17+deb8u2
ii  mount   2.25.2-6
ii  sysv-rc 2.88dsf-59
ii  udev215-17+deb8u2
ii  util-linux  2.25.2-6

Versions of packages systemd recommends:
ii  dbus1.8.20-0+deb8u1
pn  libpam-systemd  

Versions of packages systemd suggests:
pn  systemd-ui  

-- no debconf information



Bug#809405: systemd: Backport systemctl is-enabled support for SysV init scripts to Debian Jessie

2015-12-30 Thread Branko Majic
On Wed, 30 Dec 2015 12:17:13 +0100
Michael Biebl  wrote:

> Unfortunately this won't be a simple backport.
> The SysV integration wrt update-rc.d has been reworked completely in v220.
> If we want to add support for "is-enabled" for v215 this has to be
> implemented quite differently.

Hm... Would it be hard to implement a different patch for the v215? Is
there any gotchas?

I could try giving it a go perhaps (although my C is somewhat rusty). I
think I managed to get something going last time I had a look at it,
although it was a bit hack-ish. In such a case, what would be the best
way to discuss the proposed patches - issue tracker or there is some
sort of mailing list?

From what I can tell, the main difficulty comes from certain packages
providing both the init script and systemd service files.

Best regards

-- 
Branko Majic
Jabber: bra...@majic.rs
Please use only Free formats when sending attachments to me.

Бранко Мајић
Џабер: bra...@majic.rs
Молим вас да додатке шаљете искључиво у слободним форматима.