]> Pileus Git - mkinit/blob - services.mk
a1c7977d122a992a0dc676c73723b947a35f6bb4
[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 reboot -ndfk
21
22 # Initial setup/shutdown for mkinit
23 boot:VEPservice -u: /
24         echo Starting init
25         $P mount -o remount,rw /
26         # mount proc here to make bootchart happier
27         $P mount -t proc proc /proc
28         service -F
29         service -U $target
30
31 # Kill all process, then remount and sync
32 halt:QVE: utmp-stop hwclock-stop alsa-stop
33         echo TERMinating all processes
34         $P pkill -15 --inverse -g0 >/dev/null >[2=1]
35         for (i in 1 2 3 4 5)
36                 { $P pgrep -vg0 && $P sleep 1 }
37         echo KILLing all processes
38         $P pkill  -9 --inverse -g0 >/dev/null >[2=1]
39         for (i in 1 2 3)
40                 { $P pgrep -vg0 && $P sleep 1 }
41         service -F
42         echo Remounting read-only
43         $P mount -o remount,ro /
44         $P sync
45
46 # Bare
47 # ----
48 # Listener for /dev/initctl, for shutdown(8)
49 initctl-start:VPservice -u: boot
50         fifo=/dev/initctl
51         if (! test -e $fifo)
52                 $P mkfifo $fifo
53         { exec $P initctld $fifo |
54           while(line=`{line})
55                 $P mkinit $line >/dev/console >[2=1] 
56         } &
57         service -U $target
58 initctl-stop_cmd=fuser -k /dev/initctl
59
60 # Proc, mtab, fstab
61 mounts-start:VPservice -u: boot
62         $P cp /proc/mounts /etc/mtab
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 gettys for tty[23456]
106 getty-start:VEPservice -u: hostname-start utmp-start
107         $P respawn setsid agetty 38400 tty2 linux
108         $P respawn setsid agetty 38400 tty3 linux
109         $P respawn setsid agetty 38400 tty4 linux
110         $P respawn setsid agetty 38400 tty5 linux
111         $P respawn setsid agetty 38400 tty6 linux
112         service -U $target
113 getty-stop_cmd=fuser -k /dev/tty2 /dev/tty3 /dev/tty4 /dev/tty5 /dev/tty6
114
115 # Spawn qingys for tty[7]
116 qingy-start:VEPservice -u: hostname-start utmp-start modules-start
117         $P respawn setsid /sbin/qingy-DirectFB tty7 &
118         $P chvt 7
119         service -U $target
120 qingy-stop_cmd=fuser -k /dev/tty7
121
122 # Login records
123 utmp-start:VPservice -u: fsclean-start
124         for (i in /var/run/utmp /var/log/wtmp) {
125                 $P eval 'echo -n > $i'
126                 $P chgrp utmp $i
127                 $P chmod 0664 $i
128         }
129         service -U $target
130 utmp-stop_cmd=halt -w
131
132 # CPU freq
133 cpufreq-start:VPservice -u: mounts-start
134         $P cpufreq-set -g ondemand
135         service -U $target
136
137 # Localhost
138 localhost-start_cmd=ifconfig lo 127.0.0.1
139 localhost-stop_cmd=ifconfig lo down
140
141 # Set hostname
142 hostname-start_cmd=hostname
143
144 # Kernel parameters
145 sysctl-start:VPservice -u: mounts-start
146         $P sysctl -p
147         $P chmod a+w /sys/class/leds/smc::kbd_backlight/brightness
148         $P chmod a+w /sys/class/backlight/gmux_backlight/brightness
149         service -U $target
150
151
152 # System
153 # -------
154 at-start_cmd=atd
155 at-stop_cmd=pkill atd
156
157 cron-start_cmd=cron
158 cron-stop_cmd=pkill cron
159
160 hddtemp-start_cmd=hddtemp -d
161 hddtemp-stop_cmd=pkill hddtemp
162
163 hwclock-start_cmd=hwclock --hctosys --utc
164 hwclock-stop_cmd=hwclock --systohc --utc
165
166 sshd-start_cmd=/usr/sbin/sshd
167 sshd-stop_cmd=pkill sshd
168
169 swap-start_cmd=swapon -a
170 swap-stop_cmd=swapoff -a
171
172 syslog-start:VPservice -u: mounts-start
173         $P syslog-ng
174         service -U $target
175 syslog-stop_cmd=pkill syslog
176
177
178 # Desktop
179 # -------
180 alsa-start_cmd=alsactl restore
181 alsa-stop_cmd=alsactl store
182
183 cups-start_cmd=cupsd
184 cups-stop_cmd=pkill cupsd
185
186 dbus-start:VPservice -u: fsclean-start localhost-start
187         $P install -m 1777 -d /var/run/dbus
188         $P /usr/bin/dbus-daemon --system
189         service -U $target
190 dbus-stop_cmd=pkill dbus-daemon
191
192 gpm-start_cmd=gpm -m /dev/input/mice -t ps2
193 gpm-stop_cmd=pkill gpm
194
195 gpsd-start_cmd=gpsd tcp://localhost:2222
196 gpsd-stop_cmd=pkill gpsd
197
198 keymap-start_cmd=loadkeys -u us-cc
199
200 polipo-start:VPservice -u: localhost-start
201         $P polipo
202         service -U $target
203 polipo-stop_cmd=pkill polipo
204
205
206 # Server
207 # ------
208 apache2-start:VPservice -u: fsclean-start
209         $P install -o apache -g apache -d /var/run/session
210         $P apache2 $apache2-opts
211 apache2-stop_cmd=pkill apache2
212
213 #bitlbee-start_cmd=sudo -u bitlbee bitlbeed /usr/sbin/bitlbee
214 bitlbee-start_cmd=bitlbee -D -u bitlbee
215 bitlbee-stop_cmd=pkill bitlbee
216
217 denyhosts-start_cmd=denyhosts.py --daemon
218 denyhosts-stop_cmd=pkill denyhosts.py
219
220 courier-start:VPservice -u: fsclean-start
221         $P install -o mail -g mail -d /var/run/courier
222         $P authdaemond       start
223         $P courier           start
224         $P courierfilter     start
225         $P courier-imapd-ssl start
226         service -U $target
227 courier-stop_cmd=pkill '(courier|authdaemon)'
228
229 dioc-start:VPservice -u: munged-start
230         $P mount -n /mnt/c
231         $P mount -n /mnt/c/mnt/x
232         service -U $target
233 dioc-stop:EVPservice -d:
234         $P umount /mnt/c/mnt/x
235         $P umount /mnt/c
236         service -D $target
237
238 diod-start:VPservice -u: munged-start
239         $P diod --export-all
240         service -U $target
241 diod-stop_cmd=pkill diod
242
243 dovecot-start_cmd=dovecot
244 dovecot-stop_cmd=pkill dovecot
245
246 eth0-start_cmd=dhcpcd eth0
247 eth0-stop_cmd=dhcpcd eth0 -k
248
249 exim-start_cmd=exim -bd -q5m
250 exim-stop_cmd=pkill exim
251
252 gitd-start:VPservice -u: boot
253         $P exec /usr/libexec/git-core/git-daemon \
254                 '--syslog' \
255                 '--export-all' \
256                 '--user-path=git' \
257                 '--interpolated-path=/etc/git/%H%D' \
258                 '--listen=0.0.0.0' \
259                 '--user=nobody' \
260                 '--group=nobody' &
261         service -U $target
262 gitd-stop_cmd=pkill git-daemon
263
264 mailman-start_cmd=sudo -u mailman -g mailman \
265         /usr/lib64/mailman/bin/mailmanctl -s start
266 mailman-stop_cmd=sudo -u mailman -g mailman \
267         /usr/lib64/mailman/bin/mailmanctl stop
268
269 munged-start:VPservice -u: boot
270         $P install -o munge -g munge -d /var/run/munge
271         $P sudo -u munge -g munge munged
272         service -U $target
273 munged-stop_cmd=pkill munged
274
275 mysql-start:VPservice -u: fsclean-start
276         $P install -o mysql -g mysql -d /var/run/mysqld
277         $P exec mysqld &
278         service -U $target
279 mysql-stop_cmd=pkill mysqld
280
281 ntpd-start_cmd=ntpd
282 ntpd-stop_cmd=pkill ntpd
283
284 privoxy-start_cmd=privoxy --user privoxy.privoxy /etc/privoxy/config
285 privoxy-stop_cmd=pkill privoxy
286
287 rngd-start_cmd=rngd -b -s64 -t60
288 rngd-stop_cmd=pkill rngd
289
290 spamd-start_cmd=spamd -u spamd -d
291 spamd-stop_cmd=pkill spamd
292
293 tftpd-start_cmd=in.tftpd -s -l /img/boot
294 tftpd-stop_cmd=
295
296 tor-start:VPservice -u: boot
297         $P exec tor &
298         service -U $target
299 tor-stop_cmd=pkill tor
300
301 wlan0-start:VPservice -u: wpa-start
302         $P dhcpcd wlan0
303         service -U $target
304 wlan0-stop_cmd=dhcpcd wlan0 -k
305
306 wpa-start:VPservice -u: mdev-start
307         $P modprobe b43
308         $P exec wpa_supplicant -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf &
309         service -U $target
310 wpa-stop_cmd=pkill wpa
311
312 # Library 
313 # -------
314 %-start:QVPservice -u: boot
315         if (~ $#($stem^-start_cmd) 0)
316                 echo No such service $stem && exit 0
317         $P $($stem^-start_cmd) $($stem^-opts)
318         service -U $target
319
320 %-stop:QVPservice -d: /
321         if (~ $#($stem^-stop_cmd) 0)
322                 echo No such service $stem
323         if not
324                 $P $($stem^-stop_cmd)
325         service -D $target
326
327 %-zap:QVPservice -d: /
328         service -D $target
329
330 %-status:QV:
331         service -q $target