Bug#775795: [Pkg-puppet-devel] Bug#775795: Patch to use /usr/sbin/service in Debian service-provider

2015-03-01 Thread Apollon Oikonomopoulos
On 10:05 Sun 01 Mar , Stig Sandbeck Mathisen wrote:
 Feel free to commit the patch to the packaging repo.

Pushed!


signature.asc
Description: Digital signature


Bug#775795: [Pkg-puppet-devel] Bug#775795: Patch to use /usr/sbin/service in Debian service-provider

2015-03-01 Thread Stig Sandbeck Mathisen
Apollon Oikonomopoulos apoi...@debian.org writes:

 On Fri, 27 Feb 2015 11:20:30 +0200 Apollon Oikonomopoulos 
 apoi...@debian.org wrote:
 The attached patch on top of 3.7.2-2 (hopefully) addresses all of
 these issues (and drops support for pre-2.88 sysv-rc if you don't
 mind). I have not tested it on a sysvinit Jessie system though, so if
 anyone could do this it would be appreciated!

 I also tested it on a sysv-rc Jessie system. This is an updated
 version of the patch, marking the systemctl command as optional.
 Without this, sysv-rc Jessie systems would have the Debian provider
 blacklisted because of the missing systemctl command.

Feel free to commit the patch to the packaging repo.

-- 
Stig Sandbeck Mathisen


signature.asc
Description: PGP signature


Bug#775795: Patch to use /usr/sbin/service in Debian service-provider

2015-02-28 Thread Apollon Oikonomopoulos
On Fri, 27 Feb 2015 11:20:30 +0200 Apollon Oikonomopoulos apoi...@debian.org 
wrote:
 The attached patch on top of 3.7.2-2 (hopefully) addresses all of 
 these issues (and drops support for pre-2.88 sysv-rc if you don't 
 mind). I have not tested it on a sysvinit Jessie system though, so if 
 anyone could do this it would be appreciated!

I also tested it on a sysv-rc Jessie system. This is an updated version 
of the patch, marking the systemctl command as optional. Without this, 
sysv-rc Jessie systems would have the Debian provider blacklisted 
because of the missing systemctl command.

Interdiff:

--- b/lib/puppet/provider/service/debian.rb
+++ b/lib/puppet/provider/service/debian.rb
@@ -15,7 +15,7 @@
   # http://projects.reductivelabs.com/issues/2538
   # is resolved.
   commands :invoke_rc = /usr/sbin/invoke-rc.d
-  commands :systemctl = /bin/systemctl
+  optional_commands :systemctl = /bin/systemctl
 
   # This isn't being used directly, it's just here to ensure
   # that the /usr/sbin/service binary is available.

Cheers,
Apollon
From a9b76dbfba96f537227c445297d3ccd115de46ca Mon Sep 17 00:00:00 2001
From: Apollon Oikonomopoulos apoi...@debian.org
Date: Fri, 27 Feb 2015 10:55:34 +0200
Subject: [PATCH] Fix service listing and enable/disable in Debian
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Add two support methods to detect when we're running systemd as PID 1
and if a service has only an initscript.

Use these to implement the following functionality:

 • Under systemd, use systemctl enable/disable for all services. This
   works correctly for all types of services.

 • Under systemd, use systemctl is-enabled only for services that have a
   systemd unit file and fall back to invoke-rc.d for sysv services.

Also, fix self.instances to augment the list of systemd-enabled services
with the sysv services.

