]> Pileus Git - mkinit/blob - init.mk
(no commit message)
[mkinit] / init.mk
1 # Copyright (C) 2009 Andy Spencer
2 # See COPYING for terms
3
4 # Config
5 MKSHELL=/usr/lib/plan9/bin/rc
6 NPROC=10
7
8 # Example
9 #test-start:VQPservice -u: foo-start
10 #       echo starting test
11 #       service -U $target
12 #
13 #test-stop:VQPservice -d: /
14 #       echo stopping test
15 #       service -D $target
16
17 # Runlevels
18 user   = alsa keymap polipo spam dbus
19 system = at cron hddtemp hostname hwclock sshd swap syslog
20 bare   = cpufreq fsclean getty qingy initctl localhost modules mounts uevents utmp
21
22 default:V: user
23
24 user:V:   `{echo $user^-start $system^-start $bare^-start}
25 system:V: `{echo $user^-stop  $system^-start $bare^-start}
26 bare:V:   `{echo $user^-stop  $system^-stop  $bare^-start}
27 single:V: `{echo $user^-stop  $system^-stop  $bare^-stop }
28
29 poweroff:V: halt 
30         $P poweroff -ndf
31 reboot:V: halt
32         $P reboot -ndf
33 kexec:V: halt
34         $P reboot -ndfk
35
36 # Initial setup/shutdown for mkinit
37 boot:VEPservice -u: /
38         echo Starting init
39         $P mount -o remount,rw /
40         # mount proc here to make bootchart happier
41         $P mount -t proc proc /proc
42         service -F
43         service -U $target
44
45 # Kill all process, then remount and sync
46 halt:QVE: utmp-stop hwclock-stop alsa-stop
47         echo TERMinating all processes
48         $P pkill -15 -vg0 >/dev/null >[2=1]
49         for (i in 1 2 3 4 5)
50                 $P pgrep -vg0 >/dev/null >[2=1] && $P sleep 1
51         echo KILLing all processes
52         $P pkill  -9 -vg0 >/dev/null >[2=1]
53         for (i in 1 2 3)
54                 $P pgrep -vg0 >/dev/null >[2=1] && $P sleep 1
55         service -F
56         echo Remounting read-only
57         $P mount -o remount,ro /
58         $P sync
59
60 # Bare
61 # ----
62 # Listener for /dev/initctl, for shutdown(8)
63 initctl-start:VPservice -u: boot
64         fifo=/dev/initctl
65         if (! test -e $fifo)
66                 $P mkfifo $fifo
67         { exec $P initctld $fifo |
68           while(line=`{line})
69                 $P mkinit $line >/dev/console >[2=1] 
70         } &
71         service -U $target
72 initctl-stop_cmd=fuser -k /dev/initctl
73
74 # Proc, mtab, udev, fstab
75 mounts-start:VPservice -u: boot
76         $P cp /proc/mounts /etc/mtab
77         $P udevd --daemon
78         $P mount -a
79         service -U $target
80
81 # Load kernel modules
82 modules-start:VEPservice -u: boot
83         $P modprobe uvesafb
84         service -U $target
85
86 # Trigger udev uevents
87 uevents-start:VEPservice -u:  mounts-start
88         $P udevadm trigger
89         $P udevadm settle '--timeout=10'
90         service -U $target
91
92 # Clean out /tmp and /var/run directories
93 fsclean-start:VPservice -u: boot
94         dirs=(/var/run /tmp)
95         $P mkdir -p /.old
96         $P mv $dirs /.old
97         $P mkdir -p $dirs
98         $P chmod 1777 /tmp
99         $P exec rm -rf /.old &
100         service -U $target
101
102 # Spawn gettys for tty[456]
103 getty-start:VEPservice -u: hostname-start utmp-start
104         $P respawn /sbin/agetty 38400 tty4 linux
105         $P respawn /sbin/agetty 38400 tty5 linux
106         $P respawn /sbin/agetty 38400 tty6 linux
107         service -U $target
108 getty-stop_cmd=fuser -k /dev/tty4 /dev/tty5 /dev/tty6
109
110 # Spawn qingys for tty[23]
111 qingy-start:VEPservice -u: hostname-start utmp-start modules-start uevents-start
112         $P respawn /sbin/qingy tty2
113         $P respawn /sbin/qingy tty3
114         service -U $target
115 qingy-stop_cmd=fuser -k /dev/tty2 /dev/tty3
116
117 # Login records
118 utmp-start:VPservice -u: fsclean-start
119         for (i in /var/run/utmp /var/log/wtmp) {
120                 $P eval 'echo -n > $i'
121                 $P chgrp utmp $i
122                 $P chmod 0664 $i
123         }
124         service -U $target
125 utmp-stop_cmd=halt -w
126
127 # CPU freq
128 cpufreq-start:VPservice -u: uevents-start
129         $P cpufreq-set -g ondemand
130         service -U $target
131
132 # Keymap (us-cc = us with ctrl-capslock switched)
133 keymap-start_cmd=loadkeys -u us-cc
134
135 # Localhost
136 localhost-start_cmd=ifconfig lo 127.0.0.1
137 localhost-stop_cmd=ifconfig lo down
138
139 # Set hostname
140 hostname-start_cmd=hostname b
141
142 # Kernel parameters
143 sysctl-start_cmd=sysctl -p
144
145
146 # Console
147 # -------
148 at-start_cmd=atd
149 at-stop_cmd=pkill atd
150
151 cron-start_cmd=cron
152 cron-stop_cmd=pkill cron
153
154 hwclock-start_cmd=hwclock --hctosys --utc
155 hwclock-stop_cmd=hwclock --systohc --utc
156
157 swap-start_cmd=swapon -a
158 swap-stop_cmd=swapoff -a
159
160 syslog-start:VPservice -u: mounts-start
161         $P syslog-ng
162         service -U $target
163 syslog-stop_cmd=pkill syslog
164
165 hddtemp-start:VPservice -u: localhost-start
166         $P hddtemp -d -l 127.0.0.1 /dev/sda
167         service -U $target
168 hddtemp-stop_cmd=pkill hddtemp
169
170
171 # Desktop
172 # -------
173 alsa-start_cmd=alsactl restore
174 alsa-stop_cmd=alsactl store
175
176 sshd-start_cmd=/usr/sbin/sshd
177 sshd-stop_cmd=pkill sshd
178
179 dbus-start:VPservice -u: fsclean-start localhost-start
180         $P mkdir -p /var/run/dbus
181         $P /usr/bin/dbus-daemon --system
182         service -U $target
183 dbus-stop_cmd=pkill dbus-daemon
184
185 spam-start:VPservice -u: localhost-start
186         $P spamd -d
187         service -U $target
188 spam-stop_cmd=pkill spamd
189
190 polipo-start:VPservice -u: localhost-start
191         $P polipo
192         service -U $target
193 polipo-stop_cmd=pkill polipo
194
195
196 # Library 
197 # -------
198 %-start:VPservice -u: boot
199         if (~ $#($stem^-start_cmd) 0)
200                 exit 0
201         $P $($stem^-start_cmd)
202         service -U $target
203
204 %-stop:VPservice -d: /
205         if (~ $#($stem^-stop_cmd) 0)
206                 exit 0
207         $P $($stem^-stop_cmd)
208         service -D $target
209
210 %-zap:VPservice -d: /
211         service -D $target
212
213 %-status:V:
214         service -q $target