gom-sensor-ports 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -0,0 +1,96 @@
1
+ #!/bin/sh
2
+ ### BEGIN INIT INFO
3
+ # Provides: gom-sensor-ports
4
+ # Required-Start: $remote_fs $syslog
5
+ # Required-Stop: $remote_fs $syslog
6
+ # X-Start-Before: kdm gdm xdm
7
+ # X-Stop-After: kdm gdm xdm
8
+ # Default-Start: 2 3 4 5
9
+ # Default-Stop: 1
10
+ # Short-Description: Start the gom-sensor-ports daemon
11
+ # Description: running a gateway daemon to map simple TCP/UDP sensor values to GOM HTTP updates
12
+ ### END INIT INFO
13
+
14
+ set -e
15
+
16
+ NAME=gom-sensor-ports
17
+ DESC="t-gallery gom-sensor-ports daemon"
18
+ GOM_NODE="http://gom.bonn.t-gallery/sensors/colours-and-materials/conducting-lacquer/"
19
+ LOGFILE="/var/log/colours-and-materials.log"
20
+ DAEMON_USER="webs"
21
+ DAEMON=$(which ${NAME})
22
+ VERBOSITY="--verbose"
23
+
24
+ PIDDIR=/var/run/colours-and-materials-gom-daemon
25
+ PIDFILE=$PIDDIR/pid
26
+ #VERBOSITY="--quiet"
27
+ PARAMS="--logfile=${LOGFILE} ${GOM_NODE}"
28
+
29
+ test -x $DAEMON || exit 0
30
+
31
+ # Get lsb functions
32
+ . /lib/lsb/init-functions
33
+ . /etc/default/rcS
34
+
35
+ start_it_up()
36
+ {
37
+ if [ ! -d $PIDDIR ]; then
38
+ mkdir -p $PIDDIR
39
+ chown $DAEMON_USER $PIDDIR
40
+ #chgrp $DAEMON_USER $PIDDIR
41
+ fi
42
+
43
+ touch $LOGFILE
44
+ chown $DAEMON_USER $LOGFILE
45
+
46
+ if [ -e $PIDFILE ]; then
47
+ PIDDIR=/proc/$(cat $PIDFILE)
48
+ if [ -d ${PIDDIR} -a "$(readlink -f ${PIDDIR}/exe)" = "${DAEMON}" ]; then
49
+ log_success_msg "$DESC already started; not starting."
50
+ return
51
+ else
52
+ log_success_msg "Removing stale PID file $PIDFILE."
53
+ rm -f $PIDFILE
54
+ fi
55
+ fi
56
+
57
+ log_daemon_msg "Starting $DESC" "$NAME"
58
+ /sbin/start-stop-daemon --start --background $VERBOSITY \
59
+ --make-pidfile --pidfile $PIDFILE \
60
+ -c $DAEMON_USER --exec $DAEMON -- $PARAMS
61
+
62
+ log_end_msg $?
63
+ }
64
+
65
+
66
+ shut_it_down()
67
+ {
68
+ log_daemon_msg "Stopping $DESC" "$NAME"
69
+ /sbin/start-stop-daemon $VERBOSITY --stop --retry 5 --oknodo \
70
+ --pidfile $PIDFILE --user $DAEMON_USER
71
+ # We no longer include these arguments so that start-stop-daemon
72
+ # can do its job even given that we may have been upgraded.
73
+ # We rely on the pidfile being sanely managed
74
+ log_end_msg $?
75
+ rm -f $PIDFILE
76
+ }
77
+
78
+ case "$1" in
79
+ start)
80
+ start_it_up
81
+ ;;
82
+ stop)
83
+ shut_it_down
84
+ ;;
85
+ restart)
86
+ shut_it_down
87
+ start_it_up
88
+ ;;
89
+ status)
90
+ status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
91
+ ;;
92
+ *)
93
+ log_success_msg "Usage: /etc/init.d/${NAME} {start|stop|restart|status}"
94
+ exit 2
95
+ esac
96
+
@@ -2,18 +2,21 @@ module Gom
2
2
  class SensorPorts < Gom::Remote::Entry
3
3
 
4
4
  Defaults = {
5
+ :logfile => '-',
5
6
  :interface => '0.0.0.0',
6
7
  :sensor_port => 76001,
7
8
  :mode => :udp,
8
9
  }
9
10
 
10
11
  include OAttr
11
- oattr :interface, :sensor_port, :mode
12
+ oattr :logfile, :interface, :sensor_port, :mode
12
13
 
13
14
  def initialize path, options = {}
14
15
  @path = path
15
16
  @options = Defaults.merge(gnode @path).merge(options)
16
17
  puts " -- new sensor port: #{self.inspect}"
18
+
19
+ redirect_to logfile
17
20
  end
18
21
 
19
22
  def listen
@@ -25,8 +28,9 @@ module Gom
25
28
  socket = UDPSocket.new
26
29
  socket.bind(interface, sensor_port)
27
30
  loop do
28
- msg, sender = socket.recvfrom(1024)
29
- puts "-->#{msg}<-- #{sender.inspect}"
31
+ val, sender = socket.recvfrom(1024)
32
+ puts "-->#{val}<-- #{sender.inspect}"
33
+ connection.write "#{@path}:current_value", val.to_s
30
34
  end
31
35
  ensure
32
36
  socket.close rescue nil
@@ -40,6 +44,24 @@ module Gom
40
44
  #t.login(user, password) { |c| puts c }
41
45
  "not implemented"
42
46
  end
47
+
48
+ def redirect_to logfile
49
+ (@logfile_fd && @logfile_fd.close) rescue nil
50
+ puts " -- redirecting stdout/stderr to: #{logfile}"
51
+ if logfile == '-'
52
+ if @stdout
53
+ $stderr, $stdout = @stdout, @stderr
54
+ end
55
+ else
56
+ @stderr, @stdout = $stdout, $stderr
57
+ @logfile_fd = File.open(logfile, File::WRONLY|File::APPEND|File::CREAT)
58
+ @logfile_fd.sync = true
59
+ $stderr = $stdout = @logfile_fd
60
+ end
61
+ # first line after redirect
62
+ puts " -- daemon logile redirect at #{Time.now}"
63
+ end
64
+
43
65
  end
44
66
  end
45
67
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gom-sensor-ports
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - art+com AG/dirk luesebrink
@@ -93,6 +93,7 @@ files:
93
93
  - Rakefile
94
94
  - VERSION
95
95
  - bin/gom-sensor-ports
96
+ - etc/gom-sensor-ports-debian-init-script
96
97
  - lib/gom-sensor-ports.rb
97
98
  - lib/gom-sensor-ports/sensor-ports.rb
98
99
  - spec/gom-sensor-ports/sensor-ports_spec.rb