[PC-BSD Commits] r4927 - in pcbsd/trunk/lifePreserver: . scripts

svn at pcbsd.org svn at pcbsd.org
Mon Nov 9 13:08:42 PST 2009


Author: kris
Date: 2009-11-09 13:08:42 -0800 (Mon, 09 Nov 2009)
New Revision: 4927

Added:
   pcbsd/trunk/lifePreserver/scripts/kill-backup.sh
Modified:
   pcbsd/trunk/lifePreserver/lPreserve.pro
   pcbsd/trunk/lifePreserver/lifePreserverMain.cpp
   pcbsd/trunk/lifePreserver/lifePreserverMain.h
   pcbsd/trunk/lifePreserver/preserver.cpp
   pcbsd/trunk/lifePreserver/scripts/backup-rsync.sh
   pcbsd/trunk/lifePreserver/scripts/functions.sh
Log:

Updated life-preserver more, now we can properly start / stop backups via the GUI, which is handy for those
who don't like to use cron



Modified: pcbsd/trunk/lifePreserver/lPreserve.pro
===================================================================
--- pcbsd/trunk/lifePreserver/lPreserve.pro	2009-11-09 18:44:16 UTC (rev 4926)
+++ pcbsd/trunk/lifePreserver/lPreserve.pro	2009-11-09 21:08:42 UTC (rev 4927)
@@ -17,14 +17,12 @@
 
 TRANSLATIONS = LifePreserver_en_US.ts 
 
-QT +=  webkit
-
 INCLUDEPATH     += /usr/PCBSD/includes /usr/local/kde4/include
 
 TARGET=/usr/PCBSD/lifePreserver/bin/life-preserver
 
 scripts.path=/usr/PCBSD/lifePreserver/scripts
-scripts.files=scripts/setup-ssh-keys.sh scripts/start-backup.sh scripts/functions.sh scripts/backup-rsync.sh
+scripts.files=scripts/setup-ssh-keys.sh scripts/start-backup.sh scripts/functions.sh scripts/backup-rsync.sh scripts/kill-backup.sh
 
 conf.path=/usr/PCBSD/lifePreserver/conf
 conf.files=conf/rsync-excludes

Modified: pcbsd/trunk/lifePreserver/lifePreserverMain.cpp
===================================================================
--- pcbsd/trunk/lifePreserver/lifePreserverMain.cpp	2009-11-09 18:44:16 UTC (rev 4926)
+++ pcbsd/trunk/lifePreserver/lifePreserverMain.cpp	2009-11-09 21:08:42 UTC (rev 4927)
@@ -30,6 +30,7 @@
 #include <QDir>
 #include <QFile>
 #include <QDebug>
+#include <QTimer>
 
 #include <kmenu.h>
 
@@ -56,8 +57,36 @@
    connect(pushEditPreserver, SIGNAL( clicked() ), this, SLOT(slotPushEditPreserverClicked() ) );
    connect(pushPreserverStart, SIGNAL( clicked() ), this, SLOT(slotPushPreserverStartClicked() ) );
    treePreservers->resizeColumnToContents(0);
+
+   // Start monitoring for changes
+   QTimer::singleShot(5000, this, SLOT(slotScanPreserversForChanges() ) );
 }
 
