|
58 | 58 | run_scripts /usr/lib/coriolis/firstboot/user |
59 | 59 |
|
60 | 60 | if [ $first_error -eq 0 ]; then |
61 | | - echo "All the scripts completed successfully, creating /var/lib/coriolis/firstboot-complete" |
| 61 | + echo "All the scripts completed successfully." |
| 62 | + echo "Creating /var/lib/coriolis/firstboot-complete" |
62 | 63 | mkdir -p /var/lib/coriolis |
63 | 64 | touch /var/lib/coriolis/firstboot-complete |
64 | 65 | else |
65 | | - echo "One of the scripts failed, won't create /var/lib/coriolis/firstboot-complete" |
| 66 | + echo "One of the scripts failed." |
| 67 | + echo "Won't create /var/lib/coriolis/firstboot-complete" |
66 | 68 | fi |
67 | 69 |
|
68 | 70 | exit $first_error |
@@ -168,8 +170,23 @@ def register_firstboot_script( |
168 | 170 | self, |
169 | 171 | script: str, |
170 | 172 | index: int = 0, |
171 | | - user_provided=True, |
| 173 | + user_provided: bool = True, |
| 174 | + script_filename: str | None = None, |
172 | 175 | ): |
| 176 | + """Register a script to be executed during the first replica boot. |
| 177 | +
|
| 178 | + :param script: the script content |
| 179 | + :param index: script execution index (0-99), used as a script filename |
| 180 | + prefix. The scripts will be executed in alphabetic order, |
| 181 | + the Coriolis scripts first and then user provided scripts |
| 182 | + afterwards. |
| 183 | + :param user_provider: whether this is a Coriolis internal script |
| 184 | + (executed first) or user provided script. |
| 185 | + :param script_filename: optional script filename. The index parameter |
| 186 | + will be ignored when explicitly specifying |
| 187 | + the filename. Coriolis internal scripts should |
| 188 | + specify a filename to facilitate debugging. |
| 189 | + """ |
173 | 190 | pass |
174 | 191 |
|
175 | 192 | @abc.abstractmethod |
@@ -796,18 +813,24 @@ def register_firstboot_script( |
796 | 813 | self, |
797 | 814 | script: str, |
798 | 815 | index: int = 0, |
799 | | - user_provided=True, |
| 816 | + user_provided: bool = True, |
| 817 | + script_filename: str | None = None, |
800 | 818 | ): |
801 | | - if len(script) == 0: |
| 819 | + |
| 820 | + if not script: |
802 | 821 | LOG.debug("Empty first-boot script, skipping...") |
803 | 822 | return |
804 | 823 |
|
805 | 824 | if user_provided: |
806 | 825 | script_dir = "/usr/lib/coriolis/firstboot/user" |
807 | 826 | else: |
808 | 827 | script_dir = "/usr/lib/coriolis/firstboot/service" |
809 | | - unique_id = str(uuid.uuid4()).split("-")[0] |
810 | | - script_path = os.path.join(script_dir, f"{index:02d}-{unique_id}.sh") |
| 828 | + |
| 829 | + if not script_filename: |
| 830 | + unique_id = str(uuid.uuid4()).split("-")[0] |
| 831 | + script_filename = f"{index:02d}-{unique_id}.sh" |
| 832 | + |
| 833 | + script_path = os.path.join(script_dir, script_filename) |
811 | 834 |
|
812 | 835 | self._exec_cmd_chroot(f"mkdir -p {script_dir}") |
813 | 836 | self._write_file_sudo(script_path, script) |
|
0 commit comments