PFSenseDevWiki : IdeasForANewRCSystem

PfSenseDevHome :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register
Oldest known version of this page was edited on 2007-08-18 23:50:07 by ChrisBuechler []
Page view:
rc_scripts should provide the following functions (very abstract pseudo-code):


Consider this code snippet:

$rc = array();
$rc['name'] = 'Squid';
$rc['start'] = 'squid -D';
$rc['stop'] = 'squid -k shutdown';
$rc['reload'] = 'squid -k reconfigure';
$rc['status'] = "test -n '`ps ax | grep squid | grep -v grep`";
$rc['depends'] = 'foobar,foo,bar';
write_rcfile($rc);


That would generate the following rc script:

#!/bin/sh
### DEPENDS: foobar foo bar ###

rc_start() {
	    if rc_status; then; else
	            echo -n 'Starting Squid...'
	            if squid -D; then
	                    echo ' failed!'
	            else
	                    echo ' ok!'
	            fi
	    fi
}

rc_stop() {
	    if rc_status; then
		    echo -n 'Stopping Squid...'
	            if squid -k shutdown; then
	                    echo ' failed!'
	            else
	                    echo ' ok!'
	            fi
	    fi
}

rc_reload() {
	    if rc_status; then
	            echo -n 'Reloading Squid...'
	            if squid -k reconfigure; then
	                    echo ' failed!'
	            else
	                    echo ' ok!'
	            fi
	    fi
}

rc_status() {
	    return $(test -n `ps ax | grep squid | grep -v grep`)
}

case $1 in
	    start)
	            rc_start
	            ;;
	    stop)
	            rc_stop
	            ;;
	    restart)
	            rc_start
	            rc_stop
	            ;;
	    reload)
	            rc_reload
	            ;;
	    status)
	            if rc_status; then
	                    echo 'Running'
	                    exit 0
	            else
	                    echo 'Stopped'
	                    exit 1
	            fi
	            ;;
	    *)
	            echo "Usage: $0 <start|stop|restart|reload|status>"
	            exit 1
	            ;;
esac


Note that I'm not good at shell scripting, so it's very likely that my syntax is screwed. Please correct me.

Also, our scripts shouldn't use and ampersand after executing daemons. This new rc format assumes a parallel execution, dependency-based rc system.
Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by Wikka Wakka Wiki 1.1.6.3
Page was generated in 0.0488 seconds