Many of us have been experiencing issues with fog 0.32 where Scheduled Tasks do not show up in the web GUI. I’ve seen various discussions on these forums about the issue but no definitive fix. Hopefully this will provide a solution.
Before I go any further into this I work for a large university in the UK who rely on group scheduled tasks. We re-image a large number of machines each week based on group schedules including our IT Suites and Seminar rooms. Until a few weeks ago we had been using FOG 0.29 but decided to upgrade to 0.32 to find this bug.
For reference we are running FOG with CentOS 6.5, PHP 5.3.3, MySQL 5.1.73
Though you can schedule single host tasks and group tasks the webGUI will not display the scheduled tasks to allow you to delete them.
[IMG]http://s9.postimg.org/x780ntp2n/Fog_Scheduled_Tasks_web_GUI.png[/IMG]
/fog/management/index.php?node=tasks&sub=sched
After some poking and testing I discovered the issue came down to an undefined method / function call in one of the core classes under the function “getGroupById”:
The error in /etc/httpd/logs/error_log showed:
[INDENT=1]PHP Fatal error: Call to undefined method Group::addMember() in /var/www/fog/management/lib/FOGCore.class.php on line 212,[/INDENT]
This led me to the forums where the closest fix came from [url]http://fogproject.org/forum/threads/call-to-undefined-method-group-addmember.1008/[/url]. The instructions given were to comment out some of the code which got the GUI working however it stopped group scheduled tasks from running. Host scheduled tasks continued to work.
The instructions from [URL=‘http://fogproject.org/forum/threads/call-to-undefined-method-group-addmember.1008/#post-23191’]Ritchy_Purple[/URL] were as follows (I’ve put them here for reference - do not follow them!):
Modify FOGCore.class.php
line 137
[php]else if ( $group != null )
{
//add copy from below
$task = new ScheduledTask( $host, $group, $timer, $ar[“stTaskType”], $ar[“stID”] );
$task->setShutdownAfterTask( $ar[“stShutDown”] == 1 );
$task->setOther1( $ar[“stOther1”] );
$task->setOther2( $ar[“stOther2”] );
$task->setOther3( $ar[“stOther3”] );
$task->setOther4( $ar[“stOther4”] );
$task->setOther5( $ar[“stOther5”] );
$arTasks[] = $task;
// start Comment
/* if ( $group->getCount() > 0 )
{
$arRm = array();
$hosts = $group->getMembers();
for( $i = 0; $i < count($hosts); $i++ )
{
if ( $hosts[$i] != null )
{
$h = $hosts[$i];
if ( ! ($h->isReadyToImage() && $h->getImage()->getStorageGroup()->getID() == $groupid ) )
{
$arRm[] = $h;
}
}
}
//echo ( "Before: " . $group->getCount() );
for( $i = 0; $i < count($arRm); $i++ )
{
$group->removeMember( $arRm[$i] );
}
//echo ( "After: " . $group->getCount() );
$task = new ScheduledTask( $host, $group, $timer, $ar[“stTaskType”], $ar[“stID”] );
$task->setShutdownAfterTask( $ar[“stShutDown”] == 1 );
$task->setOther1( $ar[“stOther1”] );
$task->setOther2( $ar[“stOther2”] );
$task->setOther3( $ar[“stOther3”] );
$task->setOther4( $ar[“stOther4”] );
$task->setOther5( $ar[“stOther5”] );
$arTasks[] = $task;
} */
//end comment
//and comment also from below (Line 212 for me) BOLD
$group = null;
while( $ar = mysql_fetch_array( $res ) )
{
if ( $group == null )
{
$group = new Group($ar[“groupID”], $ar[“groupName”], $ar[“groupDesc”] );
}
/* $hid = $ar[“hostid”];
if ( $hid !== null && is_numeric( $hid ) )
{
$host = $this->getHostById( $hid );
if ( $host != null )
$group->addMember( $host );
} */
}
return $group;[/php]
While working through the instructions from that thread I setup a test group and a scheduled task to run every minute. Once the web GUI was showing the scheduled tasks I checked the Fog Scheduler log to find that group scheduled tasks no longer worked as it could not find the list of hosts associated with the group. (I have edited the output of the fog scheduler to give more details)
[INDENT=1]tail -f /opt/fog/log/fogscheduler.log[/INDENT]
[INDENT=1][04-17-14 12:29:45 pm] * Task run time: * * * * *[/INDENT]
[INDENT=1][04-17-14 12:29:45 pm] * Found a task that should run…[/INDENT]
[INDENT=1][04-17-14 12:29:45 pm] - Is a group based task.[/INDENT]
[INDENT=1][04-17-14 12:29:45 pm] - Found 0 hosts.[/INDENT]
[INDENT=1][04-17-14 12:29:45 pm] - No valid hosts.[/INDENT]
So dissecting the FOGScheduler service at /opt/fog/service/FOGTaskScheduler/FOGTaskScheduler, I found that the getScheduledTasksByStorageGroupID function I’ve just commented a load of code out from is being re-used.
[INDENT=1]91 $tasks = $core->getScheduledTasksByStorageGroupID( $groupid );[/INDENT]
So looking back over the code that was commented out you can see that once the getScheduledTasksByStorageGroupID function has information about the task it looks to see if the task is a group or a single task.
[INDENT=1]Is task is a single host task?[/INDENT]
[INDENT=1]115 If ( $ar[“stIsGroup”] == 0 ){[/INDENT]
[INDENT=1]Get information about host[/INDENT]
[INDENT=1]116 $host=$this->getHostById($ar[“stGroupHostID”]);[/INDENT]
[INDENT=1]117[/INDENT]
[INDENT=1]Is task a group task?[/INDENT]
[INDENT=1]118 }else if ( $ar[“stIsGroup”] == 1 ){// Task[/INDENT]
[INDENT=1]Get information about the group[/INDENT]
[INDENT=1]119 $group = $this->getGroupById($ar[“stGroupHostID”]);[/INDENT]
[INDENT=1]120[/INDENT]
[INDENT=1]121 }[/INDENT]
For group tasks on line 119 the function passes to another function getGroupById to get the members of the group. The getGroupById function looks at the DB and gets a list of hosts that are members of the group and then builds an array / list (calling another function Group::addMember( $host ) which caused the web GUI error) with each host as an entry.
The instructions from ritchy_purple were to comment out the part of the getGroupById function that built the array / list of hosts. So commenting out that would be the reason why the Fog Scheduler stopped working for groups!