Initscripts/Writing rc.d scripts
Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary end
As part of Arch's 'BSD-style' init, rc.d scripts are used to control the starting,stopping and restarting of daemons. This guide will help to create your own rc.d scripts.
Guideline
- Source Template:Filename, Template:Filename, and optionally Template:Filename.
- Arguments and other daemon options should be placed in Template:Filename. This is done to separate configuration from logic and to keep a consistent style among daemon scripts.
- Use functions in Template:Filename.
- Include at least start, stop and restart.
Prototype
#!/bin/bash . /etc/rc.conf . /etc/rc.d/functions DAEMON=DAEMON_NAME ARGS= [ -r /etc/conf.d/$DAEMON ] && . /etc/conf.d/$DAEMON PID=$(pidof -o %PPID $DAEMON) case "$1" in start) stat_busy "Starting $DAEMON daemon" [ -z "$PID" ] && $DAEMON $ARGS &>/dev/null if [ $? = 0 ]; then add_daemon $DAEMON stat_done else stat_fail exit 1 fi ;; stop) stat_busy "Stopping $DAEMON daemon" [ -n "$PID" ] && kill $PID &>/dev/null if [ $? = 0 ]; then rm_daemon $DAEMON stat_done else stat_fail exit 1 fi ;; restart) $0 stop sleep 1 $0 start ;; status) stat_busy "Checking $DAEMON status" ck_status $DAEMON ;; *) echo "usage: $0 {start|stop|restart|status}" esac
Example
The following is an example for tftpd. Look in Template:Filename for a greater variety.
The configuration file: Template:File
The actual script: Template:File