-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathchroot-rc-script
52 lines (38 loc) · 1.42 KB
/
chroot-rc-script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/sbin/runscript
# This file shoud be saved to /etc/init.d/chroot
depend() {
need localmount
need bootmisc
}
checkconfig() {
if [ "${SVCNAME}" = "chroot" ] ; then
eerror "Template file cannot be used directly. Create the symlink"
eerror "/etc/init.d/${SVCNAME}.service -> /etc/init.d/${SVCNAME}"
eerror "and use that instead"
return 1
fi
CHROOT="/chroot/${SVCNAME##chroot.}"
if [ ! -d "${CHROOT}" ] ; then
eerror "Directory ${CHROOT} not found"
return 1
fi
}
start() {
checkconfig || return 1
ebegin "Starting ${SVCNAME}"
mountinfo -q ${CHROOT}/proc || mount -t proc proc ${CHROOT}/proc || eerror "Error mounting ${CHROOT}/proc" || return 1
mountinfo -q ${CHROOT}/sys || mount --rbind /sys ${CHROOT}/sys || eerror "Error mounting ${CHROOT}/sys" || return 1
mountinfo -q ${CHROOT}/dev || mount --rbind /dev ${CHROOT}/dev || eerror "Error mounting ${CHROOT}/dev" || return 1
mountinfo -q ${CHROOT}/tmp || mount --bind /tmp ${CHROOT}/tmp || eerror "Error mounting ${CHROOT}/tmp" || return 1
eend 0
}
stop() {
checkconfig || return 1
ebegin "Stopping ${SVCNAME}"
mountinfo -q ${CHROOT}/tmp && umount -l ${CHROOT}/tmp
mountinfo -q ${CHROOT}/dev && umount -l ${CHROOT}/dev{/shm,/pts,}
mountinfo -q ${CHROOT}/sys && umount -l ${CHROOT}/sys
mountinfo -q ${CHROOT}/proc && umount -l ${CHROOT}/proc
mountinfo -q -p ${CHROOT} && eend 1 "An error occurred while unmounting chroot directories"
eend 0
}