Simple server that triggers script and responds












2















I need to have a server running that can:




  1. Take rest call. It triggers a script when a call is made

  2. The script checks if database is running or not.

  3. If running then reply back to client as Success else reply back as
    failure


I do not wish to use apache or any other major web server. Even simple scripts running on port will do. I am aware of python -m SimpleHTTPServer but I guess it only provides file access.



I can write a simple Java program that runs on a port and replies, but I am looking some simple solution










share|improve this question





























    2















    I need to have a server running that can:




    1. Take rest call. It triggers a script when a call is made

    2. The script checks if database is running or not.

    3. If running then reply back to client as Success else reply back as
      failure


    I do not wish to use apache or any other major web server. Even simple scripts running on port will do. I am aware of python -m SimpleHTTPServer but I guess it only provides file access.



    I can write a simple Java program that runs on a port and replies, but I am looking some simple solution










    share|improve this question



























      2












      2








      2


      2






      I need to have a server running that can:




      1. Take rest call. It triggers a script when a call is made

      2. The script checks if database is running or not.

      3. If running then reply back to client as Success else reply back as
        failure


      I do not wish to use apache or any other major web server. Even simple scripts running on port will do. I am aware of python -m SimpleHTTPServer but I guess it only provides file access.



      I can write a simple Java program that runs on a port and replies, but I am looking some simple solution










      share|improve this question
















      I need to have a server running that can:




      1. Take rest call. It triggers a script when a call is made

      2. The script checks if database is running or not.

      3. If running then reply back to client as Success else reply back as
        failure


      I do not wish to use apache or any other major web server. Even simple scripts running on port will do. I am aware of python -m SimpleHTTPServer but I guess it only provides file access.



      I can write a simple Java program that runs on a port and replies, but I am looking some simple solution







      shell scripting webserver http






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 47 mins ago









      Rui F Ribeiro

      41.5k1483140




      41.5k1483140










      asked Jun 26 '14 at 9:25









      JatinJatin

      11113




      11113






















          2 Answers
          2






          active

          oldest

          votes


















          3














          One of the more trivial services I can imagine is to run one from xinetd. That has the advantage that xinetd itself is relatively light-weight but will still handle all the networking stuff for you including logging and security restrictions such as request limiting, TCP-wrappers etc.



          Install xinetd, when it is not already installed and define a custom service like /etc/xinetd.d/helloworld :



          service helloworld
          {
          disable = no
          port = 1234
          socket_type = stream
          protocol = tcp
          wait = no
          user = nobody
          server = /usr/local/bin/hello-world.sh
          server_args = test
          instances = 1
          type = unlisted
          }


          Reload/restart xinetd and you can test with a telnet localhost 1234.



          The manual page man xinetd.conf has a pretty good description of the options available.






          share|improve this answer































            2














            I would do that in BASH with the help of some simple nc commands:



            #!/bin/bash

            nc -k -l -p PORT > tempfile

            while true
            do
            if cat tempfile | grep request;
            then
            # Execute checker script
            # Reply back with nc
            : > tempfile # Clear tempfile
            fi
            sleep 1
            done


            This would require setting up the client with nc as well. Maybe setting up an nc listen command on the client is also required to receive the Success reply.



            This script is far from complete, and you should also write the client for it, but it might give you some ideas.



            The basic thing here is the use of nc. With the help of it, you can set up simple client-server architectures.






            share|improve this answer























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "106"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f139311%2fsimple-server-that-triggers-script-and-responds%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              3














              One of the more trivial services I can imagine is to run one from xinetd. That has the advantage that xinetd itself is relatively light-weight but will still handle all the networking stuff for you including logging and security restrictions such as request limiting, TCP-wrappers etc.



              Install xinetd, when it is not already installed and define a custom service like /etc/xinetd.d/helloworld :



              service helloworld
              {
              disable = no
              port = 1234
              socket_type = stream
              protocol = tcp
              wait = no
              user = nobody
              server = /usr/local/bin/hello-world.sh
              server_args = test
              instances = 1
              type = unlisted
              }


              Reload/restart xinetd and you can test with a telnet localhost 1234.



              The manual page man xinetd.conf has a pretty good description of the options available.






              share|improve this answer




























                3














                One of the more trivial services I can imagine is to run one from xinetd. That has the advantage that xinetd itself is relatively light-weight but will still handle all the networking stuff for you including logging and security restrictions such as request limiting, TCP-wrappers etc.



                Install xinetd, when it is not already installed and define a custom service like /etc/xinetd.d/helloworld :



                service helloworld
                {
                disable = no
                port = 1234
                socket_type = stream
                protocol = tcp
                wait = no
                user = nobody
                server = /usr/local/bin/hello-world.sh
                server_args = test
                instances = 1
                type = unlisted
                }


                Reload/restart xinetd and you can test with a telnet localhost 1234.



                The manual page man xinetd.conf has a pretty good description of the options available.






                share|improve this answer


























                  3












                  3








                  3







                  One of the more trivial services I can imagine is to run one from xinetd. That has the advantage that xinetd itself is relatively light-weight but will still handle all the networking stuff for you including logging and security restrictions such as request limiting, TCP-wrappers etc.



                  Install xinetd, when it is not already installed and define a custom service like /etc/xinetd.d/helloworld :



                  service helloworld
                  {
                  disable = no
                  port = 1234
                  socket_type = stream
                  protocol = tcp
                  wait = no
                  user = nobody
                  server = /usr/local/bin/hello-world.sh
                  server_args = test
                  instances = 1
                  type = unlisted
                  }


                  Reload/restart xinetd and you can test with a telnet localhost 1234.



                  The manual page man xinetd.conf has a pretty good description of the options available.






                  share|improve this answer













                  One of the more trivial services I can imagine is to run one from xinetd. That has the advantage that xinetd itself is relatively light-weight but will still handle all the networking stuff for you including logging and security restrictions such as request limiting, TCP-wrappers etc.



                  Install xinetd, when it is not already installed and define a custom service like /etc/xinetd.d/helloworld :



                  service helloworld
                  {
                  disable = no
                  port = 1234
                  socket_type = stream
                  protocol = tcp
                  wait = no
                  user = nobody
                  server = /usr/local/bin/hello-world.sh
                  server_args = test
                  instances = 1
                  type = unlisted
                  }


                  Reload/restart xinetd and you can test with a telnet localhost 1234.



                  The manual page man xinetd.conf has a pretty good description of the options available.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jun 26 '14 at 12:45









                  HBruijnHBruijn

                  5,6161527




                  5,6161527

























                      2














                      I would do that in BASH with the help of some simple nc commands:



                      #!/bin/bash

                      nc -k -l -p PORT > tempfile

                      while true
                      do
                      if cat tempfile | grep request;
                      then
                      # Execute checker script
                      # Reply back with nc
                      : > tempfile # Clear tempfile
                      fi
                      sleep 1
                      done


                      This would require setting up the client with nc as well. Maybe setting up an nc listen command on the client is also required to receive the Success reply.



                      This script is far from complete, and you should also write the client for it, but it might give you some ideas.



                      The basic thing here is the use of nc. With the help of it, you can set up simple client-server architectures.






                      share|improve this answer




























                        2














                        I would do that in BASH with the help of some simple nc commands:



                        #!/bin/bash

                        nc -k -l -p PORT > tempfile

                        while true
                        do
                        if cat tempfile | grep request;
                        then
                        # Execute checker script
                        # Reply back with nc
                        : > tempfile # Clear tempfile
                        fi
                        sleep 1
                        done


                        This would require setting up the client with nc as well. Maybe setting up an nc listen command on the client is also required to receive the Success reply.



                        This script is far from complete, and you should also write the client for it, but it might give you some ideas.



                        The basic thing here is the use of nc. With the help of it, you can set up simple client-server architectures.






                        share|improve this answer


























                          2












                          2








                          2







                          I would do that in BASH with the help of some simple nc commands:



                          #!/bin/bash

                          nc -k -l -p PORT > tempfile

                          while true
                          do
                          if cat tempfile | grep request;
                          then
                          # Execute checker script
                          # Reply back with nc
                          : > tempfile # Clear tempfile
                          fi
                          sleep 1
                          done


                          This would require setting up the client with nc as well. Maybe setting up an nc listen command on the client is also required to receive the Success reply.



                          This script is far from complete, and you should also write the client for it, but it might give you some ideas.



                          The basic thing here is the use of nc. With the help of it, you can set up simple client-server architectures.






                          share|improve this answer













                          I would do that in BASH with the help of some simple nc commands:



                          #!/bin/bash

                          nc -k -l -p PORT > tempfile

                          while true
                          do
                          if cat tempfile | grep request;
                          then
                          # Execute checker script
                          # Reply back with nc
                          : > tempfile # Clear tempfile
                          fi
                          sleep 1
                          done


                          This would require setting up the client with nc as well. Maybe setting up an nc listen command on the client is also required to receive the Success reply.



                          This script is far from complete, and you should also write the client for it, but it might give you some ideas.



                          The basic thing here is the use of nc. With the help of it, you can set up simple client-server architectures.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jun 26 '14 at 10:02









                          psimonpsimon

                          967726




                          967726






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Unix & Linux Stack Exchange!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f139311%2fsimple-server-that-triggers-script-and-responds%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Accessing regular linux commands in Huawei's Dopra Linux

                              Can't connect RFCOMM socket: Host is down

                              Kernel panic - not syncing: Fatal Exception in Interrupt