]> Pileus Git - mkinit/blob - services.mk
3f69b57d1db4d948f5110db79fdc9bda18ca0478
[mkinit] / services.mk
1 MKSHELL=/opt/plan9/bin/rc
2
3 # Example
4 #test-start:VQPservice -u: foo-start
5 #       echo starting test
6 #       service -U $target
7 #
8 #test-stop:VQPservice -d: /
9 #       echo stopping test
10 #       service -D $target
11
12 # Core commands
13 # -------------
14 # Reboot commands
15 poweroff:V: halt 
16         $P poweroff -ndf
17 reboot:V: halt
18         $P reboot -ndf
19 kexec:V: halt
20         $P kexec -l /usr/src/linux/arch/x86/boot/bzImage --reuse-cmdline
21         $P kexec -e
22
23 # Initial setup/shutdown for mkinit
24 boot:VEPservice -u: /
25         echo Starting init
26         $P mount -o remount,rw /
27         # mount proc here to make bootchart happier
28         $P mount -t proc proc /proc
29         service -F
30         service -U $target
31
32 # Kill all process, then remount and sync
33 halt:QVE: utmp-stop hwclock-stop alsa-stop
34         echo TERMinating all processes
35         $P pkill -15 --inverse -g0 >/dev/null >[2=1]
36         for (i in 1 2 3 4 5)
37                 { $P pgrep -vg0 && $P sleep 1 }
38         echo KILLing all processes
39         $P pkill  -9 --inverse -g0 >/dev/null >[2=1]
40         for (i in 1 2 3)
41                 { $P pgrep -vg0 && $P sleep 1 }
42         service -F
43         echo Remounting read-only
44         $P mount -o remount,ro /
45         $P sync
46
47 # Bare
48 # ----
49 # Listener for /dev/initctl, for shutdown(8)
50 initctl-start:VPservice -u: boot
51         fifo=/dev/initctl
52         if (! test -e $fifo)
53                 $P mkfifo $fifo
54         { exec $P initctld $fifo |
55           while(line=`{line})
56                 $P mkinit $line >/dev/console >[2=1] 
57         } &
58         service -U $target
59 initctl-stop_cmd=fuser -k /dev/initctl
60
61 # Proc, mtab, fstab
62 mounts-start:VPservice -u: boot
63         $P mdadm -A /dev/md4 /dev/sd[abc]4
64         $P mount -a
65         service -U $target
66
67 # Mount devtmpfs and shm/pts subfolders
68 devtmpfs-start:VEPservice -u: boot
69         $P mount /dev
70         $P mkdir /dev/shm
71         $P mkdir /dev/pts
72         service -U $target
73
74 # Start mdev as initial/daemon
75 mdev-start:VEPservice -u: mounts-start
76         $P echo /sbin/mdev > /proc/sys/kernel/hotplug
77         $P mdev -s
78         service -U $target
79
80 # Start udev and trigger events
81 udev-start:VEPservice -u:  mounts-start
82         $P udevd --daemon
83         $P udevadm trigger
84         $P udevadm settle '--timeout=10'
85         service -U $target
86 udev-stop_cmd=pkill udevd
87
88 # Load kernel modules
89 modules-start:VEPservice -u: boot
90         $P modprobe uvesafb
91         $P modprobe evdev
92         service -U $target
93
94 # Clean out /tmp and /var/run directories
95 fsclean-start:VPservice -u: boot
96         dirs=(/var/run /tmp)
97         $P mkdir -p /.old
98         $P mv $dirs /.old || true
99         $P mkdir -p $dirs
100         $P chmod 1777 /tmp
101         $P install -m 1777 -d /var/run/screen # Fuck you Screen
102         $P exec rm -rf /.old &
103         service -U $target
104
105 # Spawn gettyd for tty[23456]
106 gettyd-start:VEPservice -u: hostname-start utmp-start
107         $P exec gettyd tty2 tty3 tty4 tty5 tty6 &
108         service -U $target
109 gettyd-stop_cmd=fuser -k /dev/tty2 /dev/tty3 /dev/tty4 /dev/tty5 /dev/tty6
110
111 # Spawn agettys for tty[23456]
112 agetty-start:VEPservice -u: hostname-start utmp-start
113         $P respawn setsid agetty 38400 tty2 linux
114         $P respawn setsid agetty 38400 tty3 linux
115         $P respawn setsid agetty 38400 tty4 linux
116         $P respawn setsid agetty 38400 tty5 linux
117         $P respawn setsid agetty 38400 tty6 linux
118         service -U $target
119 agetty-stop_cmd=fuser -k /dev/tty2 /dev/tty3 /dev/tty4 /dev/tty5 /dev/tty6
120
121 # Spawn qingys for tty[7]
122 qingy-start:VEPservice -u: hostname-start utmp-start modules-start
123         $P respawn setsid /sbin/qingy-DirectFB tty7 &
124         $P chvt 7
125         service -U $target
126 qingy-stop_cmd=fuser -k /dev/tty7
127
128 # Login records
129 utmp-start:VPservice -u: fsclean-start
130         for (i in /var/run/utmp /var/log/wtmp) {
131                 $P eval 'echo -n > $i'
132                 $P chgrp utmp $i
133                 $P chmod 0664 $i
134         }
135         service -U $target
136 utmp-stop_cmd=halt -w
137
138 # CPU freq
139 cpufreq-start:VPservice -u: mounts-start
140         $P cpufreq-set -g ondemand
141         service -U $target
142
143 # Localhost
144 localhost-start_cmd=ifconfig lo 127.0.0.1
145 localhost-stop_cmd=ifconfig lo down
146
147 # Set hostname
148 hostname-start_cmd=hostname
149
150 # Kernel parameters
151 sysctl-start:VPservice -u: mounts-start
152         $P sysctl -p
153         $P chmod a+w /sys/class/leds/smc::kbd_backlight/brightness
154         $P chmod a+w /sys/class/backlight/gmux_backlight/brightness
155         service -U $target
156
157
158 # System
159 # -------
160 at-start_cmd=atd
161 at-stop_cmd=pkill atd
162
163 cron-start:VPservice -u: localhost-start fsclean-start
164         $P cron
165         service -U $target
166 cron-stop_cmd=pkill cron
167
168 hddtemp-start_cmd=hddtemp -d
169 hddtemp-stop_cmd=pkill hddtemp
170
171 hwclock-start_cmd=hwclock --hctosys --utc
172 hwclock-stop_cmd=hwclock --systohc --utc
173
174 mdadm-start_cmd=mdadm --monitor --scan --daemonize
175 mdadm-stop_cmd=pkill mdadm
176
177 smartd-start_cmd=smartd
178 smartd-stop_cmd=pkill smartd
179
180 sshd-start_cmd=/usr/sbin/sshd
181 sshd-stop_cmd=pkill sshd
182
183 swap-start_cmd=swapon -a
184 swap-stop_cmd=swapoff -a
185
186 syslog-start:VPservice -u: mounts-start
187         $P syslog-ng
188         service -U $target
189 syslog-stop_cmd=pkill syslog
190
191
192 # Desktop
193 # -------
194 alsa-start_cmd=alsactl restore
195 alsa-stop_cmd=alsactl store
196
197 cups-start_cmd=cupsd
198 cups-stop_cmd=pkill cupsd
199
200 dbus-start:VPservice -u: fsclean-start localhost-start
201         $P install -m 1777 -d /var/run/dbus
202         $P /usr/bin/dbus-daemon --system
203         service -U $target
204 dbus-stop_cmd=pkill dbus-daemon
205
206 gpm-start_cmd=gpm -m /dev/input/mice -t ps2
207 gpm-stop_cmd=pkill gpm
208
209 gpsd-start_cmd=gpsd tcp://localhost:2222
210 gpsd-stop_cmd=pkill gpsd
211
212 keymap-start_cmd=loadkeys -u us-cc
213
214 polipo-start:VPservice -u: localhost-start
215         $P polipo
216         service -U $target
217 polipo-stop_cmd=pkill polipo
218
219
220 # Server
221 # ------
222 apache2-start:VPservice -u: fsclean-start
223         $P install -o apache -g apache -d /var/run/session
224         $P apache2 $(apache2-opts)
225         service -U $target
226 apache2-stop_cmd=pkill apache2
227
228 #bitlbee-start_cmd=sudo -u bitlbee bitlbeed /usr/sbin/bitlbee
229 bitlbee-start_cmd=bitlbee -D -u bitlbee
230 bitlbee-stop_cmd=pkill bitlbee
231
232 cups-start_cmd=cupsd
233 cups-stop_cmd=pkill cupsd
234
235 denyhosts-start_cmd=denyhosts.py --daemon
236 denyhosts-stop_cmd=pkill denyhosts.py
237
238 courier-start:VPservice -u: fsclean-start
239         $P install -o mail -g mail -d /var/run/courier
240         $P authdaemond       start
241         $P courier           start
242         $P courierfilter     start
243         $P courier-imapd-ssl start
244         service -U $target
245 courier-stop_cmd=pkill '(courier|authdaemon)'
246
247 dioc-start:VPservice -u: munged-start
248         $P mount -n /mnt/c
249         $P mount -n /mnt/c/mnt/x
250         service -U $target
251 dioc-stop:EVPservice -d:
252         $P umount /mnt/c/mnt/x
253         $P umount /mnt/c
254         service -D $target
255
256 diod-start:VPservice -u: munged-start
257         $P diod --export-all
258         service -U $target
259 diod-stop_cmd=pkill diod
260
261 dovecot-start_cmd=dovecot
262 dovecot-stop_cmd=pkill dovecot
263
264 eth0-start_cmd=dhcpcd eth0
265 eth0-stop_cmd=dhcpcd eth0 -k
266
267 exim-start_cmd=exim -bd -q5m
268 exim-stop_cmd=pkill exim
269
270 gitd-start:VPservice -u: boot
271         $P exec /usr/libexec/git-core/git-daemon \
272                 '--syslog' \
273                 '--export-all' \
274                 '--user-path=git' \
275                 '--interpolated-path=/etc/git/%H%D' \
276                 '--listen=0.0.0.0' \
277                 '--user=nobody' \
278                 '--group=nobody' &
279         service -U $target
280 gitd-stop_cmd=pkill git-daemon
281
282 jabberd-start_cmd=sudo -u jabber -g jabber jabberd -b
283 jabberd-stop_cmd=pkill --uid jabber
284
285 mailman-start_cmd=sudo -u mailman -g mailman \
286         /usr/lib64/mailman/bin/mailmanctl -s start
287 mailman-stop_cmd=sudo -u mailman -g mailman \
288         /usr/lib64/mailman/bin/mailmanctl stop
289
290 munged-start:VPservice -u: localhost-start mounts-start
291         $P install -o munge -g munge -d /var/run/munge
292         $P sudo -u munge -g munge munged
293         service -U $target
294 munged-stop_cmd=pkill munged
295
296 mysql-start:VPservice -u: fsclean-start
297         $P install -o mysql -g mysql -d /var/run/mysqld
298         $P exec mysqld &
299         service -U $target
300 mysql-stop_cmd=pkill mysqld
301
302 ntpd-start_cmd=ntpd
303 ntpd-stop_cmd=pkill ntpd
304
305 privoxy-start_cmd=privoxy --user privoxy.privoxy /etc/privoxy/config
306 privoxy-stop_cmd=pkill privoxy
307
308 rngd-start_cmd=rngd -b -s64 -t60
309 rngd-stop_cmd=pkill rngd
310
311 spamd-start_cmd=spamd -u spamd -d
312 spamd-stop_cmd=pkill spamd
313
314 tftpd-start_cmd=in.tftpd -s -l /img/boot
315 tftpd-stop_cmd=
316
317 tor-start:VPservice -u: boot
318         $P exec tor &
319         service -U $target
320 tor-stop_cmd=pkill tor
321
322 wlan0-start:VPservice -u: wpa-start
323         $P dhcpcd wlan0
324         service -U $target
325 wlan0-stop_cmd=dhcpcd wlan0 -k
326
327 wpa-start:VPservice -u: mdev-start
328         $P modprobe b43
329         $P exec wpa_supplicant -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf &
330         service -U $target
331 wpa-stop_cmd=pkill wpa
332
333 # Library 
334 # -------
335 %-start:QVPservice -u: boot
336         if (~ $#($stem^-start_cmd) 0)
337                 echo No such service $stem && exit 0
338         $P $($stem^-start_cmd) $($stem^-opts)
339         service -U $target
340
341 %-stop:QVPservice -d: /
342         if (~ $#($stem^-stop_cmd) 0)
343                 echo No such service $stem
344         if not
345                 $P $($stem^-stop_cmd)
346         service -D $target
347
348 %-zap:QVPservice -d: /
349         service -D $target
350
351 %-status:QV:
352         service -q $target