Sunday, August 17, 2008

Create startup script in SMEServer

SME Server is a pre-configured Linux server designed for small to medium businesses!
It used Red Hat Enterprise Linux kernel, or CentOS kernel.

When creating packages, I wanted a script to be running when the system boot up. For example, an auto usb drive mounting script. I started with something that running in the background, and didn't work quite well. Using & straight away is not a clever way because script in init.d folder should follow certain standard, and can be managed by the boot up program manager( it might be called something else).

Firstly, you can write a normal script and wrap it as the following example:



#!/bin/sh
#
# description: usbMountWrapper is the daemon to xxxxxx
#

. /etc/rc.d/init.d/functions

function start()
{
printf "Starting %s: " "usbMountWrapper"
daemon /opt/smebackup/usbMountWrapper &
echo
touch /var/lock/subsys/usbMountWrapper
}

function stop()
{
printf "Stopping %s: " "usbMountWrapper"
killproc usbMountWrapper
echo
rm -f /var/lock/subsys/usbMountWrapper
}

function reload()
{
pid=`pidof ulogd`
if [ "x$pid" != "x" ]; then
kill -HUP $pid 2>/dev/null
fi
touch /var/lock/subsys/usbMountWrapper
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
reload)
reload
;;
status)
status usbMountWrapper
;;
*)
printf "Usage: %s {start|stop|status|restart|reload}\n" "usbMountWrapper"
exit 1
esac

exit 0




This is a much nice way of writing boot up script and you can start or stop them like this:
/etc/rc.d/init.d/usbMountWrapper start
/etc/rc.d/init.d/usbMountWrapper stop
/etc/rc.d/init.d/usbMountWrapper restart

1 comment:

Best Assignment Writing Service said...

This is a great idea! Startup scripts are very useful for automating server tasks, and can help improve the overall performance of a SMEServer. I would recommend researching the best practices for creating startup scripts, and making sure to use them in the most efficient way possible.