|
Starting and stopping MisterHouse automatically
This example applies to any program or service you wish to have started every time the system boots.
This example applies to Redhat linux RH7.3 or higher. It may work with other builds.
First you need to create a script and save it in the init.d directory.
With WebMin you can use File Manager to navigate to the directory
and create a new file named "MisterHouse"
(you want the "New" button that looks like a piece of paper)
and just copy/paste the script into it.
Initialization script to be created in:
/etc/rc.d/init.d/
#!/bin/sh
#
# MisterHouse MisterHouse home automation software
#
# set runlevels 345 to 99-last for startup and 01-first for shutdown
#
# chkconfig: 345 99 01
#
# description: Start and Stop MisterHouse
#
# Source profile to get PERL5LIB
. /etc/profile
# ////////////////////////////////////////////////////////////
start()
{
echo -n "Starting MisterHouse... "
# go to default RPM misterhouse directory
cd /usr/local/mh/bin
# setting to stop memory leak problem in RH 8 and 9
export LANG=C
# start misterhouse redirecting output to null
# the final & sign tells shell to continue and not wait for output
perl mh >>/dev/null 2>&1 &
echo "Started."
# give misterhouse time to open serial port
sleep 3
echo -n "Serial Port Parameters..."
# sometimes serial port opened with default settings - which don't work, fix it
stty 4800 -icrnl -ixon -iuclc -ixany -opost -isig -icanon -iexten -echo
< /dev/ttyr00
# you MUST change ttyXX to your serial port - same as cm11
echo "set"
touch /var/lock/subsys/MisterHouse
echo "Done"
}
# ////////////////////////////////////////////////////////////
stop()
{
echo -n "Stopping MisterHouse... "
# get process id from default RPM location
read pid < /usr/local/mh/data/mh.pid
kill -TERM $pid
rm -f /var/lock/subsys/MisterHouse
echo -n "Done"
}
# ////////////////////////////////////////////////////////////
restart()
{
stop
sleep 5
start
}
# ////////////////////////////////////////////////////////////
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo "Usage: MisterHouse (start|stop|restart}"
exit 1
esac
exit $?
# ////////////////////////////////////////////////////////////
# ////////////////////////////////////////////////////////////
# ////////////////////////////////////////////////////////////
Once the file is created, set chmod to 0755. You also have to issue some commands to install and verify initialization script:
(use telnet session or VNC session on Magnia)
[root@myserver root]#
chkconfig MisterHouse --add
[root@myserver root]#
chkconfig MisterHouse on
[root@myserver root]#
for i in 1 2 3 4 5 6; do ls /etc/rc.d/rc$i.d/*ouse*; done
/etc/rc.d/rc1.d/K01MisterHouse@
/etc/rc.d/rc2.d/S99MisterHouse@
/etc/rc.d/rc3.d/S99MisterHouse@
/etc/rc.d/rc4.d/S99MisterHouse@
/etc/rc.d/rc5.d/S99MisterHouse@
/etc/rc.d/rc6.d/K01MisterHouse@
if output matches above, you're all set!
Remember: Questions
can be posted in the FORUM section !
|