Added process shutdown script to takedown running processes and unmount drive before rtcwake is called
authoraidan@aidan-laptop
Thu, 20 May 2010 12:44:10 +0100
changeset 9 a90bd3d08b1a
parent 8 21caff1fea03
child 10 897c49383d46
Added process shutdown script to takedown running processes and unmount drive before rtcwake is called
installpbm
pbmd
pbmd.c
sleeprtc.sh
stbylong.sh
stbyshort.sh
stopproc.sh
--- a/installpbm	Wed May 19 17:34:21 2010 +0100
+++ b/installpbm	Thu May 20 12:44:10 2010 +0100
@@ -1,5 +1,11 @@
 #!/bin/sh
 
+cp ./stopproc.sh /etc
+chmod +x          /etc/stopproc.sh
+chown root        /etc/stopproc.sh
+chgrp root        /etc/stopproc.sh
+echo "Copied stopproc.sh to /etc ..."
+
 cp ./stbyshort.sh /etc
 chmod +x          /etc/stbyshort.sh
 chown root        /etc/stbyshort.sh
Binary file pbmd has changed
--- a/pbmd.c	Wed May 19 17:34:21 2010 +0100
+++ b/pbmd.c	Thu May 20 12:44:10 2010 +0100
@@ -28,7 +28,8 @@
 
 int main(int argc, char* argv[])
 {           
-    char *progName;      
+    char *progName = strrchr( argv[0], '/' ) + 1; // extract program name from file path
+    printf("the prog name is: %s\n", progName);
     FILE *logFile;
     char *snapFileName;
     char *bootFileName;
@@ -42,12 +43,11 @@
 
     redirectOutput();
     
-    openlog( argv[0], LOG_CONS, LOG_USER );
+    openlog( progName, LOG_CONS, LOG_USER );
     
     validateArgs( argc, argv );       
     
-    // extract args
-    progName = strrchr( argv[0], '/' ); // Arg 0 is program name
+    // extract args    
     logFile = fopen( argv[1], "a" );    // Open log file
     snapFileName = argv[2];             // Arg 2 is snapshot file
     bootFileName = argv[3];             // Arg 3 is boot flag file
--- a/sleeprtc.sh	Wed May 19 17:34:21 2010 +0100
+++ b/sleeprtc.sh	Thu May 20 12:44:10 2010 +0100
@@ -1,27 +1,27 @@
 #!/bin/bash
 # Expects 1 argument - time to wakeup in the format HH:MM
-
+#
 echo "sleeprtc: Executing at `date -R`" >> /var/log/logrtc.log
-
+#
 hourtowake=$1
-
+#
 if [ "$1" == "" ]
 then
     hourtowake="06:00"
 fi
-
+#
 timenow=`date +"%H:%M"`
-
+#
 if [ $timenow \> "22:00" ]
 then
     timetowake=`date -d "tomorrow $hourtowake" + "%s"`
 else
     timetowake=`date -d "$hourtowake" + "%s"`
 fi
-
-echo $timetowake
-
-
+#
+# stop running processes
+/etc/stopproc.sh
+#
 echo "sleeprtc: Scheduling wake for local time `date -d @$timetowake`" >> /var/log/logrtc.log
 
 /usr/sbin/vbetool vbestate save > /tmp/videostate
--- a/stbylong.sh	Wed May 19 17:34:21 2010 +0100
+++ b/stbylong.sh	Thu May 20 12:44:10 2010 +0100
@@ -1,9 +1,12 @@
 #!/bin/bash
 #
-# stby180.sh
+# stbylong.sh
 #
 BOOTFLAGFILE=/etc/bootflag
 #
+# stop running processes
+/etc/stopproc.sh
+#
 echo "stbylong: Going asleep at `date`" >> /var/log/logrtc.log
 #
 #sleep for 3hours (60*60*3 = 10800)
--- a/stbyshort.sh	Wed May 19 17:34:21 2010 +0100
+++ b/stbyshort.sh	Thu May 20 12:44:10 2010 +0100
@@ -1,9 +1,12 @@
 #!/bin/bash
 #
-# stby30.sh
+# stbyshort.sh
 #
 BOOTFLAGFILE=/etc/bootflag
 #
+# stop running processes
+/etc/stopproc.sh
+#
 echo "stbyshort: Going asleep at `date`" >> /var/log/logrtc.log
 #
 #sleep for 30min (60*30 = 1800)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stopproc.sh	Thu May 20 12:44:10 2010 +0100
@@ -0,0 +1,20 @@
+#!/bin/bash
+#
+# stopproc.sh
+#
+PATH=/etc/init.d/
+#
+echo "stopproc: taking down processes at `date`" >> /var/log/logrtc.log
+#
+$PATH/monit stop
+$PATH/dtnN4Cmiddle stop
+$PATH/dtnN4Crecv stop
+$PATH/dtn stop
+$PATH/apache2 stop
+$PATH/cron stop
+$PATH/dhcp3-server stop
+$PATH/mysql stop
+$PATH/pbm stop
+
+echo "stopproc: unmounting /data" >> /var/log/logrtc.log
+/bin/umount /data