#!/usr/bin/perl
#
#  $Id$
# -----------------------------------------------------------------------------
#  SM_NODE_DB_RESET - small tool for resetting node DB configuration
#  
# -----------------------------------------------------------------------------
#  Author: Alex Tsybylnik
#  QA by:
#  Copyright: videoNEXT LLC
# -----------------------------------------------------------------------------
#
# notes:
#   1. command line tool
#
# usage: 
#  sm_node_db_reset
#

use strict;
use warnings;
use Data::Dumper;
use File::Basename qw(dirname);
use lib dirname(__FILE__).'/../lib';            # find  SM::Config here
use SM::Config ':all';
use SKM::DB;
use Node::Conf;

# CONS ------------------------------------------------------------------------
my $APL = $ENV{APL};
my $NODERESET = (split(/\//,$0))[-1];	          # the actual name of the prog
my $UNI=UNI;                                      # char22 nodeid in domain

# VARS
my $dbm;

# MAIN =======================================================================
#
my $patrol = `ps ax | grep cam_patrol | grep -v grep`; chomp $patrol;
die "Application is running! Stop application before executing this script\n" if $patrol;

SM_LOG->info("$NODERESET: reset node UNI='$UNI'");
my $rows = 0;
eval {
    $dbm = DBMaster({RaiseError => 1});
    $rows = $dbm->do("DELETE FROM sm_nodes WHERE nodeid='$UNI'");
};
SM_LOG->logdie("DB_MASTER: $@") if $@;
if ($rows > 1) {
    SM_LOG->warn("$rows rows affected!");
} elsif ($rows == 0) {
    SM_LOG->logdie("Nothing deleted!")
}
