#197237 - 2009-12-30 04:47 PM
For Allen ;)
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
|
Since Allen is bored and my brain is starting to hurt, I'll post this as a challenge...
I have a Kix script that is running as a service on 160+ servers across the enterprise. This script runs in two modes: 1. called without args, it assumes the service role as a scheduler/dispatcher, running in an infinite loop and dispatching commands after specific time periods elapse. At the appointed time, the script calls a copy of itself via RUN, with an argument that identifies one of 8 specific tasks to perform. 2. called with an arg, it performs one of the specific duties of the service and exits. The result/status is checked by the service.
This method allows all of the code to reside in a single script, making maintenance easy. It also eliminates a common problem with schedule/dispatch logic where a sub-task can run long enough to prevent another subtask from running it its timeslot. The dispatcher invokes subtasks on 2-minute Odd, 2-minute Even, 6-minute, hourly on each of four 15-minute periods, and 4-hour periods. Subtasks take from sub-second to multi-hours to complete, and logic is present to prevent multiple copies of sub-tasks from running as well as terminate tasks that run more than 6 hours. (so far, ~90 minutes has been the longest-running sub-task, so this time-limit value may be reduced.)
So - here's what I'm struggling with.. I want the script to update itself.
The service runs constantly, but generally has little work to do overnight. It synchronizes a directory structure over the WAN from an upstream peer determined by DNS SRV records. It also consolidates individual local logs and then pushes the consolidation logs upstream, where they ultimately arrive at the master server.
The script can check its peer to determine if a newer version of the script is available. It can copy that script over itself while it is running. The child processes will immediately begin using the new copy. To avoid any compatability issues with the child process returning data to the parent, I want the scheduler to restart itself as soon as it overwrites the script file. If this were Unix, I'd simply Exec the new copy, replacing the current running process with the latest script.
Restarting the service would accomplish this, but I have two challenges. If there are child processes running, they will die.. so I need to perform the "update & restart" only when no sub processes are active. This is easy enough to detect. The one I'm struggling with is how to restart the service without some external dependency. RUN "XNET RESTART KixService" would work, but would place the dependency on the XNET.EXE command. The UDFs can start/stop the service, but once I stop, I can't restart. None of the UDFs seem to support a restart.
So - in a nutshell - I'm looking for some ideas on how I can restart an actively running script via the script itself, thus loading the newest version.
Thanks!
Glenn
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 2679 anonymous users online.
|
|
|