Finally drop pre-2.88 sysv-rc support and use `update-rc.d enable' for
all services when running under sysv-rc, preserving order changes.
---
 lib/puppet/provider/service/debian.rb | 94 ++-
 1 file changed, 71 insertions(+), 23 deletions(-)

diff --git a/lib/puppet/provider/service/debian.rb b/lib/puppet/provider/service/debian.rb
index 9f7a2f5..7a26409 100644
--- a/lib/puppet/provider/service/debian.rb
+++ b/lib/puppet/provider/service/debian.rb
@@ -15,6 +15,7 @@ Puppet::Type.type(:service).provide :debian, :parent = :init do
   # http://projects.reductivelabs.com/issues/2538
   # is resolved.
   commands :invoke_rc = /usr/sbin/invoke-rc.d
+  optional_commands :systemctl = /bin/systemctl
 
   # This isn't being used directly, it's just here to ensure
   # that the /usr/sbin/service binary is available.
@@ -23,38 +24,82 @@ Puppet::Type.type(:service).provide :debian, :parent = :init do
 
   defaultfor :operatingsystem = :debian
 
+  def self.runs_on_systemd?
+Dir.exists? /run/systemd/system
+  end
+
+  def is_sysv_unit?
+# The sysv generator sets the SourcePath attribute to the name of the
+# initscript. Use this to detect whether a unit is backed by an initscript
+# or not.
+source = systemctl(:show, -pSourcePath, @resource[:name])
+source.start_with? SourcePath=/etc/init.d/
+  end
+
+  def self.instances
+# We need to merge services with systemd unit files with those only having
+# an initscript. Note that we could use `systemctl --all` to get sysv
+# services as well, however it would only output *enabled* services.
+i = {}
+if self.runs_on_systemd?
+  begin
+output = systemctl('list-unit-files', '--type', 'service', '--full', '--all',  '--no-pager')
+output.scan(/^(\S+)\.service\s+(disabled|enabled)\s*$/i).each do |m|
+  i[m[0]] = new(:name = m[0])
+end
+  rescue Puppet::ExecutionFailure
+  end
+end
+get_services(defpath).each do |sysv|
+  unless i.has_key?(sysv.name)
+i[sysv.name] = sysv
+  end
+end
+return i.values
+  end
+
   # Remove the symlinks
   def disable
-if `dpkg --compare-versions $(dpkg-query -W --showformat '${Version}' sysv-rc) ge 2.88 ; echo $?`.to_i == 0
-  update_rc @resource[:name], disable
+if self.class.runs_on_systemd?
+  systemctl(:disable, @resource[:name])
 else
-  update_rc -f, @resource[:name], remove
-  update_rc @resource[:name], stop, 00, 1, 2, 3, 4, 5, 6, .
+  update_rc @resource[:name], disable
 end
   end
 
   def enabled?
-# TODO: Replace system call when Puppet::Util::Execution.execute gives us a way
-# to determine exit status.  http://projects.reductivelabs.com/issues/2538
-system(/usr/sbin/invoke-rc.d, --quiet, --query, @resource[:name], start)
-
-# 104 is the exit status when you query start an enabled service.
-# 106 is the exit status when the policy layer supplies a fallback action
-# See x-man-page://invoke-rc.d
-if [104, 106].include?($CHILD_STATUS.exitstatus)
-  return :true
-elsif 

Bug#775795: Patch to use /usr/sbin/service in Debian service-provider

2015-02-27 Thread Apollon Oikonomopoulos
Hi,

On Fri, 06 Feb 2015 15:49:17 +0200 Faidon Liambotis parav...@debian.org wrote:
 This seems like a nice approach for status/start/stop/restart but 
 unfortunately doesn't address enabled?/enable/disable at all. For 
 starters, puppet seems to call update-rc.d with defaults, not 
 enable. Even enable, though, does not seem to be sufficient for 
 systemd-only service files :(
 
 enabled? is similarly broken: it calls invoke-rc.d --query, which 
 returns 105 for test.service and puppet handles 105 by proceeding to 
 check for symlinks under /etc/rc*.d/...
 
 Finally, self.instances is also broken, as it just lists /etc/init.d 
 init files. The systemd provider calls systemctl list-unit-files --type 
 service --full --all instead.
 
 Honestly, I'd just switch the default provider for Debian 8+ to systemd 
 and let users who use a non-default init system handle it in their 
 manifest by supplying provider = debian or provider = upstart.

Unfortunately, switching the default provider to systemd wouldn't work 
either (see below). Besides that, we still have architectures where sysv-rc is
the default.

To put things in perspective, we currently have three types of services:

 A those shipping an initscript only
 B those shipping and initscript and a systemd service file
 C those shipping only a systemd service file and no initscript. This 
   type includes all systemd-specific services, and - inevitably - many 
   services written/managed by sysadmins.

Gaudenz's patch makes sure that start/stop works for all three types of 
services, however it does not change the enable/disable logic nor the 
service listing, which are still problematic:

 - `update-rc.d enable|disable' does not work for type C services, as 
   demonstrated by Faidon.
 - `update-rc.d -f remove  update-rc.d defaults' as currently used in 
   the `enable' does *not* enable type C *and* type B services at all.  
   `update-rc.d enable' would enable type B services but not type C.
 - querying service enable status using invoke-rc.d also doesn't work 
   for type C services.

If OTOH we were to change the default provider to systemd, we wouldn't 
be much better off:

 - `systemctl is-enabled' doesn't work for type A services, which are 
   still the majority:

   $ systemctl is-enabled ferm
   Failed to get unit file state for ferm.service: No such file or directory

 - `systemctl list-unit-files' as used by systemd's self.instances, does 
   not list type A services as well:

   $ systemctl list-unit-files --all --type service --no-pager | grep ferm
   $

So, we actually need a hybrid provider that will do the following:

 - Detect if we're running systemd as PID 1. This is trivial to do by 
   checking for the existence of /run/systemd/system.

 - Keep compatibility with sysv-rc (and I'd suggest to drop pre-2.88 
   support and spare an ugly call to dpkg).

 - If running under systemd:
   • Use `systemctl enable|disable' for *all* services. This works 
 correctly with our current systemd version for all three types of 
 services and invokes update-rc.d if appropriate.

   • Use `systemctl is-enabled` to query for enabled services only for 
 types B and C. Type A services can be detected because their 
 (auto-generated) units have the SourcePath property set to the 
 initscript path:

 $ systemctl show -pSourcePath ferm.service
 SourcePath=/etc/init.d/ferm

 For type A we need to keep the current invoke-rc.d implementation.

   • For self.instances, augment the type B and C services returned by
 `systemctl list-unit-files' with type A services from the init provider's
 self.instances.

The attached patch on top of 3.7.2-2 (hopefully) addresses all of these 
issues (and drops support for pre-2.88 sysv-rc if you don't mind). I 
have not tested it on a sysvinit Jessie system though, so if anyone could do
this it would be appreciated!

Cheers,
Apollon

P.S.: I'm a member of the Puppet maintainers team, but I haven't touched 
  the package (yet :). I could do an upload if anyone else can't.
From ef06e8211bb82ae4f984aaaf3a80947c633d00fd Mon Sep 17 00:00:00 2001
From: Apollon Oikonomopoulos apoi...@debian.org
Date: Fri, 27 Feb 2015 10:55:34 +0200
Subject: [PATCH] Fix service listing and enable/disable in Debian
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Add two support methods to detect when we're running systemd as PID 1
and if a service has only an initscript.

Use these to implement the following functionality:

 • Under systemd, use systemctl enable/disable for all services. This
   works correctly for all types of services.

 • Under systemd, use systemctl is-enabled only for services that have a
   systemd unit file and fall back to invoke-rc.d for sysv services.

Also, fix self.instances to augment the list of systemd-enabled services
with the sysv services.

Finally drop pre-2.88 sysv-rc support and use `update-rc.d enable' for
all services when running 

