Compare commits
25 Commits
Author | SHA1 | Date | |
---|---|---|---|
431f7e145e | |||
5b1dbee3ac | |||
6535b2b0e3 | |||
987c655fcc | |||
69a1c39cbc | |||
c799ab796b | |||
24d64da2ed | |||
b640a64e21 | |||
fced4775b1 | |||
58054382e2 | |||
04ff160a7d | |||
409f6f8cd2 | |||
ff28e04a20 | |||
e2b068e45d | |||
0afbcc55f2 | |||
1d5e825201 | |||
15592c0daa | |||
e379e8efff | |||
9363ea33f5 | |||
92b8205255 | |||
5dad6a777e | |||
63eda033cc | |||
2b32655365 | |||
ec2ff428f8 | |||
358824da8f |
@@ -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.
|
||||
|
44
rc.conf
44
rc.conf
@@ -1,21 +1,45 @@
|
||||
# System-wide configuration
|
||||
export PATH='/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin'
|
||||
# A default PATH
|
||||
export PATH='/usr/local/bin:/usr/local/sbin:/usr/bin'
|
||||
|
||||
# Locale
|
||||
export LC_ALL='en_US.UTF-8'
|
||||
|
||||
# Hostname
|
||||
cfg_hostname='changeme'
|
||||
cfg_hostname='spark'
|
||||
|
||||
# Timezone
|
||||
# Change this to yours
|
||||
# Uncomment and change this to yours
|
||||
#cfg_timezone='Europe/Moscow'
|
||||
|
||||
# Services
|
||||
cfg_services+=( 'fsck' 'mount' 'sysctl' 'rsyslogd' ) # Services that need tp be started in an order
|
||||
cfg_services+=( '@lo.iface' '@scron' '@sshd' ) # These start in parallel.
|
||||
cfg_services+=( @agetty-tty{2..6} ) # Comment this if your init starts something on the ttys itself.
|
||||
cfg_services+=( 'rc.local' ) # Traditionally, rc.local starts last. Technically here it doesn't. Not quite :)
|
||||
# Services that start with @ are executed in parallel
|
||||
cfg_services+=(
|
||||
'fsck' 'mount' 'sysctl' 'rsyslogd'
|
||||
'@lo.iface' '@scron' @agetty-tty{2..6}
|
||||
)
|
||||
|
||||
# Add modules you want to be loaded at boot time here
|
||||
# Uncomment and add modules you want to be loaded at boot time here
|
||||
#cfg_modules=( )
|
||||
|
||||
# Make C-A-D perform a soft reset
|
||||
ctrlaltdel soft
|
||||
|
||||
# Virtual filesystems
|
||||
cfg_mounts=(
|
||||
'run:tmpfs:/run'
|
||||
'tmp:tmpfs:/tmp'
|
||||
|
||||
'proc:proc:/proc:defaults,hidepid=2'
|
||||
'sys:sysfs:/sys'
|
||||
|
||||
'dev:devtmpfs:/dev'
|
||||
'pts:devpts:/dev/pts:noexec,nosuid,gid=5,mode=0620'
|
||||
'mqueue:mqueue:/dev/mqueue:noexec,nosuid,nodev'
|
||||
'shm:tmpfs:/dev/shm:defaults,mode=0777'
|
||||
)
|
||||
|
||||
# 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
|
||||
|
84
rc.in
84
rc.in
@@ -1,30 +1,5 @@
|
||||
#!@BASH_PATH@
|
||||
declare -A cfg_mounts
|
||||
|
||||
# Default virtual mounts for linux systems
|
||||
cfg_mounts[proc]='proc:/proc'
|
||||
cfg_mounts[run]='tmpfs:/run'
|
||||
cfg_mounts[sys]='sysfs:/sys'
|
||||
|
||||
# devfs and its children
|
||||
cfg_mounts[dev]='devtmpfs:/dev'
|
||||
cfg_mounts[pts]='devpts:/dev/pts:noexec,nosuid,gid=5,mode=0620'
|
||||
cfg_mounts[mqueue]='mqueue:/dev/mqueue:noexec,nosuid,nodev'
|
||||
cfg_mounts[shm]='tmpfs:/dev/shm:defaults,mode=0777'
|
||||
|
||||
# Some temporary directories
|
||||
cfg_tmpdirs+=( '/run/lock' '/run/lock/lvm' '/run/lvm' '/run/user' )
|
||||
|
||||
# And temporary files
|
||||
cfg_tmpfiles+=( '/run/utmp' )
|
||||
|
||||
# Default XDG_RUNTIME_DIR for all non-system users
|
||||
# rtkit:x:133:133:RealtimeKit:/proc:/sbin/nologin
|
||||
while IFS=':' read -r _ _ uid gid _; do
|
||||
if (( uid >= 1000 )); then
|
||||
cfg_tmpdirs+=( "/run/user/$uid:700:$uid:$gid" )
|
||||
fi
|
||||
done < /etc/passwd
|
||||
# vim: ft=zsh
|
||||
|
||||
# Functions
|
||||
rc.rescue() { exec "${cfg_rc_rescue_shell:-"$SHELL"}"; }
|
||||
@@ -52,15 +27,24 @@ rc.tmpfiles() {
|
||||
done
|
||||
}
|
||||
|
||||
rc.mount_misc() {
|
||||
for fs in "${!cfg_mounts[@]}"; do
|
||||
echo "$fs" | while IFS=':' read fs_type mountpoint mount_options; do
|
||||
[[ "$mount_options" ]] || { mount_options='defaults'; }
|
||||
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
|
||||
|
||||
mountpoint -q "$mountpoint" || {
|
||||
[[ -d "$mountpoint" ]] || { mkdir -p "$mountpoint"; }
|
||||
mount "$fs" -n -t "$fs_type" -o "$mount_options" "$mountpoint"
|
||||
}
|
||||
if ! [[ "$mount_options" ]]; then
|
||||
mount_options='defaults'
|
||||
fi
|
||||
|
||||
mount "$device" -n -t "$fs_type" -o "$mount_options" "$mountpoint"
|
||||
fi
|
||||
done
|
||||
done
|
||||
}
|
||||
@@ -117,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() {
|
||||
@@ -134,7 +118,7 @@ rc.remount_root() {
|
||||
}
|
||||
|
||||
rc.boot() {
|
||||
rc.mount_misc
|
||||
rc.mount
|
||||
rc.tmpfiles
|
||||
rc.hostname
|
||||
rc.timezone
|
||||
@@ -145,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() {
|
||||
@@ -188,6 +184,16 @@ rc.timezone() {
|
||||
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" )
|
||||
fi
|
||||
done < /etc/passwd
|
||||
|
||||
action="${1:-boot}"
|
||||
|
||||
case "$action" in
|
||||
|
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user