+// Slot which monitors for changes in our preservers
+void lifePreserver::slotScanPreserversForChanges()
+{
+
+  QTreeWidgetItemIterator it(treePreservers);
+  while (*it) {
+    QString host = (*it)->text(0);
+    PRESERVER myPreserver(host);
+    int pid = myPreserver.getPID();
+    if ( pid == -1 ) {
+      pushPreserverStart->setText(tr("Start"));
+      (*it)->setText(3, tr("Not running"));
+    } else {
+      pushPreserverStart->setText(tr("Stop"));
+      (*it)->setText(3, tr("Running"));
+    }
+    (*it)->setText(1, getPreserverLastBackup(host));
+    (*it)->setText(2, getPreserverFrequency(host));
+  
+    ++it;
+  }
+
+  QTimer::singleShot(3000, this, SLOT(slotScanPreserversForChanges() ) );
+}
+
 // Slot which checks which preserver is currently highlighted
 void lifePreserver::slotCurrentTreePreserverChanged(QTreeWidgetItem *curItem)
 {

Modified: pcbsd/trunk/lifePreserver/lifePreserverMain.h
===================================================================
--- pcbsd/trunk/lifePreserver/lifePreserverMain.h	2009-11-09 18:44:16 UTC (rev 4926)
+++ pcbsd/trunk/lifePreserver/lifePreserverMain.h	2009-11-09 21:08:42 UTC (rev 4927)
@@ -37,6 +37,7 @@
    void slotPushPreserverStartClicked();
    void slotCurrentTreePreserverChanged(QTreeWidgetItem *curItem);
    void loadPreservers();
+   void slotScanPreserversForChanges();
 
 private:
    lifePreserverWizard *lpw;

Modified: pcbsd/trunk/lifePreserver/preserver.cpp
===================================================================
--- pcbsd/trunk/lifePreserver/preserver.cpp	2009-11-09 18:44:16 UTC (rev 4926)
+++ pcbsd/trunk/lifePreserver/preserver.cpp	2009-11-09 21:08:42 UTC (rev 4927)
@@ -104,11 +104,15 @@
 // Function which starts the target backup
 void PRESERVER::startBackup()
 {
+  QString cmd = LIFEPRESERVERPATH + "/scripts/start-backup.sh " + connectHost + " &";
+  system(cmd.toLatin1());
 }
 
 // Function which stops the target backup
 void PRESERVER::stopBackup()
 {
+  QString cmd = LIFEPRESERVERPATH + "/scripts/kill-backup.sh " + connectHost + "";
+  system(cmd.toLatin1());
 }
 
 // Function which removes a cron entry for this backup
@@ -269,7 +273,7 @@
 int PRESERVER::getPID()
 {
    bool ok;
-   int pid;
+   int pid = -1;
 
    // Read in the pid file
    QFile pidFile( LIFEPRESERVERSDIR + "/" + connectHost + "/preserver.pid" );
@@ -280,14 +284,24 @@
      while ( !stream.atEnd() ) {
        line = stream.readLine(); // line of text excluding '\n'
        pid = line.toInt(&ok);
-       if ( ok )
-       {
-         return pid;
-       } 
+       break;
      }
+     pidFile.close();
    }
   
-  return -1;
+  if ( pid != -1 )
+  {
+    // Check if this PID is alive
+    QString cmd, tmp;
+    tmp.setNum(pid);
+    cmd = "ps -p " + tmp ;
+    if ( system(cmd.toLatin1()) != 0 )
+    {
+       pidFile.remove();
+       pid = -1;
+    }
+  }
+  return pid;
 }
 
 QVariant PRESERVER::getConfValue(QString key)

Modified: pcbsd/trunk/lifePreserver/scripts/backup-rsync.sh
===================================================================
--- pcbsd/trunk/lifePreserver/scripts/backup-rsync.sh	2009-11-09 18:44:16 UTC (rev 4926)
+++ pcbsd/trunk/lifePreserver/scripts/backup-rsync.sh	2009-11-09 21:08:42 UTC (rev 4927)
@@ -43,7 +43,7 @@
   echo "Failed: Backup already running? PID: $PID" >${BACKLOG}
   exit 150
 else
-  echo "$$" > ${PIDFILE}
+  echo "$$" >${PIDFILE}
 fi
 
 # Make sure we have the BACKDIR created
@@ -69,18 +69,16 @@
   bzip2 ${BACKLOG}
   # Success!
   # Copy the logfile to the backup dir
-sftp ${SSHHOST} << EOF
+  sftp ${SSHHOST} << EOF
 cd ${BACKDIR}/current
 put ${BACKLOG}.bz2 backup.log.bz2
 quit
 EOF
   echo "Success: ${STARTDATE}" >${RESULTFILE}
-
 else
   # Failed backup!
   echo "Failed: ${STARTDATE}" >${RESULTFILE}
 fi
 
-
 # Remove the PID
 rm ${PIDFILE}

Modified: pcbsd/trunk/lifePreserver/scripts/functions.sh
===================================================================
--- pcbsd/trunk/lifePreserver/scripts/functions.sh	2009-11-09 18:44:16 UTC (rev 4926)
+++ pcbsd/trunk/lifePreserver/scripts/functions.sh	2009-11-09 21:08:42 UTC (rev 4927)
@@ -3,7 +3,7 @@
 check_pid()
 {
   PID="$1"
-  ps -auwwx | grep -v "grep" | grep "${PID} " >/dev/null 2>/dev/null
+  ps -p "${PID} " >/dev/null 2>/dev/null
   if [ "$?" = "0" ]
   then
     return 1


Property changes on: pcbsd/trunk/lifePreserver/scripts/kill-backup.sh
___________________________________________________________________
Added: svn:executable
   + *



More information about the Commits mailing list