1 | 1 | simandl | #!/usr/bin/env perl |
2 | | | |
3 | | | $|=1; |
4 | | | |
5 | | | use lib "../../lib"; |
6 | | | use HotSaNICparser; |
7 | | | use HotSaNICmod; |
8 | | | |
9 | | | my $MODLOGDIR="."; |
10 | | | my $MODPIDFILE="running.pid"; |
11 | | | my $MODNAME=HotSaNICparser::get_module_name(); |
12 | | | |
13 | | | |
14 | | | checkargs(@ARGV); |
15 | | | |
16 | | | |
17 | | | ###################################################################### |
18 | | | # |
19 | | | # wrapper |
20 | | | # |
21 | | | sub sample { |
22 | | | if (-e "./read-data") { system ("nice -5 ./read-data"); } |
23 | | | elsif (-e "./read-data.pl") { system ("nice -5 ./read-data.pl"); } |
24 | | | } |
25 | | | |
26 | | | sub update { |
27 | | | } |
28 | | | |
29 | | | ###################################################################### |
30 | | | # |
31 | | | # fork into background |
32 | | | # |
33 | | | sub daemonize { |
34 | | | my ($MODPIDFILE,$MODNAME,$MODLOGDIR)=@_; |
35 | | | |
36 | | | # set signal handlers |
37 | | | # |
38 | | | $SIG{TERM} = \&terminate; |
39 | | | $SIG{HUP} = \&configure; |
40 | | | $SIG{USR1} = \&sample; |
41 | | | $SIG{USR2} = \&update; |
42 | | | |
43 | | | $MODLOGDIR=""; |
44 | | | # open STDIN,"/dev/null"; |
45 | | | # open STDOUT,">>$MODLOGDIR"."/mod_$MODNAME.log"; |
46 | | | # open STDERR,">>$MODLOGDIR"."/mod_$MODNAME.log"; |
47 | | | # chdir "/"; |
48 | | | fork && exit 0; |
49 | | | } |
50 | | | |
51 | | | |
52 | | | ###################################################################### |
53 | | | # |
54 | | | # terminate module daemon |
55 | | | # |
56 | | | sub terminate { |
57 | | | HotSaNICmod::dupe_control("stop",$MODNAME,""); |
58 | | | unlink $MODPIDFILE if -e $MODPIDFILE; |
59 | | | # close STDIN; |
60 | | | # close STDOUT; |
61 | | | # close STDERR; |
62 | | | exit 0; |
63 | | | } |
64 | | | |
65 | | | |
66 | | | ###################################################################### |
67 | | | # |
68 | | | # check cmdline arguments |
69 | | | # |
70 | | | sub checkargs { |
71 | | | $args=join " ",@_; |
72 | | | |
73 | | | if ( $args eq "" ) { |
74 | | | print "arguments missing!\n"; |
75 | | | print "usage: $0 [start/stop/status/version]\n"; |
76 | | | } |
77 | | | |
78 | | | if ( $args =~ /version/) { |
79 | | | print "wrapper script\n"; |
80 | | | } |
81 | | | |
82 | | | if ( $args =~ /start/) { |
83 | | | my ($pid,$uptime)=HotSaNICmod::dupe_control("check",$MODNAME,""); |
84 | | | if ($pid > 0) { print "$MODNAME already running on PID $pid\n"; } |
85 | | | else { |
86 | | | daemonize($MODPIDFILE,$MODNAME,$MODLOGDIR); |
87 | | | HotSaNICmod::dupe_control("start",$MODNAME,""); |
88 | | | while (1 == 1) { sleep; } |
89 | | | } |
90 | | | } |
91 | | | |
92 | | | if ( $args =~ /status/) { |
93 | | | my ($pid,$uptime)=HotSaNICmod::dupe_control("check",$MODNAME,""); |
94 | | | print "$MODNAME running on PID $pid for $uptime sec.\n"; |
95 | | | } |
96 | | | |
97 | | | if ( $args =~ /sample/) { |
98 | | | my ($pid,$uptime)=HotSaNICmod::dupe_control("check",$MODNAME,""); |
99 | | | if ($pid > 0) { kill "SIGUSR1",$pid; } |
100 | | | else { print "no process running.\n"; } |
101 | | | } |
102 | | | |
103 | | | if ( $args =~ /stop/) { |
104 | | | my ($pid,$uptime)=HotSaNICmod::dupe_control("check",$MODNAME,""); |
105 | | | if ($pid > 0) { kill "SIGTERM",$pid; } |
106 | | | else { print "no process running.\n"; } |
107 | | | } |
108 | | | } |
109 | | | |