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

From ArchWiki
Jump to: navigation, search
m (Prototype: o god)
(content isn't different enough to be beneficial)
Line 16: Line 16:
 
*Use functions in {{Filename|/etc/rc.d/functions}}.
 
*Use functions in {{Filename|/etc/rc.d/functions}}.
 
*Include at least start, stop and restart.
 
*Include at least start, stop and restart.
 
==Prototype==
 
<pre>
 
#!/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
 
</pre>
 
  
 
==Example==
 
==Example==
The following is an example for ''tftpd''. Look in {{Filename|/etc/rc.d}} for a greater variety.
+
The following is an example for ''crond''. Look in {{Filename|/etc/rc.d}} for a greater variety.
  
 
The configuration file:
 
The configuration file:
{{File|name=/etc/conf.d/tftpd|content=<nowiki>ARGS="-l -s /var/tftpboot -c"</nowiki>}}
+
{{File|name=/etc/conf.d/tftpd|content=<nowiki>ARGS="-S -l info"</nowiki>}}
  
 
The actual script:
 
The actual script:
Line 81: Line 30:
 
. /etc/rc.d/functions
 
. /etc/rc.d/functions
  
DAEMON=tftpd
+
DAEMON=crond
 
ARGS=
 
ARGS=
  
 
[ -r /etc/conf.d/$DAEMON ] && . /etc/conf.d/$DAEMON
 
[ -r /etc/conf.d/$DAEMON ] && . /etc/conf.d/$DAEMON
  
PID=$(pidof -o %PPID in.tftpd)
+
PID=$(pidof -o %PPID $DAEMON)
  
 
case "$1" in
 
case "$1" in
 
  start)
 
  start)
 
   stat_busy "Starting $DAEMON"
 
   stat_busy "Starting $DAEMON"
   [ -z "$PID" ] && in.tftpd $ARGS &>/dev/null
+
   [ -z "$PID" ] && $DAEMON $ARGS &>/dev/null
 
   if [ $? = 0 ]; then
 
   if [ $? = 0 ]; then
 
     add_daemon $DAEMON
 
     add_daemon $DAEMON

Revision as of 03:34, 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

Example

The following is an example for crond. Look in Template:Filename for a greater variety.

The configuration file: Template:File

The actual script: Template:File