Bug#775795: Patch to use /usr/sbin/service in Debian service provider

2015-02-07 Thread Cameron Norman
On Fri, 06 Feb 2015 15:49:17 +0200 Faidon Liambotis 
parav...@debian.org wrote:

 reopen 775795
 thanks

 On 02/01/15 01:03, Gaudenz Steinlin wrote:
  I created a patch to use /usr/sbin/service as suggested earlier in 
this

  report to start/stop/status/restart services on Debian. I'm a bit
  reluctant to just NMU puppet and would prefer if one of the 
maintainers
  and/or Faidon could have a look at my patch first. If you approve 
I can

  then do the NMU if you are short on time.
 
  I tested the patch locally and as far as I can see it works fine 
with

  systemd and does call the right command. I don't have a system with
  system V handy to test on.

 Apologies, it seems like I didn't review this on time...

 This seems like a nice approach for status/start/stop/restart but
 unfortunately doesn't address enabled?/enable/disable at all. For
 starters, puppet seems to call update-rc.d with defaults, not
 enable. Even enable, though, does not seem to be sufficient for
 systemd-only service files :(

 Try this:
 # cp /etc/systemd/system/ssh.service  
/etc/systemd/system/test.service

 # systemctl daemon-reload
 # update-rc.d -f test defaults
 update-rc.d: error: initscript does not exist: /etc/init.d/test
 # update-rc.d -f test enable
 update-rc.d: error: cannot find a LSB script for test


While an error is shown, is enable actually enabling the systemd 
service or no?


 enabled? is similarly broken: it calls invoke-rc.d --query, which
 returns 105 for test.service and puppet handles 105 by proceeding to
 check for symlinks under /etc/rc*.d/...

 Finally, self.instances is also broken, as it just lists /etc/init.d
 init files. The systemd provider calls systemctl list-unit-files 
--type

 service --full --all instead.

Are there any packages that only have systemd services?

Cheers,
--
Cameron Norman


Bug#775795: [Pkg-puppet-devel] Bug#775795: Patch to use /usr/sbin/service in Debian service provider

2015-02-05 Thread Stig Sandbeck Mathisen
Gaudenz Steinlin gaud...@debian.org writes:

 Attached is an updated patch that uses a propoer Ruby constant for
 /usr/sbin/service. The first patch was botched by my Pythonistic
 approach to code this.

That looks much better, thanks.

-- 
Stig Sandbeck Mathisen


signature.asc
Description: PGP signature


Bug#775795: [Pkg-puppet-devel] Bug#775795: Patch to use /usr/sbin/service in Debian service provider

2015-02-05 Thread Stig Sandbeck Mathisen
Gaudenz Steinlin gaud...@debian.org writes:

 Attached is an updated patch that uses a propoer Ruby constant for
 /usr/sbin/service. The first patch was botched by my Pythonistic
 approach to code this.

Patch committed. I've tested the packages with autopkgtest as well as
manually. I've uploaded the new packages, and sent an unblock request to
the release team.

Thank you. :)

