Wiki source for IdeasForANewRCSystem


Show raw source

rc_scripts should provide the following functions (very abstract pseudo-code):

- rc_start => running ? nothing : start
- rc_stop => running ? stop : nothing
- rc_restart => running ? stop : nothing; start
- rc_reload => running ? reload : start
- rc_status => running ? true : false

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 :: Valid CSS: :: Powered by WikkaWiki