From: pharrington Date: 2009-05-24T00:30:05+09:00 Subject: Re: Can't start webrick as the root user On May 23, 10:28 am, Pra Bhandar wrote: > Hi, > > I am trying to start Webrick as root user and get TCP Bind error even > though the port appears to be not taken.  Running the same script as a > non-root user that owns the ruby installs works just fine. > > 1) Running dvdelta_start.sh runs just fine as a non root user > 2) Running the same script gives me TCP Bind error >  su - dvdelta -c "/opt/apps/datavail/current-delta/dvdelta_start.sh > start" 2>&1 >>/tmp/dvdelta.log > > I'd appreciate any pointers to help debug this issue. > > Thanks. > > Prakash > +++++++++++++++++++++++++++++++++++ > > The log file shows the following - > > [2009-05-22 04:46:37] INFO  WEBrick 1.3.1 > [2009-05-22 04:46:37] INFO  ruby 1.8.7 (2009-04-08) [x86_64-linux] > [2009-05-22 04t:46:47] WARN  TCPServer Error: Address already in use - > bind(2) > [2009-05-22 04:46:47] INFO  WEBrick::HTTPServer#start: pid=30733 > port=8192 > > login as: root > > ++++++++++++++++++++++++++++++++++++++++++++++++++ > class JobServer > >    def initialize(jobRepository, port) >      @repos = jobRepository >      @port = port >    end > >    def run >     @server = HTTPServer.new( :Port => @port ) >     @server.mount("/styles.css", CssServlet) >     @server.mount("/jobs", ListJobsServlet, @repos) >     @server.mount("/deploy", DeployJobServlet, @repos) >     @server.mount("/", IndexServlet) >     trap("INT"){ @server.shutdown } >     @server.start >    end > > end > / > ++++++++++++++++++++++++++++++++++++++++++++++++++++ > Calling the server start... > >   server = JobServer.new(jobRepository, 8192) >   server.run > > ++++++++++++++++++++++++++++++++++++++++++++++++++++ > The log file shows the following - > > [2009-05-22 04:46:37] INFO  WEBrick 1.3.1 > [2009-05-22 04:46:37] INFO  ruby 1.8.7 (2009-04-08) [x86_64-linux] > [2009-05-22 04:46:47] WARN  TCPServer Error: Address already in use - > bind(2) > [2009-05-22 04:46:47] INFO  WEBrick::HTTPServer#start: pid=30733 > port=8192 > -- > Posted viahttp://www.ruby-forum.com/. Did you check to make sure that your app *really* isn't binding to port 8192? If it isn't, strace and netstat will be able to isolate that problem. More importantly, why does your app need to run as root? Running as root and connecting to the internet is the most reliable way to ensure you get compromised. If there are certain resources that *absolutely* require root to obtain, then obtain them as early as possible (definitely before starting the WEBrick server), then setuid down to a saner user.