nexpose_pxgrid 0.1.2-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.travis.yml +4 -0
  4. data/Gemfile +4 -0
  5. data/LICENCE.APACHE +144 -0
  6. data/LICENSE.MIT +21 -0
  7. data/README.md +49 -0
  8. data/RadiusSimulator.jar +0 -0
  9. data/Rakefile +31 -0
  10. data/bin/logback.xml +17 -0
  11. data/bin/pxnx.rb +34 -0
  12. data/bin/pxnx_daemon.rb +105 -0
  13. data/keystore.jks +0 -0
  14. data/lib/java_libs/FastInfoset-1.2.12.jar +0 -0
  15. data/lib/java_libs/commons-cli-20040117.000000.jar +0 -0
  16. data/lib/java_libs/commons-codec-1.7.jar +0 -0
  17. data/lib/java_libs/commons-io-2.4.jar +0 -0
  18. data/lib/java_libs/commons-lang-2.6.jar +0 -0
  19. data/lib/java_libs/cxf-api-2.7.3.jar +0 -0
  20. data/lib/java_libs/cxf-rt-bindings-xml-2.7.3.jar +0 -0
  21. data/lib/java_libs/cxf-rt-core-2.7.3.jar +0 -0
  22. data/lib/java_libs/cxf-rt-frontend-jaxrs-2.7.3.jar +0 -0
  23. data/lib/java_libs/cxf-rt-transports-http-2.7.3.jar +0 -0
  24. data/lib/java_libs/geronimo-javamail_1.4_spec-1.7.1.jar +0 -0
  25. data/lib/java_libs/istack-commons-runtime-2.14.jar +0 -0
  26. data/lib/java_libs/javax.ws.rs-api-2.0-m10.jar +0 -0
  27. data/lib/java_libs/jaxb-api-2.2.7.jar +0 -0
  28. data/lib/java_libs/jaxb-core-2.2.7-b57.jar +0 -0
  29. data/lib/java_libs/jaxb-impl-2.2.7-b57.jar +0 -0
  30. data/lib/java_libs/log4j-1.2.17.jar +0 -0
  31. data/lib/java_libs/log4j-rolling-appender-20131024-2017.jar +0 -0
  32. data/lib/java_libs/logback-classic-1.1.2.jar +0 -0
  33. data/lib/java_libs/logback-core-1.1.2.jar +0 -0
  34. data/lib/java_libs/pxgrid-core-model-1.0.0.10.jar +0 -0
  35. data/lib/java_libs/pxgrid-eps-client-stub-1.0.0.10.jar +0 -0
  36. data/lib/java_libs/pxgrid-eps-model-1.0.0.10.jar +0 -0
  37. data/lib/java_libs/pxgrid-gc-admin-model-1.0.0.10.jar +0 -0
  38. data/lib/java_libs/pxgrid-gcl-1.0.0.10.jar +0 -0
  39. data/lib/java_libs/pxgrid-identity-client-stub-1.0.0.10.jar +0 -0
  40. data/lib/java_libs/pxgrid-identity-model-1.0.0.10.jar +0 -0
  41. data/lib/java_libs/pxgrid-ise-model-1.0.0.10.jar +0 -0
  42. data/lib/java_libs/pxgrid-isemetadata-client-stub-1.0.0.10.jar +0 -0
  43. data/lib/java_libs/pxgrid-isemetadata-model-1.0.0.10.jar +0 -0
  44. data/lib/java_libs/pxgrid-net-model-1.0.0.10.jar +0 -0
  45. data/lib/java_libs/pxgrid-netcapture-model-1.0.0.10.jar +0 -0
  46. data/lib/java_libs/pxgrid-tdanalysis-model-1.0.0.10.jar +0 -0
  47. data/lib/java_libs/slf4j-api-1.7.2.jar +0 -0
  48. data/lib/java_libs/smack-3.2.1.jar +0 -0
  49. data/lib/java_libs/smackx-3.2.1.jar +0 -0
  50. data/lib/java_libs/stax-api-1.0-2.jar +0 -0
  51. data/lib/java_libs/stax2-api-3.1.1.jar +0 -0
  52. data/lib/java_libs/woodstox-core-asl-4.1.4.jar +0 -0
  53. data/lib/java_libs/wsdl4j-1.6.2.jar +0 -0
  54. data/lib/java_libs/xmlschema-core-2.0.3.jar +0 -0
  55. data/lib/pxnx_jruby.rb +70 -0
  56. data/lib/pxnx_jruby/config/pxnx.config +40 -0
  57. data/lib/pxnx_jruby/connection.rb +84 -0
  58. data/lib/pxnx_jruby/connection_manager.rb +44 -0
  59. data/lib/pxnx_jruby/eps_broker.rb +49 -0
  60. data/lib/pxnx_jruby/nexpose_connection.rb +62 -0
  61. data/lib/pxnx_jruby/nx_logger.rb +166 -0
  62. data/lib/pxnx_jruby/session_directory_notification.rb +26 -0
  63. data/lib/pxnx_jruby/spoon/README +7 -0
  64. data/lib/pxnx_jruby/spoon/pxnx_daemon_unix.rb +181 -0
  65. data/lib/pxnx_jruby/spoon/pxnx_daemon_windows.rb +50 -0
  66. data/lib/pxnx_jruby/spoon/pxnx_runner.rb +7 -0
  67. data/lib/pxnx_jruby/version.rb +5 -0
  68. data/pxnx.gemspec +28 -0
  69. data/releases/pxnx-0.1.0-java.gem +0 -0
  70. data/truststore.jks +0 -0
  71. metadata +220 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ecba8523665d3a8a4c2f56417082f8a44c6a9ff8
