MKSHELL=/opt/plan9/bin/rc # Example test-start:VQPservice -u: foo-start echo starting test service -U $target test-stop:VQPservice -d: / echo stopping test service -D $target # Core commands # ------------- # Reboot commands poweroff:V: halt $P poweroff -ndf reboot:V: halt $P reboot -ndf kexec:V: halt $P reboot -ndfk # Initial setup/shutdown for mkinit boot:VEPservice -u: / echo Starting init $P mount -o remount,rw / $P mount -t tmpfs tmpfs /lib/mkinit/state # mount proc here to make bootchart happier $P mount -t proc proc /proc service -U $target # Kill all process, then remount and sync halt:QVE: utmp-stop hwclock-stop alsa-stop echo TERMinating all processes $P pkill -15 --inverse -g0 >/dev/null >[2=1] for (i in 1 2 3 4 5) { $P pgrep -vg0 && $P sleep 1 } echo KILLing all processes $P pkill -9 --inverse -g0 >/dev/null >[2=1] for (i in 1 2 3) { $P pgrep -vg0 && $P sleep 1 } service -F echo Remounting read-only $P mount -o remount,ro / $P sync # Bare # ---- # Listener for /dev/initctl, for shutdown(8) initctl-start:VPservice -u: boot fifo=/dev/initctl if (! test -e $fifo) $P mkfifo $fifo { exec $P initctld $fifo | while(line=`{line}) $P mkinit $line >/dev/console >[2=1] } & service -U $target initctl-stop_cmd=fuser -k /dev/initctl # Proc, mtab, fstab mounts-start:VPservice -u: $devnodes-start $P mdadm -A /dev/md2 /dev/sd[bcd]2 || true $P ln -snf /proc/self/fd /dev/fd $P mount -a service -U $target # Set console font font-start_cmd=setfont # Setup device nodes devtmpfs-start:VEPservice -u: boot $P mount /dev $P mkdir /dev/shm $P mkdir /dev/pts service -U $target devawk-start:VEPservice -u: devtmpfs-start $P echo /root/bin/dev.awk > /proc/sys/kernel/hotplug $P /root/bin/dev.awk service -U $target devsh-start:VEPservice -u: devtmpfs-start $P echo /root/bin/dev.sh > /proc/sys/kernel/hotplug $P /root/bin/dev.sh -a service -U $target mdev-start:VEPservice -u: devtmpfs-start $P echo /sbin/mdev > /proc/sys/kernel/hotplug $P mdev -s service -U $target udev-start:VEPservice -u: mounts-start $P udevd --daemon $P udevadm trigger $P udevadm settle '--timeout=10' service -U $target udev-stop_cmd=pkill udevd # Load kernel modules modules-start:VEPservice -u: mounts-start for (i in `{find /sys/devices -name wakeup -not -path '*PWRBN*'}) { $P echo disabled > $i } service -U $target # Intel graphics card intel-start:VEPservice -u: mounts-start $P modprobe i915 'modeset=1' $P modprobe nouveau 'modeset=1' $P echo OFF > /sys/kernel/debug/vgaswitcheroo/switch service -U $target # Nvidia graphics card nvidia-start:VEPservice -u: mounts-start $P modprobe i915 'modeset=1' $P modprobe nouveau 'modeset=1' $P echo DDIS > /sys/kernel/debug/vgaswitcheroo/switch $P echo 0 > /sys/class/vtconsole/vtcon1/bind $P modprobe -r nouveau $P modprobe nvidia $P setpci -v -H1 -s '00:01.00' 'BRIDGE_CONTROL=0' service -U $target # Nouveau graphics card nouveau-start:VEPservice -u: mounts-start $P modprobe i915 'modeset=1' $P modprobe nouveau 'modeset=1' $P echo DDIS > /sys/kernel/debug/vgaswitcheroo/switch $P echo 0 > /sys/class/vtconsole/vtcon1/bind $P modprobe -r nouveau $P modprobe nouveau 'modeset=1' service -U $target # Clean out /tmp and /var/run directories fsclean-start:VPservice -u: boot dirs=(/run /var/run /tmp) $P mkdir -p /.old $P mv $dirs /.old || true $P mkdir -p $dirs $P chmod 1777 /tmp $P install -m 1777 -d /var/run/screen # Fuck you Screen $P exec rm -rf /.old & service -U $target # Hardware keys hwkeys-start:VEPservice -u: mounts-start $P /root/bin/touchpad.sh $P exec hwkeys & service -U $target hwkeys-stop_cmd=pkill hwkeys # Spawn gettyd for tty[23456] gettyd-start:VEPservice -u: hostname-start utmp-start $P exec gettyd tty2 tty3 tty4 tty5 tty6 & service -U $target gettyd-stop_cmd=fuser -k /dev/tty2 /dev/tty3 /dev/tty4 /dev/tty5 /dev/tty6 # Spawn agettys for tty[23456] agetty-start:VEPservice -u: hostname-start utmp-start $P respawn setsid agetty 38400 tty2 linux $P respawn setsid agetty 38400 tty3 linux $P respawn setsid agetty 38400 tty4 linux $P respawn setsid agetty 38400 tty5 linux $P respawn setsid agetty 38400 tty6 linux service -U $target agetty-stop_cmd=fuser -k /dev/tty2 /dev/tty3 /dev/tty4 /dev/tty5 /dev/tty6 # Spawn qingys for tty[7] qingy-start:VEPservice -u: hostname-start utmp-start modules-start $devnodes-start $P /root/bin/touchpad.sh $P exec setsid /sbin/qingy tty7 & $P chvt 7 service -U $target qingy-stop_cmd=fuser -k /dev/tty7 # Spawn xorg on tty[7] xinit-start:VEPservice -u: mounts-start $P /root/bin/gpu $graphics | tee /root/gpu.log $P /root/bin/touchpad.sh $p chown andy:tty /dev/tty7 $p rm -f /usr/libexec/xf86-video-intel-backlight-helper $p exec su -l andy -c /home/andy/bin/xsession & service -U $target xinit-stop_cmd=fuser -k /dev/tty7 # Login records utmp-start:VPservice -u: fsclean-start for (i in /var/run/utmp /var/log/wtmp) { $P eval 'echo -n > $i' $P chgrp utmp $i $P chmod 0664 $i } service -U $target utmp-stop_cmd=halt -w # CPU freq cpufreq-start:VPservice -u: mounts-start $P cpupower frequency-set -g ondemand service -U $target # Localhost localhost-start_cmd=ifconfig lo 127.0.0.1 localhost-stop_cmd=ifconfig lo down # Set hostname hostname-start_cmd=hostname # Power management power-start:VPservice -u: mounts-start echo 1 | $P tee /sys/module/snd_hda_intel/parameters/power_save echo min_power | $P tee /sys/class/scsi_host/*/link_power_management_policy echo auto | $P tee /sys/bus/usb/devices/*/power/control echo auto | $P tee /sys/bus/pci/devices/*/power/control echo 1500 | $P tee /proc/sys/vm/dirty_writeback_centisecs service -U $target # Kernel parameters sysctl-start:VPservice -u: mounts-start $P sysctl -p $P chmod a+w /sys/class/leds/smc::kbd_backlight/brightness $P chmod a+w /sys/class/backlight/gmux_backlight/brightness $P chmod a+w /sys/devices/platform/applesmc.768/fan[12]_manual $P chmod a+w /sys/devices/platform/applesmc.768/fan[12]_output service -U $target # System # ------- at-start:VPservice -u: fsclean-start $P atd service -U $target at-stop_cmd=pkill atd cron-start:VPservice -u: localhost-start fsclean-start $P crond service -U $target cron-stop_cmd=pkill cron hddtemp-start_cmd=hddtemp -d hddtemp-stop_cmd=pkill hddtemp hwclock-start_cmd=hwclock --hctosys --utc hwclock-stop_cmd=hwclock --systohc --utc mdadm-start_cmd=mdadm --monitor --scan --daemonize mdadm-stop_cmd=pkill mdadm smartd-start_cmd=smartd smartd-stop_cmd=pkill smartd sshd-start_cmd=/usr/sbin/sshd sshd-stop_cmd=pkill sshd swap-start_cmd=swapon -a swap-stop_cmd=swapoff -a syslog-start:VPservice -u: mounts-start $P syslog-ng service -U $target syslog-stop_cmd=pkill syslog # Desktop # ------- alsa-start:VPservice -u: boot $P modprobe snd-hda-intel $P modprobe snd-usb-audio $P sleep 0.1 $P alsactl restore service -U $target alsa-stop_cmd=alsactl store bluez-start:VPservice -u: dbus-start $P modprobe btusb $P modprobe hidp $P hciconfig hci0 up $P exec /usr/libexec/bluetooth/bluetoothd & service -U $target bluez-stop_cmd=pkill bluetoothd cups-start_cmd=cupsd cups-stop_cmd=pkill cupsd dbus-start:VPservice -u: fsclean-start localhost-start $P install -m 1777 -d /var/run/dbus $P /usr/bin/dbus-daemon --system service -U $target dbus-stop_cmd=pkill dbus-daemon gpm-start_cmd=gpm -m /dev/input/mice -t ps2 gpm-stop_cmd=pkill gpm gpsd-start_cmd=gpsd tcp://localhost:2222 gpsd-stop_cmd=pkill gpsd keymap-start_cmd=loadkeys -u us-cc polipo-start:VPservice -u: localhost-start $P polipo service -U $target polipo-stop_cmd=pkill polipo # Server # ------ apache2-start:VPservice -u: fsclean-start $P install -o apache -g apache -d /var/run/session $P install -o apache -g apache -d /run/apache_ssl_mutex $P apache2 $(apache2-opts) service -U $target apache2-stop_cmd=pkill apache2 bitlbee-start_cmd=bitlbee -D -u bitlbee bitlbee-stop_cmd=pkill bitlbee cups-start_cmd=cupsd cups-stop_cmd=pkill cupsd denyhosts-start_cmd=denyhosts.py --daemon denyhosts-stop_cmd=pkill denyhosts.py courier-start:VPservice -u: fsclean-start $P install -o mail -g mail -d /var/run/courier $P authdaemond start $P courier start $P courierfilter start $P courier-imapd-ssl start service -U $target courier-stop_cmd=pkill '(courier|authdaemon)' dioc-start:VPservice -u: munged-start $P mount -n /mnt/c $P mount -n /mnt/c/mnt/x service -U $target dioc-stop:EVPservice -d: $P umount /mnt/c/mnt/x $P umount /mnt/c service -D $target diod-start:VPservice -u: munged-start $P diod --export-all service -U $target diod-stop_cmd=pkill diod docker-start_cmd=docker docker-stop_cmd=pkill docker dovecot-start_cmd=dovecot dovecot-stop_cmd=pkill dovecot eth0-start_cmd=dhcpcd eth0 -4 -A eth0-stop_cmd=dhcpcd eth0 -k exim-start_cmd=exim -bd -q5m exim-stop_cmd=pkill exim fail2ban-start:VPservice -u: boot $P mkdir -p /run/fail2ban $P fail2ban-client start service -U $target fail2ban-stop_cmd=fail2ban-client stop gitd-start_cmd=git daemon \ '--detach' \ '--syslog' \ '--export-all' \ '--user-path=git' \ '--interpolated-path=/etc/git/%H%D' \ '--listen=0.0.0.0' \ '--user=nobody' \ '--group=nobody' gitd-stop_cmd=pkill git-daemon iptables-start:VPservice -u: boot $P iptables-restore < /var/lib/iptables/rules-save service -U $target iptables-stop:EVPservice -d: $P iptables-save > /var/lib/iptables/rules-save service -D $target jabberd-start_cmd=sudo -u jabber -g jabber jabberd-andy -b jabberd-stop_cmd=pkill --uid jabber mailman-start_cmd=sudo -u mailman -g mailman \ /usr/lib64/mailman/bin/mailmanctl -s start mailman-stop_cmd=sudo -u mailman -g mailman \ /usr/lib64/mailman/bin/mailmanctl stop minidlna-start:VPservice -u: mounts-start $P install -o minidlna -g minidlna -d /var/run/minidlna $P install -o minidlna -g minidlna -d /var/cache/minidlna $P sudo -u minidlna -g minidlna minidlnad service -U $target minidlna-stop_cmd=pkill minidlnad munged-start:VPservice -u: localhost-start mounts-start $P install -o munge -g munge -d /var/run/munge $P sudo -u munge -g munge munged service -U $target munged-stop_cmd=pkill munged mysql-start:VPservice -u: fsclean-start $P install -o mysql -g mysql -d /var/run/mysqld $P exec mysqld & service -U $target mysql-stop_cmd=pkill mysqld ntpd-start_cmd=ntpd ntpd-stop_cmd=pkill ntpd privoxy-start_cmd=privoxy --user privoxy.privoxy /etc/privoxy/config privoxy-stop_cmd=pkill privoxy rngd-start_cmd=rngd -b -s64 -W2048 rngd-stop_cmd=pkill rngd sasl-start_cmd=saslauthd -n0 -ashadow sasl-stop_cmd=pkill saslauthd spamd-start_cmd=spamd -u spamd -d spamd-stop_cmd=pkill spamd tftpd-start_cmd=in.tftpd -s -l /img/boot tftpd-stop_cmd= tor-start:VPservice -u: boot $P exec tor & service -U $target tor-stop_cmd=pkill tor unifi-start:VPservice -u: wpa-start cd /usr/lib/unifi exec java -jar lib/ace.jar start & unifi-stop:EVPservice -d: cd /usr/lib/unifi java -jar lib/ace.jar stop service -D $target ventrilo-opts=-f/opt/ventrilo-server/ventrilo_srv -d ventrilo-start_cmd=sudo -u ventrilo -g ventrilo /opt/ventrilo-server/ventrilo_srv ventrilo-stop_cmd=pkill -u ventrilo vpn-start:VPservice -u: localhost-start $P ipsec start $P exec /usr/sbin/rp-l2tpd & $P exec /usr/sbin/pptpd & service -U $target vpn-stop:VQPservice -d: / $P pkill rp-l2tpd $P pkill pptpd $P ipsec stop service -D $target wlan0-start:VPservice -u: wpa-start $P dhcpcd -4 wlan0 service -U $target wlan0-stop_cmd=dhcpcd wlan0 -k wpa-start:VPservice -u: $devnodes-start $P modprobe brcmfmac && sleep 1 $P exec wpa_supplicant -Dnl80211 -iwlan0 -c/etc/wpa_supplicant.conf & service -U $target wpa-stop_cmd=pkill wpa # Library # ------- %-start:QVPservice -u: boot if (~ $#($stem^-start_cmd) 0) echo No such service $stem && exit 0 $P $($stem^-start_cmd) $($stem^-opts) service -U $target %-stop:QVPservice -d: / if (~ $#($stem^-stop_cmd) 0) echo No such service $stem if not $P $($stem^-stop_cmd) service -D $target %-zap:QVPservice -d: / service -D $target %-status:QV: service -q $target