title: Shutting down Netty Server
body: <p>I have a little problem about shutting down Netty Server.
  The documentation says about shutting down the server is that;</p>
  
  <pre><code>public class TimeServer {
  
  static final ChannelGroup allChannels = new DefaultChannelGroup("time-server");
  
  public static void main(String[] args) throws Exception {
      ...
      ChannelFactory factory = ...;
      ServerBootstrap bootstrap = ...;
      ...
      Channel channel = bootstrap.bind(...);
      allChannels.add(channel);
      waitForShutdownCommand();
      ChannelGroupFuture future = allChannels.close();
      future.awaitUninterruptibly();
      factory.releaseExternalResources();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>then after searching around what "waitForShutDownCommand" is, I found that it is something like a ShutdownHook method.
  Well then I added a shutdownhook method to my server, </p>
  
  <pre><code>Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
          @Override
          public void run() {
              nettyServer.shutDown();
          }
      }, "shutDownHook"));
  </code></pre>
  
  <p>But then, I realized that when I try to quit my server with ctrl-c it is not called always. 
  Because When server shutdown I want to do some operation which is related to that server. 
  (Like deleting all the data from Redis which is related to that server.)</p>
  
  <p>So.. I come up with an idea, but I did not implement yet, I just want to make sure that if it is a good approach or not. So, to shutdown a server I need a CLIENT (Admin Client) which sends SHUTDOWN command to that server.Actually, I did not want to create an ADMIN Client, because I don't want to care of another client application and security things etc...</p>
  
  <p>So what is your solutions? Any Ideas? 
  Thanks...</p>