diff options
author | Nicolás Reynolds <fauno@kiwwwi.com.ar> | 2011-10-30 01:40:41 -0300 |
---|---|---|
committer | Nicolás Reynolds <fauno@kiwwwi.com.ar> | 2011-10-30 01:40:41 -0300 |
commit | c3d6cdb72f7130d3361bc1b8c99e862fe15a75fa (patch) | |
tree | b664bed188c0de713be8a4649fdd86664d1c2867 | |
parent | ede246d73091a7b733ae56819fc7296e18aa4c31 (diff) | |
parent | 00070eca730dec9c6d587cc1639f6abaca83fa34 (diff) |
Merge branch 'master' of git://projects.archlinux.org/initscripts2011.10.3
Conflicts:
PKGBUILD
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | Makefile | 21 | ||||
-rw-r--r-- | PKGBUILD | 8 | ||||
-rwxr-xr-x | arch-sysctl | 29 | ||||
-rw-r--r-- | bash-completion | 20 | ||||
-rw-r--r-- | functions | 92 | ||||
-rwxr-xr-x | hwclock | 6 | ||||
-rw-r--r-- | locale.sh | 80 | ||||
-rw-r--r-- | minilogd.c | 202 | ||||
-rw-r--r-- | rc.conf | 10 | ||||
-rwxr-xr-x | rc.d | 124 | ||||
-rw-r--r-- | rc.d.8.txt | 103 | ||||
-rwxr-xr-x | rc.multi | 4 | ||||
-rwxr-xr-x | rc.shutdown | 24 | ||||
-rwxr-xr-x | rc.sysinit | 20 | ||||
-rw-r--r-- | zsh-completion | 8 |
16 files changed, 434 insertions, 319 deletions
@@ -1,5 +1,3 @@ -minilogd -minilogd.o tags *.tar.xz* pkg/ @@ -8,30 +8,39 @@ DIRS := \ /usr/sbin \ /etc/tmpfiles.d \ /usr/lib/tmpfiles.d \ + /etc/sysctl.d \ + /usr/lib/sysctl.d \ /usr/lib/initscripts \ /etc/bash_completion.d \ - /usr/share/zsh/site-functions + /usr/share/zsh/site-functions \ + /usr/share/man/man8 -minilogd: minilogd.o +all: doc installdirs: install -dm755 $(foreach DIR, $(DIRS), $(DESTDIR)$(DIR)) -install: minilogd installdirs +install: installdirs doc install -m644 -t $(DESTDIR)/etc inittab rc.conf install -m755 -t $(DESTDIR)/etc rc.local rc.local.shutdown rc.multi rc.shutdown rc.single rc.sysinit install -m644 -t $(DESTDIR)/etc/logrotate.d bootlog install -m644 -t $(DESTDIR)/etc/rc.d functions install -m755 -t $(DESTDIR)/etc/rc.d hwclock network netfs install -m755 -t $(DESTDIR)/etc/profile.d locale.sh - install -m755 -t $(DESTDIR)/usr/sbin minilogd rc.d - install -m755 -t $(DESTDIR)/usr/lib/initscripts arch-tmpfiles + install -m755 -t $(DESTDIR)/usr/sbin rc.d + install -m644 -t ${DESTDIR}/usr/share/man/man8 rc.d.8 + install -m755 -t $(DESTDIR)/usr/lib/initscripts arch-tmpfiles arch-sysctl install -m644 tmpfiles.conf $(DESTDIR)/usr/lib/tmpfiles.d/arch.conf install -m644 -T bash-completion $(DESTDIR)/etc/bash_completion.d/rc.d install -m644 -T zsh-completion $(DESTDIR)/usr/share/zsh/site-functions/_rc.d +rc.d.8: rc.d.8.txt + a2x -d manpage -f manpage rc.d.8.txt + +doc: rc.d.8 + clean: - rm -f minilogd minilogd.o + rm -f rc.d.8 release: git archive HEAD --prefix=initscripts-$(VER)/ | xz > initscripts-$(VER).tar.xz @@ -2,19 +2,21 @@ pkgname=initscripts-git pkgver=$(date +%s) pkgrel=$(git log -1 --pretty=format:%h) pkgdesc="System initialization/bootup scripts" -arch=('i686' 'x86_64') +arch=('any') url="http://parabolagnulinux.org" -license=('GPL2') +license=('GPL') groups=('base') conflicts=('initscripts') provides=('initscripts=9999') backup=(etc/inittab etc/rc.conf etc/rc.local etc/rc.local.shutdown) -depends=('glibc' 'bash' 'grep' 'coreutils' 'udev>=139-1' 'iproute2' +makedepends=('asciidoc') +depends=('glibc' 'bash' 'grep' 'coreutils' 'udev>=174' 'iproute2' 'ncurses' 'kbd' 'findutils' 'sysvinit') optdepends=('net-tools: legacy networking support' 'bridge-utils: Network bridging support' 'dhcpcd: DHCP network configuration' 'wireless_tools: Wireless networking') +makedepends=(asciidoc) source=() sha256sums=() diff --git a/arch-sysctl b/arch-sysctl new file mode 100755 index 0000000..4856df6 --- /dev/null +++ b/arch-sysctl @@ -0,0 +1,29 @@ +#!/bin/bash +# +# /usr/lib/initscripts/arch-sysctl +# +# Load sysctl configuration files following +# http://0pointer.de/public/systemd-man/sysctl.d.html +# + +shopt -s nullglob + +declare -a sysctl_d=( + /usr/lib/sysctl.d/*.conf + /etc/sysctl.d/*.conf + /run/sysctl.d/*.conf + /etc/sysctl.conf +) +declare -A fragments + +# files declared later in the sysctl_d array will override earlier +# Example: `/etc/sysctl.d/foo.conf' supersedes `/usr/lib/sysctl.d/foo.conf'. +for path in "${sysctl_d[@]}"; do + [[ -f $path ]] && fragments[${path##*/}]=$path +done + +for path in "${fragments[@]}"; do + sysctl -q -p "$path" +done + +# vim: set ts=2 sw=2 noet: diff --git a/bash-completion b/bash-completion index d78484e..4b4593b 100644 --- a/bash-completion +++ b/bash-completion @@ -3,20 +3,20 @@ _rc_d() { local action cur prev - action="help list start stop reload restart" + actions='help list start stop reload restart' + options='-s --started -S --stopped -a --auto -A --noauto' _get_comp_words_by_ref cur prev - if ((COMP_CWORD == 1)); then - COMPREPLY=($(compgen -W "${action}" -- "$cur")) - elif [[ "$prev" == help ]]; then + _get_first_arg + if [[ -z "$arg" ]]; then + COMPREPLY=($(compgen -W "${actions} ${options}" -- "$cur")) + elif [[ "$arg" == help ]]; then COMPREPLY=() - elif [[ "$prev" == list ]]; then - ((COMP_CWORD == 2)) && COMPREPLY=($(compgen -W "started stopped" -- "$cur")) || COMPREPLY=() - elif [[ "$prev" == start ]]; then + elif [[ "$arg" == start ]]; then COMPREPLY=($(comm -23 <(cd /etc/rc.d && compgen -f -X 'functions*' "$cur"|sort) <(cd /run/daemons/ && compgen -f "$cur"|sort))) - elif [[ "$prev" =~ stop|restart|reload ]]; then + elif [[ "$arg" =~ stop|restart|reload ]]; then COMPREPLY=($(cd /run/daemons/ && compgen -f "$cur"|sort)) - elif ((COMP_CWORD > 1)); then - COMPREPLY=($(cd /etc/rc.d && compgen -f -X 'functions*' "$cur"|sort)) + else + COMPREPLY=($(compgen -W "${options} $(cd /etc/rc.d && compgen -f -X 'functions*')" -- "$cur")) fi } complete -F _rc_d rc.d @@ -67,8 +67,14 @@ unset TZ unset LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY \ LC_MESSAGES LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE \ LC_MEASUREMENT LC_IDENTIFICATION LC_ALL -if [[ $DAEMON_LOCALE = [yY][eE][sS] && $LOCALE ]]; then - export LANG="${LOCALE}" +if [[ $DAEMON_LOCALE = [yY][eE][sS] ]]; then + LANG="${LOCALE:=C}" + if [ -r /etc/locale.conf ]; then + . /etc/locale.conf + fi + export LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY \ + LC_MESSAGES LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE \ + LC_MEASUREMENT LC_IDENTIFICATION LC_ALL else export LANG=C fi @@ -218,7 +224,7 @@ ck_depends() { start_daemon_bkgd() { stat_bkgd "Starting $1" - have_daemon "$1" && (start_daemon "$1") &>/dev/null & + (start_daemon "$1") >/dev/null & } stop_daemon() { @@ -284,35 +290,49 @@ stop_all_daemons() { done } -kill_all() { - # Terminate all processes - # and wait until killall5 reports all done or timeout +# $1 - signal +# $2 - iterations +kill_all_wait() { + # Send SIGTERM/SIGKILL all processes and wait until killall5 + # reports all done or timeout. # Unfortunately killall5 does not support the 0 signal, so just # use SIGCONT for checking (which should be ignored). - stat_busy "Sending SIGTERM To Processes" - local i - killall5 -15 ${omit_pids[@]/#/-o } &>/dev/null - for (( i=0; i<20 && $?!=2; i++ )); do - sleep .25 # 1/4 second - killall5 -18 ${omit_pids[@]/#/-o } &>/dev/null - done - stat_done - stat_busy "Sending SIGKILL To Processes" - local i - killall5 -9 ${omit_pids[@]/#/-o } &>/dev/null - for (( i=0; i<4 && $?!=2; i++ )); do - sleep .25 # 1/4 second - killall5 -18 ${omit_pids[@]/#/-o } &>/dev/null - done - stat_done + local i + + killall5 -${1} ${omit_pids[@]/#/-o } &>/dev/null + + for (( i=0; i<${2}; i++ )); do + + sleep .25 # 1/4 second + + # sending SIGCONT to processes to check if they are there + killall5 -18 ${omit_pids[@]/#/-o } &>/dev/null + + if (( $? == 2 )); then + return 0 + fi + done + + return 1 +} + +kill_all() { + stat_busy "Sending SIGTERM To Processes" + kill_all_wait 15 40 + if (( $? == 0 )); then + stat_done + else + stat_fail + status "Sending SIGKILL To Processes" kill_all_wait 9 60 + fi } # Start/trigger UDev, load MODULES and settle UDev udevd_modprobe() { # $1 = where we are being called from. # This is used to determine which hooks to run. - status "Starting UDev Daemon" udevd --daemon + status "Starting UDev Daemon" /lib/udev/udevd --daemon run_hook "$1_udevlaunched" @@ -323,7 +343,7 @@ udevd_modprobe() { # Load modules from the MODULES array defined in rc.conf [[ -f /proc/modules ]] && (( ${#MODULES[*]} )) && - status "Loading Modules" modprobe -ab "${MODULES[@]}" + status "Loading User-specified Modules" modprobe -ab "${MODULES[@]}" status "Waiting for UDev uevents to be processed" \ udevadm settle --timeout=${UDEV_TIMEOUT:-30} @@ -369,6 +389,28 @@ read_crypttab() { return $failed } +set_timezone() { + local tz=$1 zonefile=/usr/share/zoneinfo/$tz + + [[ $tz ]] || return 1 + + if [[ ! -e $zonefile ]]; then + printf "error: \`%s' is not a valid timezone\n" "$tz" + return 1 + fi + + if [[ -L /etc/localtime && /etc/localtime -ef $zonefile ]]; then + return 0 + fi + + # respect the user's decision to symlink or copy + if [[ -L /etc/localtime ]]; then + ln -sf "/usr/share/zoneinfo/$tz" /etc/localtime + else + cp --remove-destination "/usr/share/zoneinfo/$tz" /etc/localtime + fi +} + # Filesystem functions # These can be overridden/reused for customizations like shutdown/loop-fsck. NETFS="nfs,nfs4,smbfs,cifs,codafs,ncpfs,shfs,fuse,fuseblk,glusterfs,davfs,fuse.glusterfs" @@ -435,7 +477,7 @@ bootlogd_stop() { kill $(< /run/bootlogd.pid) rm -f /run/bootlogd.pid sed -i -r -e 's/\^\[\[[0-9]?;?[0-9]?[0-9]?;?[0-9]?[0-9]?[ms]//g' \ - -e 's/\^\[(\[1[0-9]1|%)G//g' -e 's/\^\[\[0;1//g' /var/log/boot + -e 's/\^\[(\[1?[0-9]1|%)G//g' -e 's/\^\[\[0;1//g' /var/log/boot } ############################### @@ -13,11 +13,7 @@ case "$1" in start) add_daemon hwclock;; stop) - case $HARDWARECLOCK in - UTC) hwclock --adjust --utc;; - localtime) hwclock --adjust --localtime;; - "") hwclock --adjust;; - esac + hwclock --adjust $HWCLOCK_PARAMS rm_daemon hwclock ;; restart) @@ -1,3 +1,79 @@ -. /etc/rc.conf +if [ -s /etc/locale.conf ]; then + . /etc/locale.conf +fi -export LANG=${LOCALE:=en_US} +if [ -n "$LANG" ]; then + export LANG +else + if [ -s /etc/rc.conf ]; then + export LANG=$(. /etc/rc.conf 2> /dev/null ; echo "$LOCALE") + else + export LANG="C" + fi +fi + +if [ -n "$LC_CTYPE" ]; then + export LC_CTYPE +else + unset LC_CTYPE +fi + +if [ -n "$LC_NUMERIC" ]; then + export LC_NUMERIC +else + unset LC_NUMERIC +fi + +if [ -n "$LC_TIME" ]; then + export LC_TIME +else + unset LC_TIME +fi + +if [ -n "$LC_COLLATE" ]; then + export LC_COLLATE +else + unset LC_COLLATE +fi + +if [ -n "$LC_MONETARY" ]; then + export LC_MONETARY +else + unset LC_MONETARY +fi + +if [ -n "$LC_MESSAGES" ]; then + export LC_MESSAGES +else + unset LC_MESSAGES +fi + +if [ -n "$LC_PAPER" ]; then + export LC_PAPER +else + unset LC_PAPER +fi + +if [ -n "$LC_NAME" ]; then + export LC_NAME +else + unset LC_NAME +fi + +if [ -n "$LC_ADDRESS" ]; then + export LC_ADDRESS +else + unset LC_ADDRESS +fi + +if [ -n "$LC_TELEPHONE" ]; then + export LC_MEASUREMENT +else + unset LC_MEASUREMENT +fi + +if [ -n "$LC_IDENTIFICATION" ]; then + export LC_IDENTIFICATION +else + unset LC_IDENTIFICATION +fi diff --git a/minilogd.c b/minilogd.c deleted file mode 100644 index c86ab23..0000000 --- a/minilogd.c +++ /dev/null @@ -1,202 +0,0 @@ -/* minilogd.c - * - * A pale imitation of syslogd. Most notably, doesn't write anything - * anywhere except possibly back to syslogd. - * - */ - -#include <errno.h> -#include <fcntl.h> -#include <signal.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <strings.h> -#include <stdarg.h> -#include <syslog.h> -#ifndef __USE_BSD -# define __USE_BSD -#endif -#include <unistd.h> - -#include <sys/poll.h> -#include <sys/socket.h> -#include <sys/stat.h> -#include <sys/un.h> - -#define MAX_BUF_LINES 10000 -#define BUF_LINE_SIZE 8192 - -static int we_own_log=0; -static char **buffer=NULL; -static int buflines=0; - -int debug; - -int recvsock; - -void alarm_handler(int x) { - alarm(0); - close(recvsock); - recvsock = -1; -} - -void freeBuffer() { - struct sockaddr_un addr; - int sock; - int x=0,conn; - - memset(&addr, 0, sizeof(addr)); - addr.sun_family = AF_LOCAL; - strncpy(addr.sun_path,_PATH_LOG,sizeof(addr.sun_path)-1); - /* wait for klogd to hit syslog */ - sleep(2); - sock = socket(AF_LOCAL, SOCK_STREAM,0); - conn=connect(sock,(struct sockaddr *) &addr,(socklen_t)sizeof(addr)); - while (x<buflines) { - if (!conn) { - /*printf("to syslog: %s\n", buffer[x]);*/ - write(sock,buffer[x],strlen(buffer[x])+1); - } - free(buffer[x]); - x++; - } - free(buffer); -} - -void cleanup(int exitcode) { - /* If we own the log, unlink it before trying to free our buffer. - * Otherwise, sending the buffer to /dev/log doesn't make much sense.... */ - if (we_own_log) { - perror("wol"); - unlink(_PATH_LOG); - } - /* Don't try to free buffer if we were called from a signal handler */ - if (exitcode<=0) { - if (buffer) - freeBuffer(); - exit(exitcode); - } else - exit(exitcode+128); -} - -void runDaemon(int sock) { - struct sockaddr_un addr; - int x,done=0; - ssize_t len; - socklen_t addrlen = (socklen_t)sizeof(struct sockaddr_un); - char *message = NULL; - struct stat s1,s2; - struct pollfd pfds; - - daemon(0,-1); - /* try not to leave stale sockets lying around */ - /* Hopefully, we won't actually get any of these */ - signal(SIGHUP,cleanup); - signal(SIGINT,cleanup); - signal(SIGQUIT,cleanup); - signal(SIGILL,cleanup); - signal(SIGABRT,cleanup); - signal(SIGFPE,cleanup); - signal(SIGSEGV,cleanup); - signal(SIGPIPE,cleanup); - signal(SIGBUS,cleanup); - signal(SIGTERM,cleanup); - done = 0; - /* Get stat info on /dev/log so we can later check to make sure we - * still own it... */ - if (stat(_PATH_LOG,&s1) != 0) - memset(&s1, 0, sizeof(struct stat)); - while (!done) { - pfds.fd = sock; - pfds.events = POLLIN|POLLPRI; - pfds.revents = 0; - if ( ( (x=poll(&pfds,1,500))==-1) && errno !=EINTR) { - perror("poll"); - cleanup(-1); - } - if ( (x>0) && (pfds.revents & (POLLIN | POLLPRI))) { - if (message == NULL) { - message = calloc(BUF_LINE_SIZE,sizeof(char)); - } - recvsock = accept(sock,(struct sockaddr *) &addr, &addrlen); - alarm(2); - signal(SIGALRM, alarm_handler); - len = read(recvsock,message,BUF_LINE_SIZE); - alarm(0); - close(recvsock); - if (len>0) { - /*printf("line recv'd: %s\n", message);*/ - if (buflines < MAX_BUF_LINES) { - if (buffer) - buffer = realloc(buffer,(buflines+1)*sizeof(char *)); - else - buffer = malloc(sizeof(char *)); - message[strlen(message)]='\n'; - buffer[buflines]=message; - message = NULL; - buflines++; - } - } - else { - recvsock=-1; - } - } - if ( (x>0) && ( pfds.revents & (POLLHUP | POLLNVAL)) ) - done = 1; - /* Check to see if syslogd's yanked our socket out from under us */ - if ( (stat(_PATH_LOG,&s2)!=0) || - (s1.st_ino != s2.st_ino ) || (s1.st_ctime != s2.st_ctime) || - (s1.st_mtime != s2.st_mtime) ) { /*|| (s1.st_atime != s2.st_atime) ) {*/ - done = 1; - we_own_log = 0; - /*printf("someone stole our %s\n", _PATH_LOG); - printf("st_ino: %d %d\n", s1.st_ino, s2.st_ino); - printf("st_ctime: %d %d\n", s1.st_ctime, s2.st_ctime); - printf("st_atime: %d %d\n", s1.st_atime, s2.st_atime); - printf("st_mtime: %d %d\n", s1.st_mtime, s2.st_mtime);*/ - } - } - free(message); - cleanup(0); -} - -int main(int argc, char **argv) { - struct sockaddr_un addr; - int sock; - int pid; - - /* option processing made simple... */ - if (argc>1) debug=1; - /* just in case */ - sock = open("/dev/null",O_RDWR); - dup2(sock,0); - dup2(sock,1); - dup2(sock,2); - - memset(&addr, 0, sizeof(addr)); - addr.sun_family = AF_LOCAL; - strncpy(addr.sun_path,_PATH_LOG,sizeof(addr.sun_path)-1); - sock = socket(AF_LOCAL, SOCK_STREAM,0); - unlink(_PATH_LOG); - /* Bind socket before forking, so we know if the server started */ - if (!bind(sock,(struct sockaddr *) &addr, (socklen_t)sizeof(addr))) { - we_own_log = 1; - listen(sock,5); - if ((pid=fork())==-1) { - perror("fork"); - exit(3); - } - if (pid) { - exit(0); - } else { - /*printf("starting daemon...\n");*/ - runDaemon(sock); - /* shouldn't get back here... */ - exit(4); - } - } else { - exit(5); - } -} -/* vim: set ts=2 noet: */ @@ -7,6 +7,7 @@ # ----------------------------------------------------------------------- # # LOCALE: available languages can be listed with the 'locale -a' command +# LANG in /etc/locale.conf takes precedence # DAEMON_LOCALE: If set to 'yes', use $LOCALE as the locale during daemon # startup and during the boot process. If set to 'no', the C locale is used. # HARDWARECLOCK: set to "", "UTC" or "localtime", any other value will result @@ -113,7 +114,10 @@ NETWORK_PERSIST="no" # - prefix a daemon with a ! to disable it # - prefix a daemon with a @ to start it up in the background # -# If something other takes care of your hardware clock (ntpd, dual-boot...) -# you should disable 'hwclock' here. +# If you are sure nothing else touches your hardware clock (such as ntpd or +# a dual-boot), you might want to enable 'hwclock'. Note that this will only +# make a difference if the hwclock program has been calibrated correctly. # -DAEMONS=(hwclock syslog-ng network netfs crond) +# If you use a network filesystem you should enable 'netfs'. +# +DAEMONS=(syslog-ng network crond) @@ -4,74 +4,128 @@ NEED_ROOT=0 # this script can be run without be root . /etc/rc.conf . /etc/rc.d/functions +# print usage and exit usage() { local name=${0##*/} cat >&2 << EOF -usage: $name <action> <daemon> [daemon] ... - $name list [started|stopped] - $name help +usage: $name <action> [options] [daemons] -<daemon> is the name of a script in /etc/rc.d +options: + -s, --started Filter started daemons + -S, --stopped Filter stopped daemons + -a, --auto Filter auto started daemons + -A, --noauto Filter manually started daemons + +<daemons> is a space separated list of script in /etc/rc.d <action> can be a start, stop, restart, reload, status, ... WARNING: initscripts are free to implement or not the above actions. e.g: $name list - $name list started - $name help + $name list sshd gpm + $name list --started gpm $name start sshd gpm + $name stop --noauto + $name help EOF - exit 1 + exit ${1:-1} +} + +# filter list of daemons +filter_daemons() { + local -a new_daemons=() + for daemon in "${daemons[@]}"; do + # check if daemons is valid + if ! have_daemon "$daemon"; then + printf "${C_FAIL}:: ${C_DONE}Dameon script ${C_FAIL}${daemon}${C_DONE} does \ +not exist or is not executable.${C_CLEAR}\n" >&2 + exit 2 + fi + # check filter + ((${filter[started]} == 1)) && ck_daemon "$daemon" && continue + ((${filter[stopped]} == 1)) && ! ck_daemon "$daemon" && continue + ((${filter[auto]} == 1)) && ck_autostart "$daemon" && continue + ((${filter[noauto]} == 1)) && ! ck_autostart "$daemon" && continue + new_daemons+=("$daemon") + done + daemons=("${new_daemons[@]}") } (( $# < 1 )) && usage +# ret store the return code of rc.d declare -i ret=0 -case $1 in +# daemons store daemons on which action will be executed +declare -a daemons=() +# filter store current filter mode +declare -A filter=([started]=0 [stopped]=0 [auto]=0 [noauto]=0) + +# parse options +argv=$(getopt -l 'started,stopped,auto,noauto' -- 'sSaA' "$@") || usage +eval set -- "$argv" + +# create an initial daemon list +while [[ "$1" != -- ]]; do + case "$1" in + -s|--started) filter[started]=1 ;; + -S|--stopped) filter[stopped]=1 ;; + -a|--auto) filter[auto]=1 ;; + -A|--noauto) filter[noauto]=1 ;; + esac + shift +done + +# remove -- +shift +# get action +action=$1 +shift + +# get initial daemons list +for daemon; do + daemons+=("$daemon") +done + +# going into script directory +cd /etc/rc.d + +case $action in help) - usage - ;; + usage 0 2>&1 + ;; list) - shift - cd /etc/rc.d/ - for d in *; do - have_daemon "$d" || continue + # list take all daemons by default + [[ -z $daemons ]] && for d in *; do have_daemon "$d" && daemons+=("$d"); done + filter_daemons + for daemon in "${daemons[@]}"; do # print running / stopped satus - if ! ck_daemon "$d"; then - [[ "$1" == stopped ]] && continue - printf "${C_OTHER}[${C_DONE}STARTED${C_OTHER}]" + if ! ck_daemon "$daemon"; then + s_status="${C_OTHER}[${C_DONE}STARTED${C_OTHER}]" else - [[ "$1" == started ]] && continue - printf "${C_OTHER}[${C_FAIL}STOPPED${C_OTHER}]" + s_status="${C_OTHER}[${C_FAIL}STOPPED${C_OTHER}]" fi # print auto / manual status - if ! ck_autostart "$d"; then - printf "${C_OTHER}[${C_DONE}AUTO${C_OTHER}]" + if ! ck_autostart "$daemon"; then + s_auto="${C_OTHER}[${C_DONE}AUTO${C_OTHER}]" else - printf "${C_OTHER}[${C_FAIL} ${C_OTHER}]" + s_auto="${C_OTHER}[${C_FAIL} ${C_OTHER}]" fi - printf " ${C_CLEAR}$d\n" + printf "$s_status$s_auto${C_CLEAR} $daemon\n" done ;; *) - # check min args count - (( $# < 2 )) && usage - action=$1 - shift + # other actions need an explicit daemons list + [[ -z $daemons ]] && usage + filter_daemons # set same environment variables as init runlevel=$(/sbin/runlevel) - ENV=("PATH=/bin:/usr/bin:/sbin:/usr/sbin" + ENV=('PATH=/bin:/usr/bin:/sbin:/usr/sbin' "PREVLEVEL=${runlevel%% *}" "RUNLEVEL=${runlevel##* }" "CONSOLE=${CONSOLE:-/dev/console}" "TERM=$TERM") cd / - for i; do - if [[ -x "/etc/rc.d/$i" ]]; then - env -i "${ENV[@]}" "/etc/rc.d/$i" "$action" - else - printf "${C_OTHER}:: ${C_FAIL}Error: ${C_DONE}Daemon script \`%s' does not exist or is not executable.${C_CLEAR}\n" \ - "$i" - fi + for daemon in "${daemons[@]}"; do + env -i "${ENV[@]}" "/etc/rc.d/$daemon" "$action" (( ret += !! $? )) # clamp exit value to 0/1 done ;; diff --git a/rc.d.8.txt b/rc.d.8.txt new file mode 100644 index 0000000..d0bbcce --- /dev/null +++ b/rc.d.8.txt @@ -0,0 +1,103 @@ +///// +vim:set ts=4 sw=4 syntax=asciidoc noet: +///// +rc.d(8) +======= + +Name +---- +rc.d - Initscripts power tool + +Synopsis +-------- +*rc.d <action> [options] [rc [rc] ...]* + +Description +----------- +The *rc.d* program controls and lists rc scripts on the system. An action may be +invoked on one or more scripts using *rc.d action rc1 rc2...*. See <<A,Actions>> +below for more information. +Use *rc.d list* to get the list of all rc scripts on the system. + +Actions[[A]] +------------ +The actions supported by a rc scripts may be different from script to script, but +commonly supported actions include: + +*start*:: + Starts the script if it's not already running. + +*stop*:: + Stops a running script. + +*restart*:: + Restarts a running script. + +More uncommon actions are: + +*reload*:: + Signals the script to reload its configuration. + +*status*:: + Shows the status of the script. + +Options[[O]] +------------ +*-s, --started*:: + Filter to started scripts. + +*-S, --stopped*:: + Filter to stopped scripts. + +*-a, --auto*:: + Filter to auto started scripts. + +*-A, --noauto*:: + Filter to manually started scripts. + +Examples[[E]] +------------- +*rc.d list*:: + List all scripts. + +*rc.d list sshd gpm*:: + List only *sshd* and *gpm* scripts. + +*rc.d list --started gpm*:: + List *gpm* script only if started. + +*rc.d list --started --auto*:: + List all auto started scripts. + +*rc.d start sshd gpm*:: + Starts *sshd* and *gpm* scripts. + +*rc.d start --auto --stopped*:: + Starts all stopped scripts which are started at startup. + +*rc.d stop crond*:: + Stops the *crond* script. + +*rc.d stop --noauto*:: + Stop all script which are not runned at startup + +*rc.d restart crond*:: + Restarts the *crond* script. + +*rc.d restart --stopped crond*:: + Restarts the *crond* script only if stopped. + +*rc.d help*:: + Display help. + +Directories[[D]] +---------------- +'/etc/rc.d':: + Directory containing available daemons on the system. + +'/usr/lib/initscripts':: + Directory containing available initscripts plugins. + +Authors +------- + Written by Sebastien Luttringer and Dave Reisner. @@ -8,8 +8,8 @@ run_hook multi_start -# Load sysctl variables if sysctl.conf is present -[[ -r /etc/sysctl.conf ]] && sysctl -q -p &>/dev/null +# Load sysctl config files +[[ -x /usr/lib/initscripts/arch-sysctl ]] && /usr/lib/initscripts/arch-sysctl # Start daemons for daemon in "${DAEMONS[@]}"; do diff --git a/rc.shutdown b/rc.shutdown index db8f50b..5928b2d 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -19,6 +19,14 @@ run_hook shutdown_start stop_all_daemons +status "Shutting down UDev" udevadm control --exit + +status "Deactivating Swap" swapoff -a + +# stop monitoring of lvm2 groups before unmounting filesystems +[[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) ]] && + status "Deactivating monitoring of LVM2 groups" vgchange --monitor n + run_hook shutdown_prekillall kill_all @@ -31,26 +39,18 @@ stat_busy "Saving Random Seed" POOL_FILE=/proc/sys/kernel/random/poolsize if [[ -r $POOL_FILE ]]; then read POOL_SIZE < $POOL_FILE + (( POOL_SIZE /= 8 )) else POOL_SIZE=512 fi dd if=/dev/urandom of=$RANDOM_SEED count=1 bs=$POOL_SIZE &>/dev/null stat_done -[[ $TIMEZONE ]] && - status "Saving Time Zone" \ - cp --remove-destination "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime +[[ $TIMEZONE ]] && status "Configuring Time Zone" set_timezone "$TIMEZONE" # Write to wtmp file before unmounting halt -w -status "Deactivating Swap" swapoff -a - -# stop monitoring of lvm2 groups before unmounting filesystems -[[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) && -d /sys/block ]] && - status "Deactivating monitoring of LVM2 groups" \ - vgchange --monitor n &>/dev/null - # if we don't have devtmpfs support, /dev is mounted as tmpfs, so don't unmount it status "Unmounting Filesystems" \ umount -a -r -t nodevtmpfs,notmpfs,nosysfs,noproc,nodevpts -O no_netdev @@ -78,6 +78,8 @@ fi [[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) && -d /sys/block ]] && status "Deactivating LVM2 groups" vgchange --sysinit -a n &>/dev/null +run_hook shutdown_poweroff + if [[ -x /run/initramfs/shutdown ]]; then # decide what we want to do @@ -116,8 +118,6 @@ else status "Remounting Root Filesystem Read-only" \ mount -n -o remount,ro / - run_hook shutdown_poweroff - # Power off or reboot printsep if [[ $RUNLEVEL = 0 ]]; then @@ -16,7 +16,7 @@ printsep mountpoint -q /proc || mount -n -t proc proc /proc -o nosuid,noexec,nodev mountpoint -q /sys || mount -n -t sysfs sys /sys -o nosuid,noexec,nodev mountpoint -q /run || mount -n -t tmpfs run /run -o mode=0755,size=10M,nosuid,nodev -mountpoint -q /dev || mount -n -t devtmpfs udev /dev -o mode=0755,size=10M,nosuid &>/dev/null \ +mountpoint -q /dev || mount -n -t devtmpfs udev /dev -o mode=0755,size=10M,nosuid \ || mount -n -t tmpfs udev /dev -o mode=0755,size=10M,nosuid mkdir -p -m 1777 /run/lock mkdir -p /dev/{pts,shm} @@ -32,8 +32,7 @@ findmnt / --options ro &>/dev/null || run_hook sysinit_start -# start up our mini logger until syslog takes over -minilogd +# log all console messages bootlogd -p /run/bootlogd.pid if [[ ! -a /usr/lib ]] ; then @@ -201,6 +200,7 @@ status "Remounting Root Read/Write" \ # don't touch /etc/mtab if it is a symlink to /proc/self/mounts if [[ ! -L /etc/mtab ]]; then stat_busy "Creating mtab" + rm -f /etc/mtab~* # delete any stale locks if [[ -x $(type -P findmnt) && -e /proc/self/mountinfo ]]; then findmnt -rnu -o SOURCE,TARGET,FSTYPE,OPTIONS >| /etc/mtab else @@ -222,9 +222,7 @@ run_hook sysinit_postmount status "Activating Swap" swapon -a -[[ $TIMEZONE ]] && - status "Configuring Time Zone" \ - cp --remove-destination "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime +[[ $TIMEZONE ]] && status "Configuring Time Zone" set_timezone "$TIMEZONE" RANDOM_SEED=/var/lib/misc/random-seed [[ -f $RANDOM_SEED ]] && @@ -239,6 +237,10 @@ if [[ $HOSTNAME ]]; then echo "$HOSTNAME" >| /proc/sys/kernel/hostname && stat_done || stat_fail fi +if [[ -s /etc/locale.conf ]]; then + . /etc/locale.conf + [[ $LANG ]] && LOCALE=$LANG +fi if [[ ${LOCALE,,} =~ utf ]]; then stat_busy "Setting Consoles to UTF-8 mode" # UTF-8 consoles are default since 2.6.24 kernel @@ -260,6 +262,12 @@ else echo 0 >| /sys/module/vt/parameters/default_utf8 stat_done fi + +if [[ -s /etc/vconsole.conf ]]; then + . /etc/vconsole.conf + [[ $FONT ]] && CONSOLEFONT=$FONT + [[ $FONT_MAP ]] && CONSOLEMAP=$FONT_MAP +fi [[ $KEYMAP ]] && status "Loading Keyboard Map: $KEYMAP" loadkeys -q $KEYMAP diff --git a/zsh-completion b/zsh-completion index e5c2850..58fdfab 100644 --- a/zsh-completion +++ b/zsh-completion @@ -4,11 +4,10 @@ _rc.d () { local curcontext="$curcontext" state line typeset -A opt_args - _arguments "1: :->action" "*: :->service" - + _arguments "1: :->action" "*: :->service" {-s,--started} {-S,--stopped} {-a,--auto} {-A,--noauto} case $state in action) - _arguments "1:action:(list help start stop restart)" + _arguments "*:action:(list help start stop restart)" ;; service) local action="$words[2]" @@ -18,9 +17,6 @@ _rc.d () { help) _arguments "*: :" ;; - list) - _arguments "2: :(started stopped)" - ;; start) _arguments "*: :($(comm -23 <(echo /etc/rc.d/*(N-*:t)|tr ' ' '\n') <(echo /run/daemons/*(N:t)|tr ' ' '\n')))" ;; |