Difference between revisions of "Initscripts/Writing rc.d scripts"

From ArchWiki
Jump to: navigation, search
m (Prototype: ditto)
m (Prototype: o god)
Line 27: Line 27:
 
ARGS=
 
ARGS=
  
[ -r /etc/conf.d/$DAEMON.conf ] && . /etc/conf.d/$DAEMON
+
[ -r /etc/conf.d/$DAEMON ] && . /etc/conf.d/$DAEMON
  
 
PID=$(pidof -o %PPID $DAEMON)
 
PID=$(pidof -o %PPID $DAEMON)

Revision as of 03:23, 14 January 2011

Summary help replacing me
Writing rc.d (daemon) scripts.
Related
Arch Boot Process
Daemon
rc.conf

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

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