Blame SOURCES/bz1348579-02-fix-traceback-when-stopping-pcsd-shortly-after-start.patch

15f218
From 760028cca19c07dd56162453a4eb3d3b0de7f3af Mon Sep 17 00:00:00 2001
15f218
From: Tomas Jelinek <tojeline@redhat.com>
15f218
Date: Tue, 19 Jul 2016 13:11:04 +0200
15f218
Subject: [PATCH] fix traceback when stopping pcsd shortly after start
15f218
15f218
- properly notify systemd that pcsd finished starting up
15f218
- gracefully exit on SIGINT and SIGTERM
15f218
---
15f218
 pcsd/pcsd.service        |  1 +
15f218
 pcsd/pcsd.service-runner | 25 ++++++++++++++++++-------
15f218
 pcsd/ssl.rb              | 18 ++++++++++++++++++
15f218
 3 files changed, 37 insertions(+), 7 deletions(-)
15f218
15f218
diff --git a/pcsd/pcsd.service b/pcsd/pcsd.service
15f218
index e506f1b..20bc9ab 100644
15f218
--- a/pcsd/pcsd.service
15f218
+++ b/pcsd/pcsd.service
15f218
@@ -5,6 +5,7 @@ Description=PCS GUI and remote configuration interface
15f218
 EnvironmentFile=/etc/sysconfig/pcsd
15f218
 Environment=GEM_HOME=/usr/lib/pcsd/vendor/bundle/ruby
15f218
 ExecStart=/usr/lib/pcsd/pcsd > /dev/null &
15f218
+Type=notify
15f218
 
15f218
 [Install]
15f218
 WantedBy=multi-user.target
15f218
diff --git a/pcsd/pcsd.service-runner b/pcsd/pcsd.service-runner
15f218
index 1949a68..883d290 100644
15f218
--- a/pcsd/pcsd.service-runner
15f218
+++ b/pcsd/pcsd.service-runner
15f218
@@ -2,12 +2,23 @@
15f218
 # this file is a pcsd runner callable from a systemd unit
15f218
 # it also serves as a holder of a selinux context
15f218
 
15f218
-# add pcsd to the load path (ruby -I)
15f218
-libdir = File.dirname(__FILE__)
15f218
-$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
15f218
+begin
15f218
+  # add pcsd to the load path (ruby -I)
15f218
+  libdir = File.dirname(__FILE__)
15f218
+  $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
15f218
 
15f218
-# change current directory (ruby -C)
15f218
-Dir.chdir('/var/lib/pcsd')
15f218
+  # change current directory (ruby -C)
15f218
+  Dir.chdir('/var/lib/pcsd')
15f218
 
15f218
-# import and run pcsd
15f218
-require 'ssl'
15f218
+  # import and run pcsd
15f218
+  require 'ssl'
15f218
+rescue SignalException => e
15f218
+  if [Signal.list['INT'], Signal.list['TERM']].include?(e.signo)
15f218
+    # gracefully exit on SIGINT and SIGTERM
15f218
+    # pcsd sets up signal handlers later, this catches exceptions which occur
15f218
+    # by recieving signals before the handlers have been set up.
15f218
+    exit
15f218
+  else
15f218
+    raise
15f218
+  end
15f218
+end
15f218
diff --git a/pcsd/ssl.rb b/pcsd/ssl.rb
15f218
index f56c947..c00d8b3 100644
15f218
--- a/pcsd/ssl.rb
15f218
+++ b/pcsd/ssl.rb
15f218
@@ -3,6 +3,7 @@ require 'webrick'
15f218
 require 'webrick/https'
15f218
 require 'openssl'
15f218
 require 'rack'
15f218
+require 'socket'
15f218
 
15f218
 require 'bootstrap.rb'
15f218
 require 'pcs.rb'
15f218
@@ -66,11 +67,28 @@ def run_server(server, webrick_options, secondary_addrs)
15f218
 
15f218
   $logger.info("Listening on #{primary_addr} port #{port}")
15f218
   server.run(Sinatra::Application, webrick_options) { |server_instance|
15f218
+    # configure ssl options
15f218
     server_instance.ssl_context.ciphers = ciphers
15f218
+    # set listening addresses
15f218
     secondary_addrs.each { |addr|
15f218
       $logger.info("Adding listener on #{addr} port #{port}")
15f218
       server_instance.listen(addr, port)
15f218
     }
15f218
+    # notify systemd we are running
15f218
+    if ISSYSTEMCTL
15f218
+      socket_name = ENV['NOTIFY_SOCKET']
15f218
+      if socket_name
15f218
+        if socket_name.start_with?('@')
15f218
+          # abstract namespace socket
15f218
+          socket_name[0] = "\0"
15f218
+        end
15f218
+        $logger.info("Notifying systemd we are running (socket #{socket_name})")
15f218
+        sd_socket = Socket.new(Socket::AF_UNIX, Socket::SOCK_DGRAM)
15f218
+        sd_socket.connect(Socket.pack_sockaddr_un(socket_name))
15f218
+        sd_socket.send('READY=1', 0)
15f218
+        sd_socket.close()
15f218
+      end
15f218
+    end
15f218
   }
15f218
 end
15f218
 
15f218
-- 
15f218
1.8.3.1
15f218