Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
XanderRadio

Multi program server for base

Question

i am making a server for my modded base on a server and i need it to be able to run several programs at once so that i can control multiple things at the same time, i would like to be able to also create new programs and modify code without interrupting the other programs running on the server. if this is possible please help, try to make the solution as simple and explainable as you can as i am rather new to open computers coding as far as crazy advanced stuff goes so try to make it have as few lines and variables as possible...

thanks in advance, XanderRadio

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

What you're looking for are daemons/services.

These are programs that run in the background while your gui is available in the foreground for you to use as normal.

Trouble is, they're kinda complex :P it took me far too long to understand how to use them!

 

Simpler solutions could be turning all of your functions into separate lua scripts and having a central program execute them one by one, round robin style.

As long as the scripts don't take too long, this would probably serve your purpose.

 

Of course if you want proper multithreading (i.e. running everything at once) then simply use multiple computers and you'll find a good deal of the technical issues just melt away.

Of course that solution isn't the cheapest...

Share this post


Link to post
Share on other sites
  • 0

I would agree with your first statement. Daemons/services are probably the route to go, but don't forget OpenOS has threads which can be handy too. Services are pretty dang simple though.. The only real requirement is that you have a start and stop method, any other method is optional. You can check out the example service in /etc/rc.d/example.lua but note that there is only a start method and the 'service' isn't very compelling as to possible uses. I think an easy mix is with services that spawn threads. i.e. A service that can manage other processes by launching and killing them with service methods. Here's a (hopefully) simple and understandable service..

/etc/rc.d/testservice.lua

local event = require "event"
local shell = require "shell"
local thread = require "thread"

local threads = {}

-- # Service methods (notice they aren't local variables. That makes them service methods)

function start(prog, ...)
  -- # start a program as a thread process.
  local proc = thread.create(shell.execute, prog, os.getenv("shell"), ...)
  -- # detach it from current process so rc doesn't block the main thread when we start.
  proc:detach()
  -- # keep track of started processes
  table.insert(threads, proc)
end

function stop()
  -- # kill all not 'dead' threads service started
  for i, proc in ipairs(threads) do
    if proc.status and proc:status() ~= "dead" then
      proc:kill() -- # stabby stab...
    end
  end
end

Use like so..  `rc testservice start myprogram args...`

Hope this gives you some ideas. Feel free to ask questions :3

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.