-- 
Stig Sandbeck Mathisen


signature.asc
Description: PGP signature


Bug#775795: Patch to use /usr/sbin/service in Debian service provider

2015-02-05 Thread Gaudenz Steinlin

Hi

Gaudenz Steinlin gaud...@debian.org writes:

 Stephen Gran sg...@debian.org writes:

 Hi,

 This one time, at band camp, Stig Sandbeck Mathisen said:
 
 Hello,
 
 Thanks for the patch.  It looks like it has the correct solution, using
 the Debian abstraction layer over the alternative init systems.
 
 However, I've found a problem with it using the puppet resource
 command. Could you see if you find what causes it?

 The idea in my patch is to add the service_cmd definition to ensure that
 this provider is only choosen if the service command is available. But
 you can't use this command because of the way the provider works. The
 problem is that startcmd, stopcmd, etc. should return an array with the
 command and it's argument.

 The problem is probably that I replaced the hardcoded /usr/sbin/service
 by a variable after testing the patch and screwed that up somehow. I'm
 right now looking into this and will send a new patch as soon as it's
 fixed.

Attached is an updated patch that uses a propoer Ruby constant for
/usr/sbin/service. The first patch was botched by my Pythonistic
approach to code this.


 If I understand Stephens patch correctly it directly executes the
 service comamnd during the call to XXXcmd. As far as I can see this is
 not the way things should work (looking at provider/service/base.rb).

