Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
65466f0702 | |||
db4eb9162b | |||
431f7e145e | |||
5b1dbee3ac | |||
6535b2b0e3 | |||
987c655fcc | |||
69a1c39cbc | |||
c799ab796b | |||
24d64da2ed | |||
b640a64e21 | |||
fced4775b1 |
|
@ -5,3 +5,4 @@ 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,9 +11,12 @@ cfg_hostname='spark'
|
|||
# Uncomment and change this to yours
|
||||
#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
|
||||
cfg_services+=(
|
||||
'fsck' 'mount' 'sysctl' 'rsyslogd'
|
||||
'mount' 'sysctl' 'rsyslogd'
|
||||
'@lo.iface' '@scron' @agetty-tty{2..6}
|
||||
)
|
||||
|
||||
|
@ -40,3 +43,6 @@ cfg_mounts=(
|
|||
# Some temporary directories and files
|
||||
cfg_tmpdirs+=( '/run/lock' '/run/lock/lvm' '/run/lvm' '/run/user' )
|
||||
cfg_tmpfiles+=( '/run/utmp' )
|
||||
|
||||
# How long do we wait for all processes to die nicely?
|
||||
cfg_killall5_timeout=30
|
||||
|
|
17
rc.in
17
rc.in
|
@ -101,10 +101,10 @@ rc.services_stop() {
|
|||
|
||||
rc.stop_everything() {
|
||||
echo "Politely asking all processes to shut down..."
|
||||
killall5 -15; sleep 3
|
||||
killall5 -s 15 -w "$cfg_killall5_timeout"
|
||||
|
||||
echo "Killing the remaning ones..."
|
||||
killall5 -9
|
||||
killall5 -s 9
|
||||
}
|
||||
|
||||
rc.unmount_everything() {
|
||||
|
@ -118,6 +118,8 @@ rc.remount_root() {
|
|||
}
|
||||
|
||||
rc.boot() {
|
||||
(( cfg_early_fsck )) && rc.fsck
|
||||
|
||||
rc.mount
|
||||
rc.tmpfiles
|
||||
rc.hostname
|
||||
|
@ -149,6 +151,7 @@ rc.halt() {
|
|||
|
||||
rc.sync() {
|
||||
echo "Syncing disks."
|
||||
sync
|
||||
}
|
||||
|
||||
rc.shutdown() {
|
||||
|
@ -180,11 +183,21 @@ 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() {
|
||||
source "@ETC@/rc.conf"
|
||||
|
||||
# Default XDG_RUNTIME_DIR for all non-system users
|
||||
# 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
|
||||
if (( uid >= 1000 )); then
|
||||
cfg_tmpdirs+=( "/run/user/$uid:700:$uid:$gid" )
|
||||
|
|
|
@ -37,14 +37,60 @@ get_procs_to_kill() {
|
|||
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() {
|
||||
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 )
|
||||
all_procs=( $(get_all_procs) )
|
||||
procs_to_kill=( $(get_procs_to_kill) )
|
||||
|
||||
signal="${1:-"-15"}"
|
||||
kill -n "$signal" "${procs_to_kill[@]}" 2>/dev/null
|
||||
|
||||
kill "$signal" "${procs_to_kill[@]}" 2>/dev/null
|
||||
if (( flag_wait )); then
|
||||
pid_wait "${procs_to_kill[@]}"
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user