News : The level of daily SPAM has reached insane proportions, all registrations are now manual. I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.


Post Reply  Post Thread 
lighttpd interface
Author Message
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #1
RE: lighttpd interface

Made some changes to it so it doesn't require the bash script.
The os.execute("sleep 2") should probably bechanged to an internal pause, but I didn't want to bother scripting a pause today, and wanted it to work on older versions of murgaLua (prior to murgaLua.createFltkTimer).

It _should_ work on just about any Linux system, and I assume OSX as well. Windows, though, is not supported. Maybe it will be in the future, but that is not a priority for me.

Code:
#!/bin/murgaLua

--[[

  gui controller for lighttpd (c)2006-2007 mikshaw
  should work with all versions of murgaLua
  
  external commands used: lighttpd, killall, sleep
  
]]

-- lighttpd daemon
lighttpd="/opt/lighttpd/sbin/lighttpd"
-- process ID file
pid="/var/run/lighttpd.pid"
-- config file (can be overidden by LIGHTTPD_CONF variable)
lighttpd_conf="/opt/lighttpd.conf"
-- for command output
tempfile="/tmp/lighttpd.lua.tmp"

Fl:get_system_colors()
Fl:scheme(NULL)

-- test for readable file
function isFile(file)
  whichfile=io.open(file,"r")
  if whichfile then
    whichfile:close()
    return true
  end
end

-- find conf file
lightyvar=os.getenv("LIGHTTPD_CONF")
if lightyvar then
  if isFile(lightyvar) then
    lighttpd_conf=lightyvar
  end
end

-- see if server is running
function checkstatus()
  state:hide() -- prevents label overlap
  if isFile(pid) then
    state:label("server is running")
  else
    state:label("server is not running")
  end
  state:show()
end

function testconfig(prnt)
  outpoot:add("Using configuration file "..lighttpd_conf)
  if os.execute(lighttpd..prnt.." -t -f "..lighttpd_conf.." &>"..tempfile) == 0 then
    return true
  end
end

function start_lighty()
  if testconfig("") then
    outpoot:add("Starting lighttpd...")
    Fl:check()
    if os.execute(lighttpd.." -f "..lighttpd_conf.." &>"..tempfile) == 0 then
      outpoot:add("lighttpd started")
    end
  end
end

function stop_lighty()
  outpoot:add("Shutting down lighttpd...")
  Fl:check()
  if os.execute("killall "..lighttpd.." &>"..tempfile) == 0 then
    outpoot:add("lighttpd stopped")
    os.remove(pid)
  end
end

function lcontrol(self)
  if self:label() == "test config" then
    testconfig(" -p")
  elseif self:label() == "start" then
    start_lighty()
    checkstatus()
  elseif self:label() == "stop" then
    stop_lighty()
    checkstatus()
  elseif self:label() == "restart" then
    stop_lighty()
    Fl:check()
    os.execute("sleep 2")
    start_lighty()
    checkstatus()
  end
  -- show the command output
  filename=io.open(tempfile)
  if filename then
    for line in filename:lines() do outpoot:add(line) end
    outpoot:bottomline(outpoot:size())
    filename:close()
    os.remove(tempfile)
  end
end

-- start interface
bw=80;bh=25;ww=bw*4;wh=bh*7
w=fltk:Fl_Window(ww,wh,"LIGHTTPD Control")
cfg=fltk:Fl_Box(0,bh,ww,bh)
cfg:label("config file: "..lighttpd_conf)
state=fltk:Fl_Box(0,bh*2,ww,bh)
bup=fltk:Fl_Button(0,0,bw,bh,"start");bup:callback(lcontrol)
bdn=fltk:Fl_Button(bw,0,bw,bh,"stop");bdn:callback(lcontrol)
bre=fltk:Fl_Button(bw*2,0,bw,bh,"restart");bre:callback(lcontrol)
bt=fltk:Fl_Button(bw*3,0,bw,bh,"test config");bt:callback(lcontrol)

outpoot=fltk:Fl_Browser(0,bh*3,ww,bh*4)
w:resizable(outpoot)

checkstatus()
w:show()
Fl:run()

09-09-2007 04:53 AM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

Messages In This Thread
lighttpd interface - mikshaw - 09-08-2007, 09:53 AM
RE: lighttpd interface - mikshaw - 09-09-2007 04:53 AM

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: