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