diff options
author | Olav Vitters <olav@vitters.nl> | 2020-07-26 21:46:44 +0200 |
---|---|---|
committer | Olav Vitters <olav@vitters.nl> | 2020-07-26 21:46:44 +0200 |
commit | 244c9a00ae9a0dc62156aeb8781c2b22da0ad96e (patch) | |
tree | c0d76ed490862837a8a37bb61ed8e653e5cc2558 /usr | |
parent | d0d18c6de12efeba25eb41d7cf207037027e4964 (diff) | |
parent | 6ca701a23c74b245f35750149a22f7d21805a8e0 (diff) | |
download | initscripts-244c9a00ae9a0dc62156aeb8781c2b22da0ad96e.tar initscripts-244c9a00ae9a0dc62156aeb8781c2b22da0ad96e.tar.gz initscripts-244c9a00ae9a0dc62156aeb8781c2b22da0ad96e.tar.bz2 initscripts-244c9a00ae9a0dc62156aeb8781c2b22da0ad96e.tar.xz initscripts-244c9a00ae9a0dc62156aeb8781c2b22da0ad96e.zip |
Merge tag '10.04' into distro/mga
10.04 release
Diffstat (limited to 'usr')
-rwxr-xr-x | usr/lib/systemd/mandriva-save-dmesg | 4 | ||||
-rw-r--r-- | usr/lib/systemd/system/import-state.service | 17 | ||||
-rw-r--r-- | usr/lib/systemd/system/loadmodules.service | 16 | ||||
-rw-r--r-- | usr/lib/systemd/system/mandriva-everytime.service | 16 | ||||
-rw-r--r-- | usr/lib/systemd/system/mandriva-save-dmesg.service | 14 | ||||
-rw-r--r-- | usr/lib/systemd/system/netconsole.service | 14 | ||||
-rw-r--r-- | usr/lib/systemd/system/readonly-root.service | 15 | ||||
-rw-r--r-- | usr/lib/udev/rules.d/60-net.rules | 1 | ||||
-rwxr-xr-x | usr/libexec/import-state | 39 | ||||
-rwxr-xr-x | usr/libexec/loadmodules | 13 | ||||
-rwxr-xr-x | usr/libexec/netconsole | 165 | ||||
-rwxr-xr-x | usr/libexec/readonly-root | 204 | ||||
-rwxr-xr-x | usr/sbin/service | 154 |
13 files changed, 672 insertions, 0 deletions
diff --git a/usr/lib/systemd/mandriva-save-dmesg b/usr/lib/systemd/mandriva-save-dmesg new file mode 100755 index 00000000..92562fcc --- /dev/null +++ b/usr/lib/systemd/mandriva-save-dmesg @@ -0,0 +1,4 @@ +#!/bin/sh + +[ -f /var/log/dmesg ] && mv -f /var/log/dmesg /var/log/dmesg.old +dmesg -s 131072 > /var/log/dmesg diff --git a/usr/lib/systemd/system/import-state.service b/usr/lib/systemd/system/import-state.service new file mode 100644 index 00000000..64237a09 --- /dev/null +++ b/usr/lib/systemd/system/import-state.service @@ -0,0 +1,17 @@ +[Unit] +Description=Import network configuration from initramfs +DefaultDependencies=no +ConditionPathIsReadWrite=/ +ConditionDirectoryNotEmpty=/run/initramfs/state +Conflicts=shutdown.target +Before=shutdown.target emergency.service emergency.target systemd-tmpfiles-setup.service sysinit.target +After=local-fs.target + +[Service] +ExecStart=/usr/libexec/import-state +Type=oneshot +TimeoutSec=0 +RemainAfterExit=yes + +[Install] +WantedBy=sysinit.target diff --git a/usr/lib/systemd/system/loadmodules.service b/usr/lib/systemd/system/loadmodules.service new file mode 100644 index 00000000..85e807f7 --- /dev/null +++ b/usr/lib/systemd/system/loadmodules.service @@ -0,0 +1,16 @@ +[Unit] +Description=Load legacy module configuration +DefaultDependencies=no +Conflicts=shutdown.target +Before=sysinit.target shutdown.target +ConditionPathExists=|/etc/rc.modules +ConditionDirectoryNotEmpty=|/etc/sysconfig/modules/ + +[Service] +ExecStart=/usr/libexec/loadmodules +Type=oneshot +TimeoutSec=0 +RemainAfterExit=yes + +[Install] +WantedBy=sysinit.target diff --git a/usr/lib/systemd/system/mandriva-everytime.service b/usr/lib/systemd/system/mandriva-everytime.service new file mode 100644 index 00000000..cc247dba --- /dev/null +++ b/usr/lib/systemd/system/mandriva-everytime.service @@ -0,0 +1,16 @@ +[Unit] +Description=Reconfigure the system on administrator request +DefaultDependencies=no +Conflicts=shutdown.target +Before=basic.target shutdown.target +After=local-fs.target dkms-autorebuild.service + +[Service] +ExecStart=-/etc/init.d/mandrake_everytime +Type=oneshot +TimeoutSec=0 +StandardInput=tty +RemainAfterExit=yes + +[Install] +WantedBy=basic.target diff --git a/usr/lib/systemd/system/mandriva-save-dmesg.service b/usr/lib/systemd/system/mandriva-save-dmesg.service new file mode 100644 index 00000000..386e263e --- /dev/null +++ b/usr/lib/systemd/system/mandriva-save-dmesg.service @@ -0,0 +1,14 @@ +[Unit] +Description=Save boot dmesg content +DefaultDependencies=no +Conflicts=shutdown.target +After=systemd-udev-settle.service local-fs.target +Before=shutdown.target + +[Service] +ExecStart=-/lib/systemd/mandriva-save-dmesg +Type=oneshot +RemainAfterExit=yes + +[Install] +WantedBy=shutdown.target diff --git a/usr/lib/systemd/system/netconsole.service b/usr/lib/systemd/system/netconsole.service new file mode 100644 index 00000000..29248a4f --- /dev/null +++ b/usr/lib/systemd/system/netconsole.service @@ -0,0 +1,14 @@ +[Unit] +Description=Initializes network console logging of kernel messages +ConditionPathExists=/etc/sysconfig/netconsole +After=network-online.target +Wants=network-online.target + +[Service] +ExecStart=/usr/libexec/netconsole start +ExecStop=/usr/libexec/netconsole stop +Type=oneshot +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target diff --git a/usr/lib/systemd/system/readonly-root.service b/usr/lib/systemd/system/readonly-root.service new file mode 100644 index 00000000..26d4a118 --- /dev/null +++ b/usr/lib/systemd/system/readonly-root.service @@ -0,0 +1,15 @@ +[Unit] +Description=Configure read-only root support +DefaultDependencies=no +Conflicts=shutdown.target +Before=shutdown.target emergency.service emergency.target systemd-tmpfiles-setup.service local-fs.target systemd-random-seed.service +After=systemd-remount-fs.service + +[Service] +ExecStart=/usr/libexec/readonly-root +Type=oneshot +TimeoutSec=0 +RemainAfterExit=yes + +[Install] +WantedBy=local-fs.target diff --git a/usr/lib/udev/rules.d/60-net.rules b/usr/lib/udev/rules.d/60-net.rules new file mode 100644 index 00000000..41875017 --- /dev/null +++ b/usr/lib/udev/rules.d/60-net.rules @@ -0,0 +1 @@ +ACTION=="add", SUBSYSTEM=="net", DRIVERS=="?*", ATTR{type}=="1", PROGRAM="/lib/udev/rename_device", RESULT=="?*", NAME="$result" diff --git a/usr/libexec/import-state b/usr/libexec/import-state new file mode 100755 index 00000000..be2d13eb --- /dev/null +++ b/usr/libexec/import-state @@ -0,0 +1,39 @@ +#!/bin/bash +# import-state: import state files from initramfs (e.g. network config) + +# Copy state into root folder: +# ============================ +cd /run/initramfs/state + +IFS_backup=$IFS +IFS=$'\n' # Process find's results line by line + +dirs_found=$(find . -type d) + +for dir in $dirs_found; do + pushd "$dir" > /dev/null + + # Remove initial '.' char from the find's result: + dest_dir="${dir/\./}" + + # Create destination folder if it does not exist (with the same rights): + if [[ -n "$dest_dir" && ! -d "$dest_dir" ]]; then + mkdir -p "$dest_dir" + chmod --reference="$PWD" "$dest_dir" + chown --reference="$PWD" "$dest_dir" + fi + + # Copy all files that are not directory: + find . -mindepth 1 -maxdepth 1 -not -type d -exec cp -av -t "$dest_dir" {} \; > /dev/null + + popd > /dev/null +done + +IFS=$IFS_backup + + +# Run restorecon on the copied files: +# =================================== +if [ -e /sys/fs/selinux/enforce ] && [ -x /usr/sbin/restorecon ]; then + find . -mindepth 1 -print0 | { cd / && xargs --null restorecon -iF; } +fi diff --git a/usr/libexec/loadmodules b/usr/libexec/loadmodules new file mode 100755 index 00000000..5925bdf7 --- /dev/null +++ b/usr/libexec/loadmodules @@ -0,0 +1,13 @@ +#!/bin/bash + +# Load other user-defined modules +for file in /etc/sysconfig/modules/*.modules ; do + if [ -x $file ]; then + $file + fi +done + +# Load modules (for backward compatibility with VARs) +if [ -f /etc/rc.modules ]; then + /etc/rc.modules +fi diff --git a/usr/libexec/netconsole b/usr/libexec/netconsole new file mode 100755 index 00000000..48f9bbf4 --- /dev/null +++ b/usr/libexec/netconsole @@ -0,0 +1,165 @@ +#!/bin/bash +# +# netconsole This loads the netconsole module with the configured parameters. +# +# chkconfig: - 50 50 +# description: Initializes network console logging +# config: /etc/sysconfig/netconsole +# +### BEGIN INIT INFO +# Provides: netconsole +# Required-Start: $network +# Required-Stop: $network +# Short-Description: Initializes network console logging +# Description: Initializes network console logging of kernel messages. +### END INIT INFO + +# Copyright 2002 Red Hat, Inc. +# +# Based in part on a shell script by +# Andreas Dilger <adilger@turbolinux.com> Sep 26, 2001 + +PATH=/sbin:/usr/sbin:$PATH +RETVAL=0 +SERVER_ADDRESS_RESOLUTION= + +# Check that networking is up. +. /etc/sysconfig/network + +# Source function library. +. /etc/rc.d/init.d/functions + +# Default values +LOCALPORT=6666 +DEV= + +SYSLOGADDR= +SYSLOGPORT=514 +SYSLOGMACADDR= + +kernel=$(uname -r | cut -d. -f1-2) + +usage () +{ + gprintf "Usage: %s {start|stop|status|restart|condrestart}\n" $0 1>&2 + RETVAL=2 +} + +print_address_info () +{ + local host=$1 + local route via target + + route=$(LANG=C ip -o route get to $host/32) + + [ -z "$DEV" ] && DEV=$(echo $route | sed "s|.* dev \([^ ]*\).*|\1|") + echo "DEV=$DEV" + echo "LOCALADDR=$(echo $route | sed "s|.* src \([^ ]*\).*|\1|")" + if [[ $route == *" via "* ]] ; then + via=$(echo $route | sed "s|.* via \([^ ]*\).*|\1|") + target=$via + else + target=$host + fi + if [ -z "$SYSLOGMACADDR" ]; then + arp=$(LANG=C /sbin/arping -f -c 1 -I $DEV $target 2>/dev/null | awk '/ reply from .*[.*]/ { print gensub(".* reply from .* \\[(.*)\\].*","\\1","G"); exit }') + [ -n "$arp" ] && echo "SYSLOGMACADDR=$arp" + fi +} + +start () +{ + [ -f /etc/sysconfig/netconsole ] || exit 6 + . /etc/sysconfig/netconsole + + SYSLOGOPTS= + # syslogd server, if any + if [ -n "$SYSLOGADDR" ]; then + # IPv6 regex also covers 4to6, zero-compressed, and link-local addresses with zone-index addresses. + # It should also cover IPv4-embedded, IPv4-mapped, and IPv4-translated IPv6 addresses. + # Taken from: http://stackoverflow.com/a/17871737/3481531 + IPv4_regex="^([0-9]{1,3}\.){3}[0-9]{1,3}$" + IPv6_regex="^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$" + if ! [[ "$SYSLOGADDR" =~ $IPv4_regex ]] && ! [[ "$SYSLOGADDR" =~ $IPv6_regex ]]; then + # Use IPv4 by default: + SYSLOGADDR="$(LANG=C getent ahostsv4 $SYSLOGADDR 2> /dev/null)" + + # Try IPv6 in case IPv4 resolution has failed: + if [[ $? -eq 2 ]]; then + SYSLOGADDR="$(LANG=C getent ahostsv6 $SYSLOGADDR 2> /dev/null)" + fi + + if [[ $? -ne 0 ]]; then + echo $"Unable to resolve IP address specified in /etc/sysconfig/netconsole" 1>&2 + exit 6 + fi + + SYSLOGADDR="$(echo "$SYSLOGADDR" | head -1 | cut --delimiter=' ' --fields=1)" + fi + fi + if [ -z "$SYSLOGADDR" ] ; then + gprintf "Server address not specified in /etc/sysconfig/netconsole\n" 1>&2 + exit 6 + fi + eval $(print_address_info $SYSLOGADDR) + + if [ -z "$SYSLOGMACADDR" ]; then + gprintf "netconsole: can't resolve MAC address of %s\n" $SYSLOGADDR 1>&2 + exit 1 + fi + + SYSLOGOPTS="netconsole=$LOCALPORT@$LOCALADDR/$DEV,$SYSLOGPORT@$SYSLOGADDR/$SYSLOGMACADDR " + + /usr/bin/logger -p daemon.info -t netconsole: inserting netconsole module with arguments \ + $SYSLOGOPTS + if [ -n "$SYSLOGOPTS" ]; then + action "Initializing netconsole" modprobe netconsole \ + $SYSLOGOPTS + [ "$?" != "0" ] && RETVAL=1 + fi + touch /var/lock/subsys/netconsole +} + +stop () +{ + if /sbin/lsmod | grep netconsole >/dev/null 2>&1 ; then + action "Disabling netconsole" rmmod netconsole; + [ "$?" != "0" ] && RETVAL=1 + fi + + rm -f /var/lock/subsys/netconsole +} + +status () +{ + if /sbin/lsmod | grep netconsole >/dev/null 2>&1 ; then + gprintf "netconsole module loaded\n" + RETVAL=0 + else + gprintf "netconsole module not loaded\n" + RETVAL=3 + fi +} + + +restart () +{ + stop + start +} + +condrestart () +{ + [ -e /var/lock/subsys/netconsole ] && restart +} + + +case "$1" in + stop) stop ;; + status) status ;; + start|restart|reload|force-reload) restart ;; + condrestart) condrestart ;; + *) usage ;; +esac + +exit $RETVAL diff --git a/usr/libexec/readonly-root b/usr/libexec/readonly-root new file mode 100755 index 00000000..9b9c2824 --- /dev/null +++ b/usr/libexec/readonly-root @@ -0,0 +1,204 @@ +#!/bin/bash +# +# Set up readonly-root support. +# + +. /etc/init.d/functions + +# We need to initialize the $HOSTNAME variable by ourselves now: +# (It was previously done for RHEL-6 branch, but got lost in time.) +HOSTNAME="$(hostname)" + +# Check SELinux status +SELINUX_STATE= +if [ -e "/sys/fs/selinux/enforce" ] && [ "$(cat /proc/self/attr/current | tr -d '\000' )" != "kernel" ]; then + if [ -r "/sys/fs/selinux/enforce" ] ; then + SELINUX_STATE=$(cat "/sys/fs/selinux/enforce") + else + # assume enforcing if you can't read it + SELINUX_STATE=1 + fi +fi + +selinux_fixup() { + if [ -n "$SELINUX_STATE" ] && [ -e "$1" ]; then + restorecon -R "$1" + fi +} + +# Only read this once. +[ -z "${cmdline}" ] && cmdline=$(cat /proc/cmdline) + +READONLY= +if [ -f /etc/sysconfig/readonly-root ]; then + . /etc/sysconfig/readonly-root +fi +if strstr "$cmdline" readonlyroot ; then + READONLY=yes + [ -z "$RW_MOUNT" ] && RW_MOUNT=/var/lib/stateless/writable + [ -z "$STATE_MOUNT" ] && STATE_MOUNT=/var/lib/stateless/state +fi +if strstr "$cmdline" noreadonlyroot ; then + READONLY=no +fi + +MOUNTS=() +if is_true "$READONLY" || is_true "$TEMPORARY_STATE"; then + + add_mount() { + mnt=${1%/} + MOUNTS=("${MOUNTS[@]}" "$mnt") + } + + cp_empty() { + if [ -e "$1" ]; then + echo "$1" | cpio -p -vd "$RW_MOUNT" &>/dev/null + add_mount $1 + fi + } + + cp_dirs() { + if [ -e "$1" ]; then + mkdir -p "$RW_MOUNT$1" + find "$1" -type d -print0 | cpio -p -0vd "$RW_MOUNT" &>/dev/null + add_mount $1 + fi + } + + cp_files() { + if [ -e "$1" ]; then + cp -a --parents "$1" "$RW_MOUNT" + add_mount $1 + fi + } + + # Common mount options for scratch space regardless of + # type of backing store + mountopts= + + # Scan partitions for local scratch storage + rw_mount_dev=$(blkid -t LABEL="$RW_LABEL" -l -o device) + + bindmountopts= + is_true "$SLAVE_MOUNTS" && bindmountopts="--make-slave" + + # First try to mount scratch storage from /etc/fstab, then any + # partition with the proper label. If either succeeds, be sure + # to wipe the scratch storage clean. If both fail, then mount + # scratch storage via tmpfs. + if mount $mountopts "$RW_MOUNT" > /dev/null 2>&1 ; then + rm -rf "$RW_MOUNT" > /dev/null 2>&1 + elif [ x$rw_mount_dev != x ] && mount $rw_mount_dev $mountopts "$RW_MOUNT" > /dev/null 2>&1; then + rm -rf "$RW_MOUNT" > /dev/null 2>&1 + else + mount -n -t tmpfs $RW_OPTIONS $mountopts none "$RW_MOUNT" + fi + + for file in /etc/rwtab /etc/rwtab.d/* /run/initramfs/rwtab ; do + is_ignored_file "$file" && continue + [ -f $file ] && while read type path ; do + case "$type" in + empty) + cp_empty $path + ;; + files) + cp_files $path + ;; + dirs) + cp_dirs $path + ;; + *) + ;; + esac + done < <(cat $file) + done + + for m in "${MOUNTS[@]}"; do + prefix=0 + for mount_point in "${MOUNTS[@]}"; do + [[ $m = $mount_point ]] && continue + if [[ $m =~ ^$mount_point/.* ]] ; then + prefix=1 + break + fi + done + [[ $prefix -eq 1 ]] && continue + + mount -n --bind $bindmountopts "$RW_MOUNT$m" "$m" + selinux_fixup "$m" + done + + # Use any state passed by initramfs + [ -d /run/initramfs/state ] && cp -a /run/initramfs/state/* $RW_MOUNT + + # In theory there should be no more than one network interface active + # this early in the boot process -- the one we're booting from. + # Use the network address to set the hostname of the client. This + # must be done even if we have local storage. + ipaddr= + if [ "$HOSTNAME" = "localhost" -o "$HOSTNAME" = "localhost.localdomain" ]; then + ipaddr=$(ip addr show to 0.0.0.0/0 scope global | awk '/[[:space:]]inet / { print gensub("/.*","","g",$2) }') + for ip in $ipaddr ; do + HOSTNAME= + eval $(ipcalc -h $ipaddr 2>/dev/null) + [ -n "$HOSTNAME" ] && { hostname ${HOSTNAME} ; break; } + done + fi + + # Clients with read-only root filesystems may be provided with a + # place where they can place minimal amounts of persistent + # state. SSH keys or puppet certificates for example. + # + # Ideally we'll use puppet to manage the state directory and to + # create the bind mounts. However, until that's all ready this + # is sufficient to build a working system. + + # First try to mount persistent data from /etc/fstab, then any + # partition with the proper label, then fallback to NFS + state_mount_dev=$(blkid -t LABEL="$STATE_LABEL" -l -o device) + if mount $mountopts $STATE_OPTIONS "$STATE_MOUNT" > /dev/null 2>&1 ; then + /bin/true + elif [ x$state_mount_dev != x ] && mount $state_mount_dev $mountopts "$STATE_MOUNT" > /dev/null 2>&1; then + /bin/true + elif [ ! -z "$CLIENTSTATE" ]; then + # No local storage was found. Make a final attempt to find + # state on an NFS server. + + mount -t nfs $CLIENTSTATE/$HOSTNAME $STATE_MOUNT -o rw,nolock + fi + + if [ -w "$STATE_MOUNT" ]; then + + mount_state() { + if [ -e "$1" ]; then + [ ! -e "$STATE_MOUNT$1" ] && cp -a --parents "$1" "$STATE_MOUNT" + mount -n --bind $bindmountopts "$STATE_MOUNT$1" "$1" + fi + } + + for file in /etc/statetab /etc/statetab.d/* ; do + is_ignored_file "$file" && continue + [ ! -f "$file" ] && continue + + if [ -f "$STATE_MOUNT/$file" ] ; then + mount -n --bind $bindmountopts "$STATE_MOUNT/$file" "$file" + fi + + for path in $(grep -v "^#" "$file" 2>/dev/null); do + mount_state "$path" + selinux_fixup "$path" + done + done + + if [ -f "$STATE_MOUNT/files" ] ; then + for path in $(grep -v "^#" "$STATE_MOUNT/files" 2>/dev/null); do + mount_state "$path" + selinux_fixup "$path" + done + fi + fi + + if mount | grep -q /var/lib/nfs/rpc_pipefs ; then + mount -t rpc_pipefs sunrpc /var/lib/nfs/rpc_pipefs + fi +fi diff --git a/usr/sbin/service b/usr/sbin/service new file mode 100755 index 00000000..569d5973 --- /dev/null +++ b/usr/sbin/service @@ -0,0 +1,154 @@ +#!/bin/bash +# -*- Mode: shell-script -*- +# Copyright (C) 2001 by Chmouel Boudjnah <chmouel@mandrakesoft.com> +# MandrakeSoft. +# Redistribution of this file is permitted under the terms of the GNU +# Public License (GPL) +# Original version writen by RedHat. + +debug= +service= +opt= +fullrestart= +fullrestartall= +statusall= + +servicedir=/etc/init.d +xinetddir=/etc/xinetd.d + +basename=${0##*/} + +. /etc/init.d/functions + +function service_available () { + local subsys + cd $servicedir + + for subsys in *;do + case $subsys in + kheader|numlock|sound|usb|netfs|kudzu|local|pcmcia| \ + network|local|dm|harddrake|xfs) continue;; + esac + is_ignored_file "$service" && continue + grep -q chkconfig $subsys || continue + egrep -q 'restart.*\)' $subsys || continue + [[ -x $subsys ]] || continue + [[ -e /var/lock/subsys/$subsys ]] || continue + echo $(egrep -a '^#.*chkconfig: ' $subsys|awk '{print $4}') $subsys + done | sort -n|cut -d" " -f2 +} + +function usage () { + cat <<EOF 1>&2 +Usage: $basename -[Rfshv] SERVICE ARGUMENTS + -f|--full-restart: Do a fullrestart of the service. + -R|--full-restart-all: Do a fullrestart of all running services. + -s|--status-all: Print a status of all services. + --ignore-dependencies: Do not start required systemd services + --skip-redirect: Do not redirect to systemd + -d|--debug: Launch with debug. + -h|--help: This help. +EOF +exit 1 +} +function check_if_inetd() { + local serv=$1 + if [[ ! -f ${servicedir}/${serv} ]];then + if [[ -f ${xinetddir}/${serv} ]];then + if egrep -q ".*disable.*yes.*" ${xinetddir}/${serv};then + echo "$serv is a xinetd service and it is disabled" + echo "to activate it do the following command:" + echo "chkconfig ${serv} on" + service= + return + fi + service=xinetd + [[ $options = "start" ]] && options=reload + if [[ $options != reload ]] && [[ -z $fullrestart ]];then + echo "There is no such option for xinetd services" + echo "You can only use the start option to reload a xinetd service" + service= + fi + echo "${serv} is a xinetd service" + fi + fi + return +} + +while [[ $1 = --* ]] || [[ $1 = -* ]];do + opt=$1 + shift + case $opt in + --full-restart|-f) fullrestart=yes;; + --full-restart-all|-R) fullrestartall=yes;; + --status-all|-s) statusall=yes;; + --debug|-d) set -x ; debug="/bin/bash -x";; + --help|-h) usage;; + --ignore-dependencies) export SYSTEMCTL_IGNORE_DEPENDENCIES=1;; + --skip-redirect) export SYSTEMCTL_SKIP_REDIRECT=1;; + *) echo "Unknow option $opt"; usage; + esac +done + +service=${1##*/}; shift; +options="$@" + +#nuts ? (yes) +while :;do + [[ -z $service && -n $statusall ]] && break + [[ -z $service && -n $fullrestartall ]] && break + [[ -n $service && -n $statusall ]] && { echo "--status-all doesn't need arguments"; usage ;} + [[ -n $service && -n $fullrestartall ]] && { echo "--full-restart-all doesn't need arguments"; usage ;} + [[ -z $service ]] && usage + [[ -n $service ]] && break +done + +if [[ -n $fullrestartall ]];then + for subsys in $(service_available);do $0 -f $subsys;done + exit 0 #for glibc post upgrades +fi + +if [[ -n $statusall ]];then + cd $servicedir + for service in *;do + case $service in + functions | halt | killall | single| linuxconf| kudzu | \ + mandrake_firstime | mandrake_everytime) + continue ;; + esac + is_ignored_file "$service" && continue + if egrep -q '^([^#]*)status\)' $service;then + $debug $servicedir/$service status + fi + done + exit 0; +fi + +if [[ -n $fullrestart ]];then + check_if_inetd "$service" + cd "$servicedir" + if [[ -f ./$service ]];then + $debug ./$service stop + $debug ./$service start + exit $? + else + echo "Cannot find $servicedir/$service" + usage + fi + exit 1 +fi + +[[ -z $options ]] && { echo -e "I need an action\n" 1>&2; usage;} + +check_if_inetd "$service" ; [[ -z $service ]] && exit 1 + +if ! is_ignored_file "$service" && [[ -f $servicedir/$service ]]; then + env -i PATH="$PATH" TERM="$TERM" SYSTEMCTL_IGNORE_DEPENDENCIES=${SYSTEMCTL_IGNORE_DEPENDENCIES} SYSTEMCTL_SKIP_REDIRECT=${SYSTEMCTL_SKIP_REDIRECT} $debug "$servicedir/$service" $options + exit $? +elif [[ -f /lib/systemd/system/"$service".service ]] && [ -d /run/systemd/system/ ]; then + [ -c /dev/stderr ] && echo $"Redirecting to /bin/systemctl ${options} ${service}.service" > /dev/stderr + exec /bin/systemctl ${options} ${service}.service +else + echo "Cannot find $service service" + usage +fi |