4 . $basedir/../tests/suite
6 if head -1 debian/changelog | grep -q UNRELEASED ; then
14 cat <<'EOF' > $insconf
15 $local_fs +mountall +umountfs
16 $network +networking +ifupdown
17 $named +named +dnsmasq +lwresd +bind9 $network
18 $remote_fs $local_fs +mountnfs +mountnfs-bootclean +umountnfs +sendsigs
19 $syslog +syslog +sysklogd
22 <interactive> udev mountdevsubfs checkroot checkfs console-screen
26 ##########################################################################
27 test_normal_sequence() {
29 echo "info: test normal boot sequence scripts, and their order"
32 insertscript mountkernfs.sh <<'EOF'
34 # Provides: mountkernfs
43 insertscript mountdevsubfs.sh <<'EOF'
45 # Provides: mountdevsubfs mountvirtfs
46 # Required-Start: mountkernfs
54 insertscript checkroot.sh <<'EOF'
57 # Required-Start: mountdevsubfs
59 # Should-Start: keymap hwclockfirst
66 insertscript ifupdown-clean <<'EOF'
68 # Provides: ifupdown-clean
69 # Required-Start: checkroot
76 insertscript ifupdown <<'EOF'
79 # Required-Start: ifupdown-clean
80 # Required-Stop: $local_fs
86 insertscript checkfs.sh <<'EOF'
89 # Required-Start: checkroot
91 # Should-Start: lvm cryptdisks
98 insertscript mountall.sh <<'EOF'
101 # Required-Start: checkfs
110 insertscript mountnfs.sh <<'EOF'
113 # Required-Start: $local_fs
115 # Should-Start: $network
121 insertscript beforenfs <<'EOF'
123 # Provides: beforenfs
124 # Required-Start: $local_fs
126 # X-Start-Before: mountnfs
132 insertscript hwclock.sh <<'EOF'
135 # Required-Start: mountdevsubfs
136 # Required-Stop: $local_fs
142 insertscript killprocs <<'EOF'
144 # Provides: killprocs
145 # Required-Start: $local_fs
152 insertscript single <<'EOF'
155 # Required-Start: $local_fs killprocs $all
162 insertscript needlocalfs <<'EOF'
164 # Provides: needlocalfs
165 # Required-Start: $local_fs
166 # Required-Stop: $local_fs
167 # Default-Start: 2 3 4 5
168 # Default-Stop: 0 1 6
172 insertscript needallfs <<'EOF'
174 # Provides: needallfs
175 # Required-Start: $remote_fs
176 # Required-Stop: $remote_fs
177 # Default-Start: 2 3 4 5
178 # Default-Stop: 0 1 6
182 insertscript sysklogd <<'EOF'
185 # Required-Start: $remote_fs
186 # Required-Stop: $remote_fs
187 # Default-Start: 2 3 4 5
188 # Default-Stop: 0 1 6
192 insertscript reboot <<'EOF'
202 insertscript halt <<'EOF'
212 insertscript umountroot <<'EOF'
214 # Provides: umountroot
217 # Should-Stop: halt reboot
223 insertscript umountfs <<'EOF'
227 # Required-Stop: umountroot
233 insertscript umountnfs <<'EOF'
235 # Provides: umountnfs
237 # Required-Stop: umountfs
238 # Should-Stop: $network $portmap nfs-common
244 insertscript needallfs2 <<'EOF'
246 # Provides: needallfs2
247 # Required-Start: $remote_fs
248 # Required-Stop: $remote_fs
249 # X-Start-Before: needallfs
250 # Default-Start: 2 3 4 5
251 # Default-Stop: 0 1 6
255 insertscript kexec <<'EOF'
259 # Required-Stop: reboot
260 # X-Stop-After: umountroot
266 insertscript networking <<'EOF'
268 # Provides: networking
269 # Required-Start: mountkernfs ifupdown $local_fs
270 # Required-Stop: ifupdown $local_fs
276 insertscript nolsbheader <<'EOF'
281 check_order S mountkernfs.sh mountdevsubfs.sh
282 check_order S ifupdown-clean ifupdown
283 check_order S ifupdown-clean ifupdown
284 check_order S mountall.sh mountnfs.sh
285 check_order S mountall.sh beforenfs
286 check_order S beforenfs mountnfs.sh
288 check_order 0 needallfs umountnfs
289 check_order 0 umountroot halt
291 check_order 1 killprocs single
292 check_order 1 needallfs killprocs
294 check_order 2 needlocalfs needallfs
295 check_order 2 needlocalfs nolsbheader
296 check_order 2 sysklogd nolsbheader
297 check_order 2 needallfs2 needallfs
299 check_order 6 needallfs umountnfs
300 check_order 6 nolsbheader umountnfs
301 check_order 6 umountfs umountroot
302 check_order 6 umountnfs networking
303 check_order 6 networking ifupdown
304 check_order 6 umountnfs umountfs
305 check_order 6 umountroot reboot
306 check_order 6 umountroot kexec
307 check_order 6 kexec reboot
309 ##########################################################################
310 test_override_files() {
312 echo "info: test if override files replace headers in the file"
317 # Two scripts with a loop between them
318 insertscript base <<'EOF' || true
328 insertscript mover <<'EOF' || true
331 # Required-Start: base
338 check_order S base mover
340 mkdir -p $overridedir
341 cat <<'EOF' > $overridedir/mover
346 # X-Start-Before: base
356 # Make sure the override file moved mover before base
357 check_order S mover base
360 ##########################################################################
361 test_override_loop() {
363 echo "info: testing to insert scripts with a loop, and the effect of an override file"
368 # Two scripts with a loop between them
369 if insertscript loop1 <<'EOF' ; then
372 # Required-Start: loop2
378 error "inserting script with missing dependencies did not fail"
381 insertscript loop2 <<'EOF' || true
384 # Required-Start: loop1
391 # Test if override file can be used to break the loop
392 mkdir -p $overridedir
393 cat <<'EOF' > $overridedir/loop1
403 check_script_not_present S loop1
404 check_script_not_present S loop2
406 insserv_reg loop1 || true
407 insserv_reg loop2 || true
409 check_order S loop1 loop2
412 ##########################################################################
414 test_override_remove() {
416 echo "info: Try to reproduce BTS #540866"
421 addscript testscript <<'EOF'
423 # Provides: testscript
426 # Default-Start: 2 3 4 5
427 # Default-Stop: 0 1 6
431 mkdir -p ${overridedir}/.
432 cat >${overridedir}/testscript <<'EOF'
434 # Provides: testscript
437 # Default-Start: 2 4 5
438 # Default-Stop: 0 1 6
442 insserv_reg testscript
446 check_script_not_present 3 testscript
448 echo info: Trying to remove the script
450 insserv_del testscript
454 check_script_not_present 3 testscript
457 ##########################################################################
460 echo "info: testing to insert scripts with a longer loop, making sure it fail"
465 # Three scripts with a loop between them, make sure introducing the
466 # loop fail, as it will make insserv generate a unstable and broken
467 # boot and shutdown sequence.
468 insertscript loop1 <<'EOF'
478 insertscript loop2 <<'EOF' || true
481 # Required-Start: loop1
488 if insertscript loop3 <<'EOF' ; then
491 # Required-Start: loop2
493 # X-Start-Before: loop1
498 error "inserting script causing a loop did not fail"
501 ##########################################################################
502 test_combined_loop() {
503 # Test real loop in the combined start and stop sequence. There is no
504 # loop in the start sequence, and no loop in the stop sequence, but in
505 # the combined graph insserv is creating internally, there is a loop.
506 # This make sense, as scripts need to be installed in dependency
507 # order, and there is no way to install these scripts that make sure
508 # both start and stop dependencies are fulfilled.
510 echo "info: test handling of loops in the combination of start and stop sequences"
515 insertscript startfirst <<'EOF' || true
517 # Provides: startfirst
519 # Required-Stop: startsecond
525 insertscript startsecond <<'EOF' || true
527 # Provides: startsecond
528 # Required-Start: startfirst
537 test_order S startfirst startsecond
538 test_order 6 startsecond startfirst
540 ##########################################################################
542 # Test another fake loop. This one should work, as it is possible to
543 # install the two scripts in sequence because one of the dependencies
544 # are optional. It does not with insserv today.
546 echo "info: test handling of 'fake' loops in the combination of start and stop sequences"
551 insertscript startfirst_stopfirst <<'EOF' || true
553 # Provides: startfirst_stopfirst
556 # Should-Stop: startsecond_stoplast
562 insertscript startsecond_stoplast <<'EOF' || true
564 # Provides: startsecond_stoplast
565 # Required-Start: startfirst_stopfirst
574 check_order S startfirst_stopfirst startsecond_stoplast
575 check_order 6 startfirst_stopfirst startsecond_stoplast
577 ##########################################################################
578 test_fake_loop_reverse() {
579 # Test another fake loop using reverse dependencies to document that
580 # it can happen based on information provided in one package only.
581 # This should work, as it is possible to install the two scripts in
582 # sequence because one of the dependencies are optional. It does not
583 # with insserv today. Note thought that the generated order is
584 # different from the one above.
587 echo "info: test handling of 'fake' loops using reverse depends"
592 insertscript startfirst_stopfirst <<'EOF' || true
594 # Provides: startfirst_stopfirst
602 insertscript startsecond_stoplast <<'EOF' || true
604 # Provides: startsecond_stoplast
605 # Required-Start: startfirst_stopfirst
607 # X-Stop-After: startfirst_stopfirst
616 check_order S startfirst_stopfirst startsecond_stoplast
617 check_order 6 startfirst_stopfirst startsecond_stoplast
619 ##########################################################################
622 echo "info: test if bad script in init.d/ with no symlinks in rc*.d/ make problems"
627 addscript sitelocal <<'EOF' || true
629 # Provides: duplicate
630 # Required-Start: $remote_fs
631 # Required-Stop: $remote_fs
637 insertscript distroglobal <<'EOF' || true
639 # Provides: dublicate
640 # Required-Start: $remote_fs
641 # Required-Stop: $remote_fs
649 check_script_present S distroglobal
651 ##########################################################################
654 echo "info: check that it work to insert scripts with only start runlevels"
659 insertscript onlystart <<'EOF' || true
661 # Provides: onlystart
662 # Required-Start: $remote_fs
663 # Required-Stop: $remote_fs
664 # Default-Start: 2 3 4 5
671 check_script_present 2 onlystart
672 check_script_present 3 onlystart
673 check_script_present 4 onlystart
674 check_script_present 5 onlystart
676 check_script_not_present 0 onlystart
677 check_script_not_present 1 onlystart
678 check_script_not_present 6 onlystart
680 ##########################################################################
683 echo "info: check that it work to insert scripts with only stop runlevels"
685 # This test check that the common way to update the runlevels used by
686 # a given script is working. It simulates these calls to update-rc.d:
687 # update-rc.d oldscript default
688 # update-rc.d -f oldscript remove
689 # update-rc.d oldscript start 20 2 3 4 5 . stop 20 1 .
693 insertscript onlystop <<'EOF' || true
696 # Required-Start: $remote_fs
697 # Required-Stop: $remote_fs
705 check_script_present 0 onlystop
706 check_script_present 6 onlystop
708 check_script_not_present 1 onlystop
709 check_script_not_present 2 onlystop
710 check_script_not_present 3 onlystop
711 check_script_not_present 4 onlystop
712 check_script_not_present 5 onlystop
713 check_script_not_present S onlystop
715 ##########################################################################
718 echo "info: test if script removal removes all symlinks."
720 # This test check that the common way to update the runlevels used by
721 # a given script is working. It simulates these calls to update-rc.d:
722 # update-rc.d oldscript default
723 # update-rc.d -f oldscript remove
724 # update-rc.d oldscript start 20 2 3 4 5 . stop 20 1 .
728 insertscript oldscript <<'EOF' || true
730 # Provides: oldscript
731 # Required-Start: $remote_fs
732 # Required-Stop: $remote_fs
733 # Default-Start: 2 3 4 5
734 # Default-Stop: 0 1 6
738 # Check that the problematic symlinks are presend, as well as one that
740 check_script_present 0 oldscript
741 check_script_present 1 oldscript
742 check_script_present 3 oldscript
743 check_script_present 6 oldscript
746 addscript oldscript <<'EOF' || true
748 # Provides: oldscript
749 # Required-Start: $remote_fs
750 # Required-Stop: $remote_fs
751 # Default-Start: 2 4 5
757 # Remove old symlinks
758 insserv_del oldscript
759 # Insert new ones, this time without runlevel 0 and 6
760 insserv_reg oldscript
764 check_script_not_present 0 oldscript
765 check_script_present 1 oldscript
766 check_script_present 2 oldscript
767 check_script_not_present 3 oldscript
768 check_script_not_present 6 oldscript
771 ##########################################################################
772 test_segfault_virtfac() {
774 echo "info: detect segfault caused by script providing virtual facility."
779 insertscript badheaderscript <<'EOF' || true
784 # Default-Start: 2 3 4 5
785 # Default-Stop: 0 1 6
789 # Problem is only triggered if there are start or stop symlinks for
790 # the script present.
791 mkdir -p $initddir/../rc2.d
792 ln -s ../init.d/badheaderscript $initddir/../rc2.d/S02badheaderscript
795 insertscript okscript <<'EOF' || true
798 # Required-Start: $syslog
800 # Default-Start: 2 3 4 5
801 # Default-Stop: 0 1 6
807 check_script_present 2 okscript
809 ##########################################################################
810 test_incorrect_startscripts() {
812 echo "info: Check if insserv add start symlinks for scripts that"
813 echo "info: currently do not have them. #492526"
818 insertscript disablestartscript <<'EOF' || true
820 # Provides: disablestartscript
823 # Default-Start: 2 3 4 5
824 # Default-Stop: 0 1 6
829 check_script_present 2 disablestartscript
830 check_script_present 5 disablestartscript
831 check_script_not_present S disablestartscript
832 check_script_present 1 disablestartscript
834 rm $initddir/../rc{2,3,4,5}.d/S??disablestartscript
836 # Update symlinks, see if it add start symlinks
841 check_script_not_present 2 disablestartscript
842 check_script_not_present 3 disablestartscript
843 check_script_not_present 4 disablestartscript
844 check_script_not_present 5 disablestartscript
845 check_script_not_present S disablestartscript
846 check_script_present 0 disablestartscript
847 check_script_present 1 disablestartscript
849 ##########################################################################
850 test_incorrect_stopscripts() {
852 echo "info: Check if insserv add stop symlinks for scripts that"
853 echo "info: currently do not have them."
858 insertscript disablestopscript <<'EOF' || true
860 # Provides: disablestopscript
863 # Default-Start: 2 3 4 5
864 # Default-Stop: 0 1 6
869 check_script_present 2 disablestopscript
870 check_script_present 5 disablestopscript
871 check_script_not_present S disablestopscript
872 check_script_present 1 disablestopscript
874 rm $initddir/../rc{0,1}.d/K??disablestopscript
876 # Update symlinks, see if it add stop symlinks
881 check_script_present 2 disablestopscript
882 check_script_present 5 disablestopscript
883 check_script_not_present S disablestopscript
884 check_script_not_present 0 disablestopscript
885 check_script_not_present 1 disablestopscript
887 ##########################################################################
888 test_newbug_keepoldorder() {
890 echo "info: Verify that introducing a loop in a working system do"
891 echo "info: not change the order of the scripts currently on disk."
896 insertscript mountall <<'EOF' || true
906 insertscript needlocal <<'EOF' || true
908 # Provides: needlocal
909 # Required-Start: $local_fs
910 # Required-Stop: $local_fs
916 insertscript needremote <<'EOF' || true
918 # Provides: needremote
919 # Required-Start: $remote_fs needlocal
920 # Required-Stop: $remote_fs needlocal
926 insertscript needboth <<'EOF' || true
929 # Required-Start: needlocal needremote
930 # Required-Stop: needlocal needremote
938 check_order S mountall needlocal
939 check_order S mountall needremote
940 check_order S mountall needboth
941 check_order S needlocal needremote
942 check_order S needlocal needboth
943 check_order S needremote needboth
945 # Then introduce buggy dependencies in an existing script
947 addscript needboth <<'EOF' || true
950 # Required-Start: $remote_fs
951 # Required-Stop: $remote_fs
952 # X-Start-Before: $local_fs
959 echo "info: calling insserv after introducing a bug in script needboth"
960 insserv_reg needboth || true
964 # The severity of this test should be fatal, below is explanation about how
965 # new (1.11.10) and old (1.11.0) insserv version behaviour changed in this
968 # Hmm ... with this I've found out that the old insserv will
969 # run on a loop and therefore exit. This loop was caused
970 # by the system facility $local_fs make the old insserv
971 # to do an exit ... now the problem is that the new insserv
972 # expands all system facility to their real requirements.
973 # This leads to the new behaviour as there is no node during
974 # the sorting algorithm which would cause such a loop.
976 # In other words: that the old insserv hasn't changed the
977 # order was simply a side effect of having a ghost node
978 # whereas the new insserv does not use such nodes anymore.
980 # If you would remove the `X-Start-Before: $local_fs' the
981 # old insserv will also change the boot order.
983 ${severity}_order S mountall needlocal
984 ${severity}_order S mountall needremote
985 ${severity}_order S mountall needboth
986 ${severity}_order S needlocal needremote
987 ${severity}_order S needlocal needboth
988 ${severity}_order S needremote needboth
990 ##########################################################################
991 test_start_before() {
993 echo "info: Verify that X-start-before work as it should."
998 insertscript startlast <<'EOF' || true
1000 # Provides: startlast
1008 insertscript startfirst <<'EOF' || true
1010 # Provides: startfirst
1013 # X-Start-Before: startlast
1021 check_order S startfirst startlast
1023 ##########################################################################
1026 echo "info: Verify that X-stop-after work as it should."
1031 insertscript stopfirst <<'EOF' || true
1033 # Provides: stopfirst
1041 insertscript stopafter <<'EOF' || true
1043 # Provides: stopafter
1046 # X-Stop-After: stopfirst
1054 check_order 0 stopfirst stopafter
1056 ##########################################################################
1057 test_adding_start() {
1059 echo "info: Make sure that adding start levels do not change an existing installation."
1064 insertscript addstartscript <<'EOF' || true
1066 # Provides: addstartscript
1074 check_script_present 1 addstartscript
1076 check_script_not_present S addstartscript
1077 check_script_not_present 0 addstartscript
1078 check_script_not_present 2 addstartscript
1079 check_script_not_present 3 addstartscript
1080 check_script_not_present 4 addstartscript
1081 check_script_not_present 5 addstartscript
1082 check_script_not_present 6 addstartscript
1084 # Then change runlevel in existing script
1086 addscript addstartscript <<'EOF' || true
1088 # Provides: addstartscript
1091 # Default-Start: 2 3 4 5
1097 # Update script after changing the header
1098 insserv_reg addstartscript || true
1102 check_script_present 1 addstartscript
1104 check_script_not_present S addstartscript
1105 check_script_not_present 0 addstartscript
1106 check_script_not_present 2 addstartscript
1107 check_script_not_present 3 addstartscript
1108 check_script_not_present 4 addstartscript
1109 check_script_not_present 5 addstartscript
1110 check_script_not_present 6 addstartscript
1112 ##########################################################################
1113 test_removing_start() {
1115 echo "info: Make sure that removing start levels do not change an existing installation."
1120 insertscript remstartscript <<'EOF' || true
1122 # Provides: remstartscript
1125 # Default-Start: 2 3 4 5
1126 # Default-Stop: 0 1 6
1130 check_script_present 0 remstartscript
1131 check_script_present 1 remstartscript
1132 check_script_present 2 remstartscript
1133 check_script_present 3 remstartscript
1134 check_script_present 4 remstartscript
1135 check_script_present 5 remstartscript
1136 check_script_present 6 remstartscript
1138 # Then change runlevel in existing script
1140 addscript remstartscript <<'EOF' || true
1142 # Provides: remstartscript
1146 # Default-Stop: 0 1 6
1151 # Update script after changing the header
1152 insserv_reg remstartscript || true
1156 check_script_present 2 remstartscript
1157 check_script_present 3 remstartscript
1158 check_script_present 4 remstartscript
1159 check_script_present 5 remstartscript
1161 ##########################################################################
1162 test_adding_stop() {
1164 echo "info: Make sure that adding stop levels do not change an existing installation."
1169 insertscript addstopscript <<'EOF' || true
1171 # Provides: addstopscript
1179 check_script_present S addstopscript
1180 check_script_not_present 0 addstopscript
1181 check_script_not_present 1 addstopscript
1182 check_script_not_present 2 addstopscript
1183 check_script_not_present 3 addstopscript
1184 check_script_not_present 4 addstopscript
1185 check_script_not_present 5 addstopscript
1186 check_script_not_present 6 addstopscript
1188 # Then change runlevel in existing script
1190 addscript addstopscript <<'EOF' || true
1192 # Provides: addstopscript
1201 # Update script after changing the header
1202 insserv_reg addstopscript || true
1206 check_script_present S addstopscript
1207 check_script_not_present 0 addstopscript
1208 check_script_not_present 1 addstopscript
1209 check_script_not_present 2 addstopscript
1210 check_script_not_present 3 addstopscript
1211 check_script_not_present 4 addstopscript
1212 check_script_not_present 5 addstopscript
1213 check_script_not_present 6 addstopscript
1215 ##########################################################################
1216 test_removing_stop() {
1218 echo "info: Make sure that removing stop levels do not change an existing installation."
1223 insertscript remstopscript <<'EOF' || true
1225 # Provides: remstopscript
1233 check_script_present S remstopscript
1234 check_script_present 0 remstopscript
1235 check_script_present 6 remstopscript
1237 check_script_not_present 1 remstopscript
1238 check_script_not_present 2 remstopscript
1239 check_script_not_present 3 remstopscript
1240 check_script_not_present 4 remstopscript
1241 check_script_not_present 5 remstopscript
1243 # Then change runlevel in existing script
1245 addscript remstopscript <<'EOF' || true
1247 # Provides: remstopscript
1256 # Update script after changing the header
1257 insserv_reg remstopscript || true
1261 check_script_present 0 remstopscript
1262 check_script_present 6 remstopscript
1264 ##########################################################################
1265 test_duplicate_provides() {
1267 echo "info: test two initscripts providing same facility."
1268 echo "info: Not sure if this should fail or not."
1273 addscript one <<'EOF' || true
1283 addscript two <<'EOF' || true
1293 insserv_reg one || true
1294 insserv_reg two || true
1298 check_script_present S one
1299 ${severity}_script_not_present S two
1301 ##########################################################################
1302 test_bogus_facility() {
1304 echo "info: test insertion of script requiring a virtual facility that doesn't exist"
1309 addscript needbogusvirtual <<'EOF'
1311 # Provides: needbogusvirtual
1312 # Required-Start: $bogusvirtualfacility
1319 insserv_reg needbogusvirtual || true
1323 test_script_not_present S needbogusvirtual
1325 ##########################################################################
1326 test_insserv_conf_d() {
1328 echo "info: test that /etc/insserv.conf.d/ is used"
1333 mkdir -p ${insconf}.d
1335 # add a base service, to ensure check_order() is accurate
1336 insertscript dummy <<'EOF'
1346 cat <<'EOF' > ${insconf}.d/facone
1347 $commvirtfac +facone
1350 insertscript facone <<'EOF' || true
1353 # Required-Start: dummy
1360 cat <<'EOF' > ${insconf}.d/factwo
1361 $commvirtfac +factwo
1364 insertscript factwo <<'EOF' || true
1367 # Required-Start: dummy
1374 addscript service <<'EOF' || true
1377 # Required-Start: $commvirtfac
1384 insserv_reg service || true
1388 check_script_present S service
1389 check_order S facone service
1390 check_order S factwo service
1394 ##########################################################################
1395 test_broken_header() {
1397 echo "info: test insertion of script missing Required-{Start,Stop} fields"
1402 addscript badheader <<'EOF'
1404 # Provides: badheader
1405 # Default-Start: 2 3 4 5
1406 # Default-Stop: 0 1 6
1410 insserv_reg badheader || true
1414 test_script_present 0 badheader
1415 test_script_present 1 badheader
1416 test_script_present 2 badheader
1417 test_script_present 3 badheader
1418 test_script_present 4 badheader
1419 test_script_present 5 badheader
1420 test_script_present 6 badheader
1422 ##########################################################################
1423 test_noprovides_header() {
1425 echo "info: test insertion of script missing Provides fields"
1430 addscript badheader <<'EOF'
1434 # Default-Start: 2 3 4 5
1435 # Default-Stop: 0 1 6
1439 insserv_reg badheader || true
1443 test_script_present 0 badheader
1444 test_script_present 1 badheader
1445 test_script_present 2 badheader
1446 test_script_present 3 badheader
1447 test_script_present 4 badheader
1448 test_script_present 5 badheader
1449 test_script_present 6 badheader
1451 ##########################################################################
1452 test_no_default_start() {
1454 echo "info: test insertion of script missing Default-Start field"
1459 addscript nodefstart <<'EOF'
1461 # Provides: nodefstart
1468 insserv_reg nodefstart || true
1472 check_script_present 0 nodefstart
1473 check_script_present 6 nodefstart
1475 check_script_not_present 2 nodefstart
1476 check_script_not_present 3 nodefstart
1477 check_script_not_present 4 nodefstart
1478 check_script_not_present 5 nodefstart
1480 ##########################################################################
1481 test_no_default_stop() {
1483 echo "info: test insertion of script missing Default-Stop field"
1488 addscript nodefstop <<'EOF'
1490 # Provides: nodefstop
1493 # Default-Start: 2 3 4 5
1497 insserv_reg nodefstop || true
1501 check_script_present 2 nodefstop
1502 check_script_present 3 nodefstop
1503 check_script_present 4 nodefstop
1504 check_script_present 5 nodefstop
1506 check_script_not_present 0 nodefstop
1507 check_script_not_present 1 nodefstop
1508 check_script_not_present 6 nodefstop
1510 ##########################################################################
1511 test_initd_symlink() {
1513 echo "info: test that a symlink in /etc/init.d/ to another script does not cause problems"
1518 addscript symlinked <<'EOF'
1520 # Provides: symlinked
1523 # Default-Start: 2 3 4 5
1528 addscript outsider <<'EOF'
1530 # Provides: outsider
1533 # Default-Start: 2 3 4 5
1538 #addscript halt <<'EOF'
1548 # Now make an illegal symlink to see if it causes problems, #485045
1549 ln -s symlinked ${initddir}/symlink
1551 insserv_reg symlinked || true
1552 insserv_reg symlink || true
1554 check_script_present 1 symlinked
1555 check_script_present 2 symlinked
1556 check_script_present 3 symlinked
1557 check_script_present 4 symlinked
1558 check_script_present 5 symlinked
1559 check_script_not_present 1 symlink
1560 check_script_not_present 2 symlink
1561 check_script_not_present 3 symlink
1562 check_script_not_present 4 symlink
1563 check_script_not_present 5 symlink
1565 # Add a /etc/init.d/reboot -> halt symlink, to make sure the SUSE case
1566 # is not broken with stricter symlink sanity checking
1567 #ln -s halt ${initddir}/reboot
1569 #insserv_reg reboot || true
1571 #check_script_present 0 reboot
1572 #check_script_present 6 reboot
1574 # Move outsider to a location other than /etc/init.d/ and create a symlink
1575 # to it. insserv should register it without problems.
1576 mv ${initddir}/outsider ${initddir}/../
1577 ln -s ../outsider ${initddir}/outsidelink
1579 insserv_reg outsidelink || true
1583 check_script_present 1 outsidelink
1584 check_script_present 2 outsidelink
1585 check_script_present 3 outsidelink
1586 check_script_present 4 outsidelink
1587 check_script_present 5 outsidelink
1589 rm -f ${initddir}/../outsider
1591 ##########################################################################
1592 test_deterministic_order() {
1594 echo "info: test two or more initscripts providing same facility, making sure"
1595 echo "info: that the first script can be registered with insserv, but others fail."
1600 addscript abc <<'EOF' || true
1610 addscript xyz <<'EOF' || true
1620 addscript hjk <<'EOF' || true
1630 insserv_reg xyz || true
1631 insserv_reg hjk || true
1632 insserv_reg abc || true
1637 check_script_present S xyz
1638 check_script_not_present S abc
1639 check_script_not_present S hjk
1641 ##########################################################################
1642 test_all_keyword() {
1644 echo "info: test behaviour of a script depending on another with the \$all keyword"
1645 echo "info: #491391"
1650 # Insert a few scripts to flesh out $initdir
1651 for script in one two three
1653 insertscript $script <<EOF || true
1656 # Required-Start: \$remote_fs
1658 # Default-Start: 2 3 4 5
1664 insertscript four <<'EOF' || true
1667 # Required-Start: $remote_fs
1669 # Should-Start: one two three
1671 # Default-Start: 2 3 4 5
1676 insertscript rmnologin <<'EOF' || true
1678 # Provides: rmnologin
1679 # Required-Start: $remote_fs $all
1681 # Default-Start: 2 3 4 5
1686 # This version of bootchart LSB info is not the best, but it does reveal
1687 # an interesting and unexpected behaviour.
1688 insertscript bootchart <<'EOF' || true
1690 # Provides: bootchart
1691 # Required-Start: $remote_fs rmnologin
1693 # Default-Start: 2 3 4 5
1700 check_script_present 5 rmnologin
1701 check_script_present 5 bootchart
1702 test_order 5 rmnologin bootchart
1705 echo "info: now add \$all keyword to bootchart script and reinsert"
1709 # This information looks correct, but due to the way all_links() works two or
1710 # more scripts with keyword $all in Required-Start start at same sequence, but
1711 # do start after all other scripts
1712 addscript bootchart <<'EOF' || true
1714 # Provides: bootchart
1715 # Required-Start: $all rmnologin
1717 # Default-Start: 2 3 4 5
1722 insserv_reg bootchart || true
1725 check_script_present 5 bootchart
1726 test_order 5 rmnologin bootchart
1729 echo "info: add yet another script depending on \$all"
1731 insertscript all <<'EOF' || true
1734 # Required-Start: $all
1736 # Default-Start: 2 3 4 5
1742 check_script_present 5 all
1744 ##########################################################################
1747 echo "info: Check that start dependency on \$all only affect the start"
1748 echo "sequence. BTS #485307"
1754 # Insert a few scripts to flesh out $initdir
1755 insertscript early <<EOF || true
1765 insertscript center <<'EOF' || true
1768 # Required-Start: early
1769 # Required-Stop: early
1775 insertscript late <<'EOF' || true
1778 # Required-Start: center
1779 # Required-Stop: center
1785 # This script should start early and stop before all other scripts
1786 insertscript zcomplex <<'EOF' || true
1789 # Required-Start: early
1790 # X-Start-Before: center
1791 # Required-Stop: $all
1799 check_script_present 2 early
1800 check_script_present 2 zcomplex
1801 check_order 2 early zcomplex
1802 check_order 2 zcomplex center
1803 check_order 0 zcomplex late
1804 check_order 0 zcomplex early
1806 ##########################################################################
1807 test_script_in_runlevel() {
1809 echo "info: add a regular file where only symlinks are expected (#493202)"
1814 # Create a regular file in runlevel directory where only symlinks are expected
1815 mkdir $initddir/../rcS.d
1816 touch $initddir/../rcS.d/S06badboy
1818 insertscript goodboy <<'EOF'
1821 # Required-Start: $remote_fs
1830 check_script_present S goodboy
1832 rm $initddir/../rcS.d/S06badboy
1834 ##########################################################################
1835 test_x_interactive() {
1837 echo "info: Check if X-Interactive header work"
1843 # Insert a few scripts to flesh out $initdir
1844 insertscript first <<EOF || true
1854 # This test if X-Interactive work with existing scripts when a new
1855 # script is inserted.
1856 insertscript alone1 <<'EOF' || true
1859 # Required-Start: first
1860 # Required-Stop: first
1863 # X-Interactive: true
1867 insertscript after <<'EOF' || true
1870 # Required-Start: first
1871 # Required-Stop: first
1877 # This test if X-Interactive work with new scripts too. The code
1878 # paths in insserv are different for the two cases.
1879 insertscript alone2 <<'EOF' || true
1882 # Required-Start: first
1883 # Required-Stop: first
1886 # X-Interactive: true
1892 check_script_present 2 first
1893 check_script_present 2 after
1894 check_script_present 2 alone1
1895 check_script_present 2 alone2
1896 check_order 2 first after
1897 check_order 2 first alone1
1898 check_order 2 first alone2
1899 ${severity}_order 2 alone1 after # This ordering is not guaranteed
1900 ${severity}_order 2 alone2 after # This ordering is not guaranteed
1902 ##########################################################################
1904 test_insserv_conf_makefile() {
1906 echo "info: test how recursive /etc/insserv.conf settings show up"
1907 echo "info: in .depend.boot. BTS #534526."
1914 # If $local_fs only depend on the mountall script, the test work.
1915 # Only the last script in $local_fs make it to the dependency file.
1917 cat <<'EOF' > $insconf
1918 $local_fs +mountall +nonexisting
1919 $remote_fs $local_fs
1923 insertscript mountall <<'EOF'
1925 # Provides: mountall
1933 insertscript dbus <<'EOF'
1943 insertscript hal <<'EOF'
1946 # Required-Start: $remote_fs dbus
1955 if ! grep -q "^hal: mountall dbus" ${initddir}/.depend.start ; then
1956 msg="hal should depend on dbus and mountall in .depend.start:"
1957 if [ test = "$severity" ] ; then
1962 grep "^hal: " ${initddir}/.depend.start | sed 's/^/ /'
1968 #########################
1970 test_insserv_virt_loop() {
1972 echo "info: test insserv handle virtual facilities depending on itself."
1979 # If $local_fs depend on itself, the error is triggered.
1981 cat <<'EOF' > $insconf
1982 $local_fs +mountall $local_fs
1986 # This used to hang and use unlimited amount of memory. Now return
1988 insertscript testscript <<'EOF' || true
1990 # Provides: testscript
1991 # Required-Start: $local_fs
2003 ##########################################################################
2004 test_local_virtual() {
2006 echo "info: Test if home made virtual facilities work as they should."
2013 insertscript test1 <<'EOF' || true
2016 # Required-Start: $mail-transport-agent
2023 insertscript test2 <<'EOF' || true
2026 # Required-Start: $mail-transport-agent
2036 cat <<'EOF' > $insconf.d/test3
2037 $mail-transport-agent test3
2039 insertscript test3 <<'EOF' || true
2049 cat <<'EOF' > $insconf.d/test4
2050 $mail-transport-agent +test4
2053 insertscript test4 <<'EOF' || true
2056 # Required-Start: test3
2065 check_order 1 test3 test1
2066 check_order 1 test3 test2
2067 check_order 1 test4 test1
2068 check_order 1 test4 test2
2071 ##########################################################################
2072 test_insserv_upstart() {
2074 echo "info: test if insserv handle upstart jobs properly."
2081 # This used to hang and use unlimited amount of memory. Now return
2083 upstartdir=${tmpdir}/etc/init
2085 upstartjob="${tmpdir}/lib/init/upstart-job"
2087 # Add upstart config
2089 insconf="$insconf -u $upstartjob"
2092 mkdir -p $(dirname $upstartjob)
2093 cat > $upstartjob <<EOF
2097 # Provides: upstart-test
2105 chmod a+x $upstartjob
2107 insert_upstart_job() {
2109 mkdir -p $upstartdir
2110 cat > $upstartdir/$name
2111 ln -s $upstartjob $initddir/$name
2115 # XXX Someone that understand upstart need to fill in sensible stuff
2117 insert_upstart_job upstart-test <<EOF || true
2118 exec /bin/foo --opt -xyz foo bar
2121 insertscript test <<'EOF' || true
2124 # Required-Start: upstart-test
2134 # Undo upstart config
2138 ##########################################################################
2140 test_normal_sequence
2143 test_override_remove
2145 test_combined_loop # 1 non-fatal test failing
2147 test_fake_loop_reverse
2152 test_segfault_virtfac
2153 test_incorrect_startscripts
2154 test_incorrect_stopscripts
2155 test_newbug_keepoldorder # 3 non-fatal tests failing
2162 test_duplicate_provides
2163 test_bogus_facility # 1 non-fatal test failing
2166 test_noprovides_header
2167 test_no_default_start
2168 test_no_default_stop
2170 test_deterministic_order
2173 test_script_in_runlevel
2175 test_insserv_conf_makefile
2176 test_insserv_virt_loop
2178 test_insserv_upstart