On Solaris 10 or later using SMF is recommended, but on an earlier release you'd create an init script in /etc/init.d and link to it from the rcX.d directories. Here's a bare-bones example of an init script for launching an rsync daemon:
#!/sbin/sh
startcmd () {
/usr/local/bin/rsync --daemon # REPLACE WITH YOUR COMMANDS
}
stopcmd () {
pkill -f "/usr/local/bin/rsync --daemon" # REPLACE WITH YOUR COMMANDS
}
case "$1" in
'start')
startcmd
;;
'stop')
stopcmd
;;
'restart')
stopcmd
sleep 1
startcmd
;;
*)
echo "Usage: $0 { start | stop | restart }"
exit 1
;;
esac
Create a link to the script from each rcX.d directory (following the "S"/"K" convention).
# ln rsync /etc/rc3.d/S91rsync
# for i in `ls -1d /etc/rc*.d | grep -v 3`; do ln rsync $i/K02rsync; done
See the README in each rcX.d directory and check the man page for init.d. Here's a bit of the man page:
File names in rc?.d directories are of the form
[SK]nn<init.d filename>, where S means start this job, K
means kill this job, and nn is the relative sequence number
for killing or starting the job.
When entering a state (init S,0,2,3,etc.) the rc[S0-6]
script executes those scripts in /etc/rc[S0-6].d that are
prefixed with K followed by those scripts prefixed with S.
When executing each script in one of the /etc/rc[S0-6]
directories, the /sbin/rc[S0-6] script passes a single argu-
ment. It passes the argument 'stop' for scripts prefixed
with K and the argument 'start' for scripts prefixed with S.
There is no harm in applying the same sequence number to
multiple scripts.