Compare commits
No commits in common. "master" and "1.8.5" have entirely different histories.
@ -1,8 +1,4 @@
|
|||||||
# spark-rc
|
spark-rc
|
||||||
|
========
|
||||||
|
|
||||||
A simple rc script to kickstart your system.
|
A simple rc script to kickstart your system.
|
||||||
|
|
||||||
## depends
|
|
||||||
|
|
||||||
* Enabled sysrq or halt from suckless.org's ubase.
|
|
||||||
* /proc support.
|
|
||||||
|
8
rc.conf
8
rc.conf
@ -11,12 +11,9 @@ cfg_hostname='spark'
|
|||||||
# Uncomment and change this to yours
|
# Uncomment and change this to yours
|
||||||
#cfg_timezone='Europe/Moscow'
|
#cfg_timezone='Europe/Moscow'
|
||||||
|
|
||||||
# Early fsck, if you don't have such a step in your initrd
|
|
||||||
cfg_early_fsck=1
|
|
||||||
|
|
||||||
# Services that start with @ are executed in parallel
|
# Services that start with @ are executed in parallel
|
||||||
cfg_services+=(
|
cfg_services+=(
|
||||||
'mount' 'sysctl' 'rsyslogd'
|
'fsck' 'mount' 'sysctl' 'rsyslogd'
|
||||||
'@lo.iface' '@scron' @agetty-tty{2..6}
|
'@lo.iface' '@scron' @agetty-tty{2..6}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -43,6 +40,3 @@ cfg_mounts=(
|
|||||||
# Some temporary directories and files
|
# Some temporary directories and files
|
||||||
cfg_tmpdirs+=( '/run/lock' '/run/lock/lvm' '/run/lvm' '/run/user' )
|
cfg_tmpdirs+=( '/run/lock' '/run/lock/lvm' '/run/lvm' '/run/user' )
|
||||||
cfg_tmpfiles+=( '/run/utmp' )
|
cfg_tmpfiles+=( '/run/utmp' )
|
||||||
|
|
||||||
# How long do we wait for all processes to die nicely?
|
|
||||||
cfg_killall5_timeout=30
|
|
||||||
|
49
rc.in
49
rc.in
@ -1,5 +1,4 @@
|
|||||||
#!@BASH_PATH@
|
#!@BASH_PATH@
|
||||||
# vim: ft=zsh
|
|
||||||
|
|
||||||
# Functions
|
# Functions
|
||||||
rc.rescue() { exec "${cfg_rc_rescue_shell:-"$SHELL"}"; }
|
rc.rescue() { exec "${cfg_rc_rescue_shell:-"$SHELL"}"; }
|
||||||
@ -30,21 +29,13 @@ rc.tmpfiles() {
|
|||||||
rc.mount() {
|
rc.mount() {
|
||||||
for fs in "${cfg_mounts[@]}"; do
|
for fs in "${cfg_mounts[@]}"; do
|
||||||
echo "$fs" | while IFS=':' read device fs_type mountpoint mount_options; do
|
echo "$fs" | while IFS=':' read device fs_type mountpoint mount_options; do
|
||||||
if mountpoint -q "$mountpoint"; then
|
|
||||||
if [[ "$mount_options" ]]; then
|
|
||||||
mount -o "remount,$mount_options" "$mountpoint"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
if ! [[ -d "$mountpoint" ]]; then
|
|
||||||
mkdir -p "$mountpoint"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! [[ "$mount_options" ]]; then
|
[[ "$mount_options" ]] || { mount_options='defaults'; }
|
||||||
mount_options='defaults'
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
mountpoint -q "$mountpoint" || {
|
||||||
|
[[ -d "$mountpoint" ]] || { mkdir -p "$mountpoint"; }
|
||||||
mount "$device" -n -t "$fs_type" -o "$mount_options" "$mountpoint"
|
mount "$device" -n -t "$fs_type" -o "$mount_options" "$mountpoint"
|
||||||
fi
|
}
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
@ -101,10 +92,10 @@ rc.services_stop() {
|
|||||||
|
|
||||||
rc.stop_everything() {
|
rc.stop_everything() {
|
||||||
echo "Politely asking all processes to shut down..."
|
echo "Politely asking all processes to shut down..."
|
||||||
killall5 -s 15 -w "$cfg_killall5_timeout"
|
killall5 -15; sleep 3
|
||||||
|
|
||||||
echo "Killing the remaning ones..."
|
echo "Killing the remaning ones..."
|
||||||
killall5 -s 9
|
killall5 -9
|
||||||
}
|
}
|
||||||
|
|
||||||
rc.unmount_everything() {
|
rc.unmount_everything() {
|
||||||
@ -118,8 +109,6 @@ rc.remount_root() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
rc.boot() {
|
rc.boot() {
|
||||||
(( cfg_early_fsck )) && rc.fsck
|
|
||||||
|
|
||||||
rc.mount
|
rc.mount
|
||||||
rc.tmpfiles
|
rc.tmpfiles
|
||||||
rc.hostname
|
rc.hostname
|
||||||
@ -131,27 +120,15 @@ rc.boot() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
rc.halt() {
|
rc.halt() {
|
||||||
if type -P halt &>/dev/null; then
|
|
||||||
function rc.halt_poweroff { halt -p; }
|
|
||||||
function rc.halt_reboot { halt -r; }
|
|
||||||
elif (( $(</proc/sys/kernel/sysrq) )); then
|
|
||||||
function rc.halt_poweroff { echo 'o' > /proc/sysrq-trigger; }
|
|
||||||
function rc.halt_reboot { echo 'b' > /proc/sysrq-trigger; }
|
|
||||||
else
|
|
||||||
printf 'Cannot halt, please install halt from suckless.org ubase or enable sysrq.\n'
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
case "$action" in
|
case "$action" in
|
||||||
|
poweroff|shutdown) echo 'o' > /proc/sysrq-trigger;;
|
||||||
halt) :;;
|
halt) :;;
|
||||||
poweroff|shutdown) rc.halt_poweroff;;
|
reboot|*) echo 'b' > /proc/sysrq-trigger;;
|
||||||
reboot|*) rc.halt_reboot;;
|
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
rc.sync() {
|
rc.sync() {
|
||||||
echo "Syncing disks."
|
echo "Syncing disks."
|
||||||
sync
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rc.shutdown() {
|
rc.shutdown() {
|
||||||
@ -183,21 +160,11 @@ rc.timezone() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rc.fsck() {
|
|
||||||
declare root_rw=0
|
|
||||||
touch /rc-write-test && root_rw=1
|
|
||||||
(( root_rw )) && mount -o remount,ro /
|
|
||||||
fsck -A -C -p
|
|
||||||
(( root_rw )) && mount -o remount,rw /
|
|
||||||
}
|
|
||||||
|
|
||||||
rc.main() {
|
rc.main() {
|
||||||
source "@ETC@/rc.conf"
|
source "@ETC@/rc.conf"
|
||||||
|
|
||||||
# Default XDG_RUNTIME_DIR for all non-system users
|
# Default XDG_RUNTIME_DIR for all non-system users
|
||||||
# rtkit:x:133:133:RealtimeKit:/proc:/sbin/nologin
|
# rtkit:x:133:133:RealtimeKit:/proc:/sbin/nologin
|
||||||
# Also add one for root
|
|
||||||
cfg_tmpdirs+=( "/run/user/0:700:0:0" )
|
|
||||||
while IFS=':' read -r _ _ uid gid _; do
|
while IFS=':' read -r _ _ uid gid _; do
|
||||||
if (( uid >= 1000 )); then
|
if (( uid >= 1000 )); then
|
||||||
cfg_tmpdirs+=( "/run/user/$uid:700:$uid:$gid" )
|
cfg_tmpdirs+=( "/run/user/$uid:700:$uid:$gid" )
|
||||||
|
@ -37,60 +37,14 @@ get_procs_to_kill() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
pids_exist() {
|
|
||||||
for i in "$@"; do
|
|
||||||
if [[ -d "/proc/$i" ]]; then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
pid_wait() {
|
|
||||||
declare counter
|
|
||||||
|
|
||||||
while pids_exist "$@"; do
|
|
||||||
if (( counter == timeout )); then
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
sleep 1
|
|
||||||
|
|
||||||
(( counter++ ))
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
timeout=30
|
|
||||||
signal=15
|
|
||||||
|
|
||||||
while (( $# )); do
|
|
||||||
case $1 in
|
|
||||||
-w)
|
|
||||||
flag_wait=1
|
|
||||||
timeout=$2
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
|
|
||||||
-s)
|
|
||||||
signal=$2
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
|
|
||||||
my_tree=( $(get_my_tree) self thread-self )
|
my_tree=( $(get_my_tree) self thread-self )
|
||||||
all_procs=( $(get_all_procs) )
|
all_procs=( $(get_all_procs) )
|
||||||
procs_to_kill=( $(get_procs_to_kill) )
|
procs_to_kill=( $(get_procs_to_kill) )
|
||||||
|
|
||||||
kill -n "$signal" "${procs_to_kill[@]}" 2>/dev/null
|
signal="${1:-"-15"}"
|
||||||
|
|
||||||
if (( flag_wait )); then
|
kill "$signal" "${procs_to_kill[@]}" 2>/dev/null
|
||||||
pid_wait "${procs_to_kill[@]}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user