4
+ data.tar.gz: 38d4c4353f6a41bd9dbd6ee0cabe6567a0e37ced
5
+ SHA512:
6
+ metadata.gz: 72ea383d0d355b2504ff804c4d9cef347c817109b4e2f7a508b3e803f5c938a2485af36593a0f0e0c2da0f8baca90d98a46a1d8faf24e1285131b7516eb0bc70
7
+ data.tar.gz: 37a8bba9738599e3cfc91d6fc1a7047e182b19251088a6e3bbd7ea9cd0062eb3bf92e671f0f4183c6ba34e662fb7ec774f152910715126b5e8ac14cdb3e537e5
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .idea/*
11
+ *DS_Store*
12
+ *.log
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ before_install: gem install bundler -v 1.10.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pxnx.gemspec
4
+ gemspec
data/LICENCE.APACHE ADDED
@@ -0,0 +1,144 @@
1
+ Apache License
2
+
3
+ Version 2.0, January 2004
4
+
5
+ http://www.apache.org/licenses/
6
+
7
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ 1. Definitions.
10
+
11
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as
12
+ defined by Sections 1 through 9 of this document.
13
+
14
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that
15
+ is granting the License.
16
+
17
+ "Legal Entity" shall mean the union of the acting entity and all other entities that
18
+ control, are controlled by, or are under common control with that entity. For the purposes
19
+ of this definition, "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or otherwise, or (ii) ownership
21
+ of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of
22
+ such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by
25
+ this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications, including but not
28
+ limited to software source code, documentation source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical transformation or translation of
31
+ a Source form, including but not limited to compiled object code, generated documentation,
32
+ and conversions to other media types.
33
+
34
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available
35
+ under the License, as indicated by a copyright notice that is included in or attached to the
36
+ work (an example is provided in the Appendix below).
37
+
38
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on
39
+ (or derived from) the Work and for which the editorial revisions, annotations, elaborations,
40
+ or other modifications represent, as a whole, an original work of authorship. For the
41
+ purposes of this License, Derivative Works shall not include works that remain separable
42
+ from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works
43
+ thereof.
44
+
45
+ "Contribution" shall mean any work of authorship, including the original version of the Work
46
+ and any modifications or additions to that Work or Derivative Works thereof, that is
47
+ intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by
48
+ an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the
49
+ purposes of this definition, "submitted" means any form of electronic, verbal, or written
50
+ communication sent to the Licensor or its representatives, including but not limited to
51
+ communication on electronic mailing lists, source code control systems, and issue tracking
52
+ systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and
53
+ improving the Work, but excluding communication that is conspicuously marked or otherwise
54
+ designated in writing by the copyright owner as "Not a Contribution."
55
+
56
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a
57
+ Contribution has been received by Licensor and subsequently incorporated within the Work.
58
+
59
+ 2. Grant of Copyright License. Subject to the terms and conditions of this License, each
60
+ Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge,
61
+ royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of,
62
+ publicly display, publicly perform, sublicense, and distribute the Work and such Derivative
63
+ Works in Source or Object form.
64
+
65
+ 3. Grant of Patent License. Subject to the terms and conditions of this License, each
66
+ Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge,
67
+ royalty-free, irrevocable (except as stated in this section) patent license to make, have
68
+ made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license
69
+ applies only to those patent claims licensable by such Contributor that are necessarily
70
+ infringed by their Contribution(s) alone or by combination of their Contribution(s) with the
71
+ Work to which such Contribution(s) was submitted. If You institute patent litigation against
72
+ any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or
73
+ a Contribution incorporated within the Work constitutes direct or contributory patent
74
+ infringement, then any patent licenses granted to You under this License for that Work shall
75
+ terminate as of the date such litigation is filed.
76
+
77
+ 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works
78
+ thereof in any medium, with or without modifications, and in Source or Object form, provided
79
+ that You meet the following conditions:
80
+
81
+ You must give any other recipients of the Work or Derivative Works a copy of this License;
82
+ and
83
+
84
+ You must cause any modified files to carry prominent notices stating that You changed the
85
+ files; and
86
+
87
+ You must retain, in the Source form of any Derivative Works that You distribute, all
88
+ copyright, patent, trademark, and attribution notices from the Source form of the Work,
89
+ excluding those notices that do not pertain to any part of the Derivative Works; and
90
+
91
+ If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative
92
+ Works that You distribute must include a readable copy of the attribution notices contained
93
+ within such NOTICE file, excluding those notices that do not pertain to any part of the
94
+ Derivative Works, in at least one of the following places: within a NOTICE text file
95
+ distributed as part of the Derivative Works; within the Source form or documentation, if
96
+ provided along with the Derivative Works; or, within a display generated by the Derivative
97
+ Works, if and wherever such third-party notices normally appear. The contents of the NOTICE
98
+ file are for informational purposes only and do not modify the License. You may add Your own
99
+ attribution notices within Derivative Works that You distribute, alongside or as an addendum
100
+ to the NOTICE text from the Work, provided that such additional attribution notices cannot
101
+ be construed as modifying the License. You may add Your own copyright statement to Your
102
+ modifications and may provide additional or different license terms and conditions for use,
103
+ reproduction, or distribution of Your modifications, or for any such Derivative Works as a
104
+ whole, provided Your use, reproduction, and distribution of the Work otherwise complies with
105
+ the conditions stated in this License.
106
+
107
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution
108
+ intentionally submitted for inclusion in the Work by You to the Licensor shall be under the
109
+ terms and conditions of this License, without any additional terms or conditions.
110
+ Notwithstanding the above, nothing herein shall supersede or modify the terms of any
111
+ separate license agreement you may have executed with Licensor regarding such Contributions.
112
+
113
+ 6. Trademarks. This License does not grant permission to use the trade names, trademarks,
114
+ service marks, or product names of the Licensor, except as required for reasonable and
115
+ customary use in describing the origin of the Work and reproducing the content of the NOTICE
116
+ file.
117
+
118
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing,
119
+ Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS"
120
+ BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including,
121
+ without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT,
122
+ MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for
123
+ determining the appropriateness of using or redistributing the Work and assume any risks
124
+ associated with Your exercise of permissions under this License.
125
+
126
+ 8. Limitation of Liability. In no event and under no legal theory, whether in tort
127
+ (including negligence), contract, or otherwise, unless required by applicable law (such as
128
+ deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be
129
+ liable to You for damages, including any direct, indirect, special, incidental, or
130
+ consequential damages of any character arising as a result of this License or out of the use
131
+ or inability to use the Work (including but not limited to damages for loss of goodwill,
132
+ work stoppage, computer failure or malfunction, or any and all other commercial damages or
133
+ losses), even if such Contributor has been advised of the possibility of such damages.
134
+
135
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative
136
+ Works thereof, You may choose to offer, and charge a fee for, acceptance of support,
137
+ warranty, indemnity, or other liability obligations and/or rights consistent with this
138
+ License. However, in accepting such obligations, You may act only on Your own behalf and on
139
+ Your sole responsibility, not on behalf of any other Contributor, and only if You agree to
140
+ indemnify, defend, and hold each Contributor harmless for any liability incurred by, or
141
+ claims asserted against, such Contributor by reason of your accepting any such warranty or
142
+ additional liability.
143
+
144
+ END OF TERMS AND CONDITIONS
data/LICENSE.MIT ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Damian Finol
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # PxnxJruby
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/pxnx_jruby`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'pxnx_jruby'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install pxnx_jruby
22
+
23
+ ## From Cisco Docs
24
+ If the client is connecting to the pxGrid Controller for the first time, an account is established on the pxGrid Controller.
25
+ In pxGrid’s auto-registration mode (set by administrator through the ISE web-based user interface),
26
+ the client is allowed to communicate once the account is created.
27
+ Whereas if auto registration mode is turned off, the node and authorization group assignment of the
28
+ node remains in Pending Approval mode and not allowed to communicate over pxGrid until it is approved by the administrator.
29
+ Also, the user must be part of the EPS group.
30
+
31
+ ## Usage
32
+
33
+ TODO: Write usage instructions here
34
+
35
+ ## Development
36
+
37
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
38
+
39
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
40
+
41
+ ## Contributing
42
+
43
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/pxnx_jruby.
44
+
45
+
46
+ ## License
47
+
48
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
49
+
Binary file
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ #require "bundler/gem_tasks"
2
+ require 'rake'
3
+ require 'ipaddr'
4
+ require 'bundler'
5
+ require 'pxnx_jruby'
6
+
7
+ namespace :pxnx do
8
+ task :default => :simulate
9
+ # TODO. (!) Read the parameters from arg/config/env/etc.
10
+ desc 'Authenticate and connect through Radius'
11
+ task :simulate, [:ip] => [:authenticate, :connect] do |t, args|
12
+ puts 'Sent Radius packets. Check log file.'
13
+ end
14
+
15
+ desc 'Authenticate to Radius'
16
+ task :authenticate, :ip do |t, args|
17
+ args.with_defaults(ip: PxnxJruby.random_ip)
18
+ @ip = args[:ip]
19
+ sh "java -cp #{File.expand_path File.dirname(__FILE__)}/RadiusSimulator.jar -DUSERNAME=dfinol -DPASSWORD=Nexpose4lyfe -DCALLING_STATION_ID=11:22:33:44:55:66 -DAUDIT_SESSION_ID=1001 -DFRAMED_IP_ADDRESS=#{@ip} -DRADIUS_SECRET=nxadmin -DFRAMED_IP_MASK=255.255.255.255 RadiusAuthentication 10.4.91.100"
20
+ end
21
+
22
+ desc 'Start accounting'
23
+ task :connect, :ip do |t, args|
24
+ sh "java -cp #{File.expand_path File.dirname(__FILE__)}/RadiusSimulator.jar -DUSERNAME=dfinol -DPASSWORD=Nexpose4lyfe -DCALLING_STATION_ID=11:22:33:44:55:66 -DAUDIT_SESSION_ID=1001 -DFRAMED_IP_ADDRESS=#{@ip} -DRADIUS_SECRET=nxadmin -DFRAMED_IP_MASK=255.255.255.255 RadiusAccountingStart 10.4.91.100"
25
+ end
26
+
27
+ desc 'Stop accounting'
28
+ task :stop, :ip do |t, args|
29
+ sh "java -cp #{File.expand_path File.dirname(__FILE__)}/RadiusSimulator.jar -DUSERNAME=dfinol -DPASSWORD=Nexpose4lyfe -DCALLING_STATION_ID=11:22:33:44:55:66 -DAUDIT_SESSION_ID=1001 -DFRAMED_IP_ADDRESS=#{@ip} -DRADIUS_SECRET=nxadmin -DFRAMED_IP_MASK=255.255.255.255 RadiusAccountingStop 10.4.91.100"
30
+ end
31
+ end
data/bin/logback.xml ADDED
@@ -0,0 +1,17 @@
1
+ <configuration debug="false" scan="false">
2
+ <appender name="TIME_BASED_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
3
+ <File>../lib/logs/rapid7_cisco.log</File>
4
+ <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
5
+ <!-- Rotates every week -->
6
+ <fileNamePattern>../lib/logs/rapid7_cisco.%d{yyyy/ww}.log</fileNamePattern>
7
+ <maxHistory>4</maxHistory>
8
+ </rollingPolicy>
9
+ <encoder>
10
+ <pattern>%date{ISO8601} [%thread] %-5level %logger{34} - %msg%n</pattern>
11
+ </encoder>
12
+ </appender>
13
+
14
+ <root level="DEBUG">
15
+ <appender-ref ref="TIME_BASED_FILE" />
16
+ </root>
17
+ </configuration>
data/bin/pxnx.rb ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pxnx_jruby'
3
+ require 'yaml'
4
+ require 'pxnx_jruby/nx_logger'
5
+ require 'pxnx_jruby/version'
6
+
7
+ begin
8
+ # Path to the pxnx Configuration file.
9
+ PXNX_CONFIG_PATH = File.join(File.dirname(__FILE__),
10
+ '../lib/pxnx_jruby/config/pxnx.config')
11
+ # Read in pxnx options from pxnx.config.
12
+ pxnx_options = begin
13
+ YAML.load_file(PXNX_CONFIG_PATH)
14
+ rescue ArgumentError => e
15
+ raise "Could not parse YAML #{PXNX_CONFIG_PATH} : #{e.message}"
16
+ end
17
+
18
+ log = PxnxJruby::NxLogger.instance
19
+ log.setup_statistics_collection(PxnxJruby::VENDOR, PxnxJruby::PRODUCT, PxnxJruby::VERSION)
20
+ log.setup_logging(pxnx_options[:logging_enabled],
21
+ pxnx_options[:log_level] || 'info')
22
+
23
+ connection = PxnxJruby.create_connection(pxnx_options)
24
+ handler = PxnxJruby::SessionDirectoryNotification.new
25
+ connection.connect
26
+ sleep(5)
27
+ pxnx_options[:grid_connection] = connection
28
+ PxnxJruby::ConnectionManager.instance.setup(pxnx_options)
29
+ # Subscribes to SessionDirectoryNotification!
30
+ Java::com.cisco.pxgrid.stub.identity.SessionDirectoryFactory.registerNotification(connection.grid, handler)
31
+ # TODO: Exception handling.
32
+ rescue java.lang.IllegalStateException => e
33
+ puts("Error when executing pxnx! The error was <#{e.message}> and backtrace was <#{e.backtrace.join("\n")}>.")
34
+ end
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env ruby
2
+ require '../lib/pxnx_jruby/spoon/pxnx_runner'
3
+ require 'timeout'
4
+
5
+ def setup()
6
+ @pid_dir = File.join(File.dirname(__FILE__), '.')
7
+ @name = "pxnx_daemon_process"
8
+ @pid_path = File.join(@pid_dir, "#{@name}.pid")
9
+ @pid = get_pid_from_file()
10
+ @timeout = 120
11
+ end
12
+
13
+ def create_pid_file(pid)
14
+ begin
15
+ open(@pid_path, 'w') do |f|
16
+ f.puts pid
17
+ end
18
+ rescue => e
19
+ STDERR.puts "Error: Unable to open #{@pid_path} for writing:\n\t <#{e.message}>"
20
+ exit
21
+ end
22
+ end
23
+
24
+ def get_pid_from_file
25
+ @pid = nil
26
+ open(@pid_path, 'r') do |f|
27
+ @pid = f.readline.to_s.gsub(/[^0-9]/,'')
28
+ end
29
+ rescue Errno::ENOENT => e
30
+ #File does not exist. Leave PID at nil.
31
+ @pid.to_i unless @pid.nil?
32
+ end
33
+
34
+ def remove_pid_file
35
+ File.unlink(@pid_path)
36
+ rescue => e
37
+ STDERR.puts "ERROR: Unable to unlink #{@pid_path}:\n\t <#{e.message}>"
38
+ exit
39
+ end
40
+
41
+ def running?
42
+ setup()
43
+ return false if @pid.nil?
44
+ begin
45
+ Process.kill(0, @pid.to_i)
46
+ return true
47
+ rescue Errno::ESRCH, TypeError => e
48
+ #STDERR.puts "Error querying PID <#{@pid}>! Error was <#{e.message}>";
49
+ return false
50
+ rescue Errno::EPERM
51
+ STDERR.puts "No permission to query #{@pid}!";
52
+ return false
53
+ rescue => e
54
+ STDERR.puts "ERROR: Unable to check PXNX status:\n\t <#{e.message}>"
55
+ return false
56
+ end
57
+ end
58
+
59
+ def stop
60
+ setup()
61
+ abort "PXNX is not running!" unless running?
62
+ begin
63
+ STDOUT.puts "Stopping process #{@pid}..."
64
+ Timeout.timeout(@timeout) do
65
+ Process.kill("TERM", @pid.to_i)
66
+ sleep 5 while running?
67
+ end
68
+ rescue Timeout::Error
69
+ STDERR.puts "Shutdown timeout... forcing shutdown!"
70
+ Process.kill("KILL", @pid.to_i)
71
+ sleep 5 while process_exists?
72
+ end
73
+
74
+ remove_pid_file
75
+ STDOUT.puts "Process stopped."
76
+ end
77
+
78
+ def start()
79
+ abort "Process already running!" if running?
80
+ if pid = Spoon.spawnp('jruby', *ARGV)
81
+ create_pid_file(pid)
82
+ STDOUT.puts "Process started with pid #{pid}"
83
+ else
84
+ Process.setsid
85
+ end
86
+ end
87
+
88
+ case ARGV.shift
89
+ when 'start'
90
+ start()
91
+ when 'stop'
92
+ stop()
93
+ when 'restart'
94
+ stop()
95
+ start()
96
+ when 'status'
97
+ if running?
98
+ STDOUT.puts "PXNX is running with pid #{@pid}"
99
+ else
100
+ STDOUT.puts "PXNX is not running."
101
+ end
102
+ else
103
+ STDERR.puts "Usage: jruby pxnx_daemon.rb <start|stop|restart>"
104
+ exit!
105
+ end