21 Commits

Author SHA1 Message Date
fbt
431f7e145e wait what how
Signed-off-by: fbt <fbt@fleshless.org>
2017-07-15 16:56:06 +03:00
fbt
5b1dbee3ac Merge branch 'master' of builder:git/spark-rc 2017-01-03 22:45:28 +03:00
fbt
6535b2b0e3 add a rundir for root
Signed-off-by: fbt <fbt@fleshless.org>
2016-09-14 08:46:07 +03:00
fbt
987c655fcc Just use /proc to see if a process is running 2016-03-29 19:21:53 +03:00
fbt
69a1c39cbc default timeout in the config 2016-03-29 16:23:55 +03:00
fbt
c799ab796b we need to actually return 1 if no pids are alive. DUH 2016-03-29 16:03:44 +03:00
fbt
24d64da2ed stupid typo 2016-03-29 15:48:59 +03:00
fbt
b640a64e21 Merge branch 'master' of builder:git/spark-rc 2016-03-29 15:40:20 +03:00
fbt
fced4775b1 wait flag for killall5 2016-03-29 15:40:14 +03:00
fbt
58054382e2 null the type output
Signed-off-by: fbt <fbt@fleshless.org>
2016-03-26 18:13:47 +03:00
fbt
04ff160a7d better sysrq test
Signed-off-by: fbt <fbt@fleshless.org>
2016-03-26 17:52:27 +03:00
fbt
409f6f8cd2 Merge branch 'master' of builder:git/spark-rc 2016-03-25 12:31:32 +03:00
fbt
ff28e04a20 use halt if available 2016-03-25 12:31:12 +03:00
fbt
e2b068e45d vim modeline 2015-11-04 21:06:19 +03:00
fbt
0afbcc55f2 rc.mount rewrite 2015-10-27 18:43:56 +03:00
fbt
1d5e825201 a huge oops 2015-10-26 19:16:18 +03:00
fbt
15592c0daa this should be a decent default 2015-10-14 10:03:58 +03:00
fbt
e379e8efff set the locale in rc.conf 2015-10-13 11:23:10 +03:00
fbt
9363ea33f5 agettys 2015-09-07 23:01:14 +03:00
fbt
92b8205255 on a second thought, the default IFS sucks 2015-09-01 13:05:37 +03:00
fbt
5dad6a777e default IFS, add tmp 2015-09-01 13:02:18 +03:00
4 changed files with 102 additions and 21 deletions

View File

@@ -1,4 +1,8 @@
spark-rc
========
# spark-rc
A simple rc script to kickstart your system.
## depends
* Enabled sysrq or halt from suckless.org's ubase.
* /proc support.

14
rc.conf
View File

@@ -1,6 +1,9 @@
# System-wide configuration
# A default PATH
export PATH='/usr/local/bin:/usr/local/sbin:/usr/bin'
# Locale
export LC_ALL='en_US.UTF-8'
# Hostname
cfg_hostname='spark'
@@ -11,7 +14,7 @@ cfg_hostname='spark'
# Services that start with @ are executed in parallel
cfg_services+=(
'fsck' 'mount' 'sysctl' 'rsyslogd'
'@lo.iface' '@scron'
'@lo.iface' '@scron' @agetty-tty{2..6}
)
# Uncomment and add modules you want to be loaded at boot time here
@@ -22,8 +25,10 @@ ctrlaltdel soft
# Virtual filesystems
cfg_mounts=(
'proc:proc:/proc'
'run:tmpfs:/run'
'tmp:tmpfs:/tmp'
'proc:proc:/proc:defaults,hidepid=2'
'sys:sysfs:/sys'
'dev:devtmpfs:/dev'
@@ -35,3 +40,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

39
rc.in
View File

@@ -1,4 +1,5 @@
#!@BASH_PATH@
# vim: ft=zsh
# Functions
rc.rescue() { exec "${cfg_rc_rescue_shell:-"$SHELL"}"; }
@@ -29,13 +30,21 @@ rc.tmpfiles() {
rc.mount() {
for fs in "${cfg_mounts[@]}"; 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
[[ "$mount_options" ]] || { mount_options='defaults'; }
if ! [[ "$mount_options" ]]; then
mount_options='defaults'
fi
mountpoint -q "$mountpoint" || {
[[ -d "$mountpoint" ]] || { mkdir -p "$mountpoint"; }
mount "$device" -n -t "$fs_type" -o "$mount_options" "$mountpoint"
}
fi
done
done
}
@@ -92,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() {
@@ -120,15 +129,27 @@ rc.boot() {
}
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
poweroff|shutdown) echo 'o' > /proc/sysrq-trigger;;
halt) :;;
reboot|*) echo 'b' > /proc/sysrq-trigger;;
poweroff|shutdown) rc.halt_poweroff;;
reboot|*) rc.halt_reboot;;
esac
}
rc.sync() {
echo "Syncing disks."
sync
}
rc.shutdown() {
@@ -165,6 +186,8 @@ rc.main() {
# 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" )

View File

@@ -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
}