@@ -14,22 +14,17 @@ import (
1414 "github.com/autonomy/dianemo/initramfs/cmd/init/pkg/rootfs"
1515 "github.com/autonomy/dianemo/initramfs/cmd/init/pkg/service"
1616 "github.com/autonomy/dianemo/initramfs/cmd/init/pkg/switchroot"
17- "github.com/autonomy/dianemo/initramfs/cmd/init/ pkg/userdata"
17+ "github.com/autonomy/dianemo/initramfs/pkg/userdata"
1818)
1919
2020var (
2121 switchRoot * bool
2222)
2323
24- func hang () {
25- if rec := recover (); rec != nil {
26- err , ok := rec .(error )
27- if ok {
28- log .Printf ("%s\n " , err .Error ())
29- }
24+ func recovery () {
25+ if r := recover (); r != nil {
26+ log .Printf ("recovered from: %v\n " , r )
3027 }
31- // Hang forever to avoid a kernel panic.
32- select {}
3328}
3429
3530func init () {
@@ -44,23 +39,28 @@ func init() {
4439
4540func initram () (err error ) {
4641 // Read the block devices and populate the mount point definitions.
42+ log .Println ("initializing mount points" )
4743 if err = mount .Init (constants .NewRoot ); err != nil {
4844 return
4945 }
5046 // Download the user data.
47+ log .Println ("downloading the user data" )
5148 data , err := userdata .Download ()
5249 if err != nil {
5350 return
5451 }
5552 // Prepare the necessary files in the rootfs.
53+ log .Println ("preparing the root filesystem" )
5654 if err = rootfs .Prepare (constants .NewRoot , data ); err != nil {
5755 return
5856 }
5957 // Unmount the ROOT and DATA block devices.
58+ log .Println ("unmounting the ROOT and DATA partitions" )
6059 if err = mount .Unmount (); err != nil {
6160 return
6261 }
6362 // Perform the equivalent of switch_root.
63+ log .Println ("entering the new root" )
6464 if err = switchroot .Switch (constants .NewRoot ); err != nil {
6565 return
6666 }
@@ -69,20 +69,26 @@ func initram() (err error) {
6969}
7070
7171func root () (err error ) {
72- // Download the user data.
73- data , err := userdata .Download ()
72+ // Read the user data.
73+ log .Println ("reading the user data" )
74+ data , err := userdata .Open (constants .UserDataPath )
7475 if err != nil {
7576 return
7677 }
7778
7879 services := & service.Manager {
79- UserData : data ,
80+ UserData : * data ,
8081 }
8182
82- // Start the OSD gRPC service.
83+ // Start the services essential to managing the node.
84+ log .Println ("starting OS services" )
8385 services .Start (& service.OSD {})
86+ if data .Kubernetes .Init {
87+ services .Start (& service.ROTD {})
88+ }
8489
8590 // Start the services essential to running Kubernetes.
91+ log .Println ("starting Kubernetes services" )
8692 switch data .Kubernetes .ContainerRuntime {
8793 case constants .ContainerRuntimeDocker :
8894 services .Start (& service.Docker {})
@@ -98,17 +104,19 @@ func root() (err error) {
98104}
99105
100106func main () {
101- defer hang ()
107+ defer recovery ()
102108
103109 if * switchRoot {
104110 if err := root (); err != nil {
105111 panic (err )
106112 }
113+ select {}
107114 }
108115
109116 if err := initram (); err != nil {
110117 panic (err )
111118 }
112119
120+ // We should only reach this point if something within initram() fails.
113121 select {}
114122}
0 commit comments