I did not manage to get this patch to run at all :-(.

Gaudenz
From 089cb15a2ec53831def122a958965e950709b664 Mon Sep 17 00:00:00 2001
From: Gaudenz Steinlin gaud...@debian.org
Date: Thu, 5 Feb 2015 12:14:06 +0100
Subject: [PATCH] Use /usr/sbin/service in Debian service provider

Closes: #775795
---
 .../0004-debian-service-provider-use-service.patch | 56 ++
 debian/patches/series  |  1 +
 2 files changed, 57 insertions(+)
 create mode 100644 debian/patches/0004-debian-service-provider-use-service.patch

diff --git a/debian/patches/0004-debian-service-provider-use-service.patch b/debian/patches/0004-debian-service-provider-use-service.patch
new file mode 100644
index 000..0a81c3e
--- /dev/null
+++ b/debian/patches/0004-debian-service-provider-use-service.patch
@@ -0,0 +1,56 @@
+From: Gaudenz Steinlin gaud...@debian.org
+Subject: Use /usr/sbin/service for service management on Debian
+
+In Debian jessie systemd will be the default init system. But the old system V
+and other alternative init systems are still supported. /usr/sbin/service
+provides an abstraction layer which is able to start, stop and restart
+services independent of the init system used.
+
+Bug: https://tickets.puppetlabs.com/browse/PUP-2023
+Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=775795
+---
+Index: puppet/lib/puppet/provider/service/debian.rb
+===
+--- puppet.orig/lib/puppet/provider/service/debian.rb	2015-02-05 12:07:37.451292892 +0100
 puppet/lib/puppet/provider/service/debian.rb	2015-02-05 12:13:06.500095957 +0100
+@@ -16,6 +16,11 @@
+   # is resolved.
+   commands :invoke_rc = /usr/sbin/invoke-rc.d
+ 
++  # This isn't being used directly, it's just here to ensure
++  # that the /usr/sbin/service binary is available.
++  SERVICE = /usr/sbin/service
++  commands :service_cmd = SERVICE
++
+   defaultfor :operatingsystem = :debian
+ 
+   # Remove the symlinks
+@@ -61,4 +66,28 @@
+ update_rc -f, @resource[:name], remove
+ update_rc @resource[:name], defaults
+   end
++
++  # The start, stop, restart and status command use service
++  # this makes sure that these commands work with whatever init
++  # system is installed
++  def startcmd
++[SERVICE, @resource[:name], :start]
++  end
++
++  # The stop command is just the init script with 'stop'.
++  def stopcmd
++[SERVICE, @resource[:name], :stop]
++  end
++
++  def restartcmd
++(@resource[:hasrestart] == :true)  [SERVICE, @resource[:name], :restart]
++  end
++
++  # If it was specified that the init script has a 'status' command, then
++  # we just return that; otherwise, we return false, which causes it to
++  # fallback to other mechanisms.
++  def statuscmd
++(@resource[:hasstatus] == :true)  [SERVICE, @resource[:name], :status]
++  end
++
+ end
diff --git a/debian/patches/series b/debian/patches/series
index 471a23b..6543a01 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1,3 +1,4 @@
 0001-Do-not-require-rubygems.patch
 0002-Set-passenger-puppet-master-document-root.patch
 0003-fix-puppet-master-logcheck-rule.patch
+0004-debian-service-provider-use-service.patch
-- 
2.1.4



signature.asc
Description: PGP signature


Bug#775795: Patch to use /usr/sbin/service in Debian service provider

2015-02-05 Thread Gaudenz Steinlin
Stephen Gran sg...@debian.org writes:

 Hi,

 This one time, at band camp, Stig Sandbeck Mathisen said:
 
 Hello,
 
 Thanks for the patch.  It looks like it has the correct solution, using
 the Debian abstraction layer over the alternative init systems.
 
 However, I've found a problem with it using the puppet resource
 command. Could you see if you find what causes it?

The idea in my patch is to add the service_cmd definition to ensure that
this provider is only choosen if the service command is available. But
you can't use this command because of the way the provider works. The
problem is that startcmd, stopcmd, etc. should return an array with the
command and it's argument.

The problem is probably that I replaced the hardcoded /usr/sbin/service
by a variable after testing the patch and screwed that up somehow. I'm
right now looking into this and will send a new patch as soon as it's
fixed.

If I understand Stephens patch correctly it directly executes the
service comamnd during the call to XXXcmd. As far as I can see this is
not the way things should work (looking at provider/service/base.rb).

Gaudenz

 
 With puppet 3.7.22-1:
 
 ,
 | root@dagon:~# puppet resource service apache2
 | service { 'apache2':
 |   ensure = 'stopped',
 |   enable = 'true',
 | }
 `
 
 With your patch:
 
 ,
 | root@dagon:~# puppet resource service apache2
 | Error: Could not run: undefined local variable or method `service' for 
 #Puppet::Type::Service::ProviderDebian:0x00029b9d88
 `

 Try this (lightly tested) one instead.  The problem is in the definition
 and use of the service command in the first patch.

 Cheers,
 -- 
  -
 |   ,''`.Stephen Gran |
 |  : :' :sg...@debian.org |
 |  `. `'Debian user, admin, and developer |
 |`- http://www.debian.org |
  -
 From 2eae3a2a71de50889535f0e917ac6f4ecaeb8975 Mon Sep 17 00:00:00 2001
 From: Gaudenz Steinlin gaud...@soziologie.ch
 Date: Sat, 31 Jan 2015 16:09:08 +0100
 Subject: [PATCH] Use /usr/sbin/service in Debian service provider

 Closes: #775795
 ---
  .../0004-debian-service-provider-use-service.patch | 56 
 ++
  debian/patches/series  |  1 +
  2 files changed, 57 insertions(+)
  create mode 100644 
 debian/patches/0004-debian-service-provider-use-service.patch

 diff --git a/debian/patches/0004-debian-service-provider-use-service.patch 
 b/debian/patches/0004-debian-service-provider-use-service.patch
 new file mode 100644
 index 000..29a4277
 --- /dev/null
 +++ b/debian/patches/0004-debian-service-provider-use-service.patch
 @@ -0,0 +1,56 @@
 +From: Gaudenz Steinlin gaud...@debian.org
 +Subject: Use /usr/sbin/service for service management on Debian
 +
 +In Debian jessie systemd will be the default init system. But the old system 
 V
 +and other alternative init systems are still supported. /usr/sbin/service
 +provides an abstraction layer which is able to start, stop and restart
 +services independent of the init system used.
 +
 +Bug: https://tickets.puppetlabs.com/browse/PUP-2023
 +Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=775795
 +---
 +Index: puppet/lib/puppet/provider/service/debian.rb
 +===
 +--- puppet.orig/lib/puppet/provider/service/debian.rb2015-01-31 
 17:30:09.0 +0100
  puppet/lib/puppet/provider/service/debian.rb 2015-01-31 
 23:05:10.477108925 +0100
 +@@ -16,6 +16,11 @@
 +   # is resolved.
 +-   commands :invoke_rc = /usr/sbin/invoke-rc.d
 ++   commands :invoke_rc = /usr/sbin/invoke-rc.d, :service = service
 + 
 +   defaultfor :operatingsystem = :debian
 + 
 +   # Remove the symlinks
 +@@ -61,4 +66,28 @@
 + update_rc -f, @resource[:name], remove
 + update_rc @resource[:name], defaults
 +   end
 ++
 ++  # The start, stop, restart and status command use service
 ++  # this makes sure that these commands work with whatever init
 ++  # system is installed
 ++  def startcmd
 ++service @resource[:name], start
 ++  end
 ++
 ++  # The stop command is just the init script with 'stop'.
 ++  def stopcmd
 ++service @resource[:name], stop
 ++  end
 ++
 ++  def restartcmd
 ++(@resource[:hasrestart] == :true)  service @resource[:name], restart
 ++  end
 ++
 ++  # If it was specified that the init script has a 'status' command, then
 ++  # we just return that; otherwise, we return false, which causes it to
 ++  # fallback to other mechanisms.
 ++  def statuscmd
 ++(@resource[:hasstatus] == :true)  service @resource[:name], status
 ++  end
 ++
 + end
 diff --git a/debian/patches/series b/debian/patches/series
 index 471a23b..6543a01 100644
 --- a/debian/patches/series
 +++ b/debian/patches/series
 @@ -1,3 

Bug#775795: Patch to use /usr/sbin/service in Debian service provider

2015-02-05 Thread Stephen Gran
Hi,

This one time, at band camp, Stig Sandbeck Mathisen said:
 
 Hello,
 
 Thanks for the patch.  It looks like it has the correct solution, using
 the Debian abstraction layer over the alternative init systems.
 
 However, I've found a problem with it using the puppet resource
 command. Could you see if you find what causes it?
 
 With puppet 3.7.22-1:
 
 ,
 | root@dagon:~# puppet resource service apache2
 | service { 'apache2':
 |   ensure = 'stopped',
 |   enable = 'true',
 | }
 `
 
 With your patch:
 
 ,
 | root@dagon:~# puppet resource service apache2
 | Error: Could not run: undefined local variable or method `service' for 
 #Puppet::Type::Service::ProviderDebian:0x00029b9d88
 `

Try this (lightly tested) one instead.  The problem is in the definition
and use of the service command in the first patch.

Cheers,
-- 
 -
|   ,''`.Stephen Gran |
|  : :' :sg...@debian.org |
|  `. `'Debian user, admin, and developer |
|`- http://www.debian.org |
 -
From 2eae3a2a71de50889535f0e917ac6f4ecaeb8975 Mon Sep 17 00:00:00 2001
From: Gaudenz Steinlin gaud...@soziologie.ch
Date: Sat, 31 Jan 2015 16:09:08 +0100
Subject: [PATCH] Use /usr/sbin/service in Debian service provider

Closes: #775795
---
 .../0004-debian-service-provider-use-service.patch | 56 ++
 debian/patches/series  |  1 +
 2 files changed, 57 insertions(+)
 create mode 100644 debian/patches/0004-debian-service-provider-use-service.patch

diff --git a/debian/patches/0004-debian-service-provider-use-service.patch b/debian/patches/0004-debian-service-provider-use-service.patch
new file mode 100644
index 000..29a4277
--- /dev/null
+++ b/debian/patches/0004-debian-service-provider-use-service.patch
@@ -0,0 +1,56 @@
+From: Gaudenz Steinlin gaud...@debian.org
+Subject: Use /usr/sbin/service for service management on Debian
+
+In Debian jessie systemd will be the default init system. But the old system V
+and other alternative init systems are still supported. /usr/sbin/service
+provides an abstraction layer which is able to start, stop and restart
+services independent of the init system used.
+
+Bug: https://tickets.puppetlabs.com/browse/PUP-2023
+Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=775795
+---
+Index: puppet/lib/puppet/provider/service/debian.rb
+===
+--- puppet.orig/lib/puppet/provider/service/debian.rb	2015-01-31 17:30:09.0 +0100
 puppet/lib/puppet/provider/service/debian.rb	2015-01-31 23:05:10.477108925 +0100
+@@ -16,6 +16,11 @@
+   # is resolved.
+-   commands :invoke_rc = /usr/sbin/invoke-rc.d
++   commands :invoke_rc = /usr/sbin/invoke-rc.d, :service = service
+ 
+   defaultfor :operatingsystem = :debian
+ 
+   # Remove the symlinks
+@@ -61,4 +66,28 @@
+ update_rc -f, @resource[:name], remove
+ update_rc @resource[:name], defaults
+   end
++
++  # The start, stop, restart and status command use service
++  # this makes sure that these commands work with whatever init
++  # system is installed
++  def startcmd
++service @resource[:name], start
++  end
++
++  # The stop command is just the init script with 'stop'.
++  def stopcmd
++service @resource[:name], stop
++  end
++
++  def restartcmd
++(@resource[:hasrestart] == :true)  service @resource[:name], restart
++  end
++
++  # If it was specified that the init script has a 'status' command, then
++  # we just return that; otherwise, we return false, which causes it to
++  # fallback to other mechanisms.
++  def statuscmd
++(@resource[:hasstatus] == :true)  service @resource[:name], status
++  end
++
+ end
diff --git a/debian/patches/series b/debian/patches/series
index 471a23b..6543a01 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1,3 +1,4 @@
 0001-Do-not-require-rubygems.patch
 0002-Set-passenger-puppet-master-document-root.patch
 0003-fix-puppet-master-logcheck-rule.patch
+0004-debian-service-provider-use-service.patch
-- 
2.1.4



Bug#775795: Patch to use /usr/sbin/service in Debian service provider

2015-02-04 Thread Stig Sandbeck Mathisen

Hello,

Thanks for the patch.  It looks like it has the correct solution, using
the Debian abstraction layer over the alternative init systems.

However, I've found a problem with it using the puppet resource
command. Could you see if you find what causes it?

With puppet 3.7.22-1:

,
| root@dagon:~# puppet resource service apache2
| service { 'apache2':
|   ensure = 'stopped',
|   enable = 'true',
| }
`

With your patch:

,
| root@dagon:~# puppet resource service apache2
| Error: Could not run: undefined local variable or method `service' for 
#Puppet::Type::Service::ProviderDebian:0x00029b9d88
`

-- 
Stig Sandbeck Mathisen


-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org