cleaned up some debug prints
[urisagit/Stem.git] / DEMO_INETD
CommitLineData
4536f655 1
2 Demonstration of Inetd Server Emulation
3
4This demonstration script emulates the standard inetd super-daemon found
5on all Unix systems. It showcases the Stem modules Stem::Proc (which
6handle processes) and Stem::SockMsg (a socket to message gateway). This
7demonstration runa a single Hub which listens for socket connections on
8two ports. When a connection comes in, a new process is spawned which
9interacts with the remote client that made the connection. This is
10effectively what inetd does but inetd_demo has several major
11advantages. StemInetd can insert filters and/or taps in the data stream,
12all its connections and status changes can be logged and filtered and it
13can be distributed securely across a network. The demo script is
14described in detail below with sections on running, using, configuring
15and experimenting with it.
16
17Running inetd_demo
18
19The single Hub inetd demonstration is called inetd_demo and it uses the
20inetd.stem configuration file (found in conf/). It is run with the simple
21command:
22
23inetd_demo
24
25To exit, just enter 'q' in the inetd_demo script window itself. It will
26kill all the other windows and then exit. This will also happen if you
27interrupt the demo script with ^C.
28
29If the -s option is used, then all the windows will use ssfe (split
30screen front end) which provides a command line edit and history window
31section and an output section. A single Hub window named Stem will be
32created and then 4 smaller telnet windows which will be connected to
33listen sockets in the Stem Hub. These telnet windows are the inetd users
34and they can type data and interact with a simple command line server
35program named proc_serv. The telnet windows are named A, B, C and D and
36if you use ssfe, each will display the telnet command it ran.
37
38Using inetd_demo
39
40Now enter the help command into window A and hit return. These are the
41commands you give the proc_serv application. Each of the user windows is
42connected to a different running proc_serv process. You can verify this
43by running the pid command in each window. Then have fun with the yow
44and insult commands. Later in the experimenting section, you can change
45the program to run and its options. The major difference among the user
46windows is that two of them A and C are connected to the 6666 port in
47the Hub and run the proc_serv in normal mode. The B and D windows are
48connected to the 6667 port in the Hub and run the proc_serv with -n so
49numbers the successful output lines.
50
51You can print out the list of all the registered Cells by sending a
52status command message to the Stem:Route Class Cell which is aliased to
53'reg'. In the Hub window (named Stem) type this command:
54
55reg status
56
57You will see this printout:
58
59Route Status for Hub ''
60
61 Object Cells with Target names of their Cloned Cells
62
63 A => Stem::SockMsg=HASH(0x2dd5a0)
64 :aaaaaa => Stem::SockMsg=HASH(0x2fda20)
65 :aaaaab => Stem::SockMsg=HASH(0x350ab0)
66 B => Stem::SockMsg=HASH(0x2ed474)
67 :aaaaaa => Stem::SockMsg=HASH(0x2c10ac)
68 :aaaaab => Stem::SockMsg=HASH(0x355040)
69 proc_serv => Stem::Proc=HASH(0x2fdbc4)
70 :aaaaac => Stem::Proc=HASH(0x3515c4)
71 :aaaaad => Stem::Proc=HASH(0x35554c)
72 :aaaaaa => Stem::Proc=HASH(0x2f881c)
73 :aaaaab => Stem::Proc=HASH(0x352660)
74
75 Class Cells with their Aliases
76
77 Stem::Conf => conf
78 Stem::Demo::Cmd => cmd
79 Stem::Hub => hub
80 Stem::Log =>
81 Stem::Log::Entry => entry
82 Stem::Portal => port
83 Stem::Route => foo reg
84 Stem::TtyMsg => tty
85 Stem::Vars => var
86
87This shows the Parent Object Cells A, B and proc_serv each with their
88own set of Cloned Cells. Below that are the loaded Class Cells.
89The two Stem::SockMsg Cells have 2 telnet users connected to them and
90the proc_serv Cell has cloned four Objects, each of which manages a
91single process. Note that parent Cells don't do the work, they manage
92the Cloned Cells which do it.
93
94
95How inetd_demo is Configured
96
97Look at the file conf/inetd.stem. That is the configuration file used by
98inetd_demo. It is very simple and easy to understand. It is a Perl list
99of lists structure with pairs of keys and values. Read the config_notes
100for more on this.
101
102The first Cell configured is Stem::TtyMsg which supports typing in and
103sending command messages. This is done in all the demo configurations.
104
105 [
106 class => 'Stem::TtyMsg',
107 args => [],
108 ],
109
110Then come two Stem::SockMsg Cells named A and B. Each has a server
111socket listening on its own port. Also they each will create a piped
112connection to the cell named 'proc_serv'. The Cell B has one extra
113attribute set, it adds the -n option when a process is spawned for it.
114
115[
116 class => 'Stem::SockMsg',
117 name => 'A',
118 args => [
119 port => 6666,
120 server => 1,
121 piped_to => 'proc_serv',
122 ],
123],
124[
125 class => 'Stem::SockMsg',
126 name => 'B',
127 args => [
128 port => 6667,
129 server => 1,
130 piped_to => 'proc_serv',
131 piped_args => [ '-n' ],
132 ],
133],
134
135
136
137Finally we have the Stem::Proc Cell named 'proc_serv' which can clone
138itself and spawn off processes.
139
140[
141 class => 'Stem::Proc',
142 name => 'proc_serv',
143 args => [
144 path => 'proc_serv',
145 use_stderr => 1,
146 piped_to => 1,
147 no_init_spawn => 1,
148 ],
149],
150
151The 'path' attribute is the absolute path or program name to
152be run. Note that this configuration assumes it will find 'proc_serv in
153$PATH. The three boolean attributed tell the Cell that it should handle
154output from stderr of the process, it is expecting a pipe connection
155request and it should only spawn processes when it has been cloned.
156
157
158Experimenting with inetd_demo
159
160These experiments are similar to the Hub and Portal ones in
161DEMO_CHAT. They show you how to change the processes StemInetd runs, and
162to distribute it over multiple systems over secure connections. Choose a
163second system and make sure Stem is properly installed on it (NFS
164mounting the tarball dir will help).
165
166To support a remote Hub connecting the Hub which owns the Stem::Proc
167Cell, you have to add a Stem::Portal Cell to each of them.
168
169Make two copies of the configuration file conf/inetd.stem and call them
170inetd_server.stem and inetd_client.stem
171
172Edit inetd_server.stem and rename the Stem::Hub configuration to
173inetd_server. Also insert this Stem::Portal Cell configuration into it
174replacing 'foo_host' with the server hostname:
175
176[
177 class => 'Stem::Portal',
178 args => [
179 'server' => 1,
180 'host' => 'foo_host'
181 ],
182],
183
184
185Edit inetd_client.stem and rename the Stem::Hub configuration to
186inetd_client. Delete the Stem::Proc Cell configuration. Also insert
187this Stem::Portal Cell configuration into it replacing 'foo_host' with
188the server hostname:
189
190[
191 class => 'Stem::Portal',
192 args => [
193 'host' => 'foo_host'
194 ],
195],
196
197
198You can create and modify as many of the Stem::SockMsg Cells as you want
199on each Hub. Then in a window on the server box, do:
200
201run_stem inetd_server
202
203and on a window in the other box (called bar_host) where Stem is setup do:
204
205run_stem inetd_client
206
207You can create telnet sessions from the 'server' system that connect
208to the ports of the Stem::SockMsg Cells.
209
210telnet localhost 6666
211telnet localhost 6667
212
213And on the 'inetd_client' system, connect telnets to the ports of its
214Stem::SockMsg Cells.
215
216telnet localhost 6666
217telnet localhost 6667
218
219You can now interact with this Stem application just as you did when it
220was running on one system as it did with inetd_demo.
221
222Instead of editing the configuration files, you could also set the
223Stem::Portal host attribute by setting a command line argument or
224environment variable. This command will make the 'server' Hub accept
225connections from the 'foo' host interface:
226
227run_stem host=foo chat_server
228
229You can do the same for the 'client' Hub and have it connect to host
230'foo'. By setting the STEM_HOST environment variable to the host name
231you can get the same effect.