fleet/orbit/pkg/packaging
aysiu b5c0e61f7d
Enable launch daemon before trying to bootstrap it (#22764)
## Description
Moves the enabling of the launch daemon to before trying to launch it,
so it doesn't fail if the launch daemon is disabled

## Testing Done
launch daemon is enabled
```
 launchctl print system | grep fleetdm
		   78074      - 	com.fleetdm.orbit
		"com.fleetdm.orbit" => enabled
```
uninstalling FleetDM via
https://github.com/fleetdm/fleet/blob/main/orbit/tools/cleanup/cleanup_macos.sh
```
sudo ~/Desktop/removefleet.sh 
Removing fleet, system will be unenrolled in 15 seconds...
Executing detached child process
```
launch daemon is still enabled:
```
launchctl print system | grep fleetdm   
		   78074      - 	com.fleetdm.orbit
		"com.fleetdm.orbit" => enabled
```
If I manually disable the launch daemon...
```
sudo launchctl disable system/com.fleetdm.orbit
```
```
launchctl print system | grep fleetdm          
		       0     78 	com.fleetdm.orbit
		"com.fleetdm.orbit" => disabled
```
... then the install will fail:
```
sudo installer -pkg ~/Desktop/fleet-osquery-1.18.3.pkg -target /
installer: Package name is Fleet osquery
installer: Installing at base path /
installer: The install failed. (The Installer encountered an error that caused the installation to fail. Contact the software manufacturer for assistance. An error occurred while running scripts from the package “fleet-osquery-1.18.3.pkg”.)
```
Excerpt from `/var/log/install.log`:
```
2024-10-08 15:00:57-07 HOSTNAME package_script_service[80350]: ./postinstall: Retrying launchctl bootstrap...
2024-10-08 15:00:57-07 HOSTNAME package_script_service[80350]: ./postinstall: Bootstrap failed: 5: Input/output error
2024-10-08 15:00:58-07 HOSTNAME package_script_service[80350]: ./postinstall: Retrying launchctl bootstrap...
2024-10-08 15:00:58-07 HOSTNAME package_script_service[80350]: ./postinstall: Bootstrap failed: 5: Input/output error
2024-10-08 15:00:59-07 HOSTNAME package_script_service[80350]: ./postinstall: Retrying launchctl bootstrap...
2024-10-08 15:00:59-07 HOSTNAME package_script_service[80350]: ./postinstall: Bootstrap failed: 5: Input/output error
2024-10-08 15:01:00-07 HOSTNAME package_script_service[80350]: ./postinstall: Retrying launchctl bootstrap...
2024-10-08 15:01:00-07 HOSTNAME package_script_service[80350]: ./postinstall: Bootstrap failed: 5: Input/output error
2024-10-08 15:01:01-07 HOSTNAME package_script_service[80350]: ./postinstall: Retrying launchctl bootstrap...
2024-10-08 15:01:01-07 HOSTNAME package_script_service[80350]: ./postinstall: Bootstrap failed: 5: Input/output error
2024-10-08 15:01:02-07 HOSTNAME package_script_service[80350]: ./postinstall: Retrying launchctl bootstrap...
2024-10-08 15:01:02-07 HOSTNAME package_script_service[80350]: ./postinstall: Bootstrap failed: 5: Input/output error
2024-10-08 15:01:03-07 HOSTNAME package_script_service[80350]: ./postinstall: Retrying launchctl bootstrap...
2024-10-08 15:01:03-07 HOSTNAME package_script_service[80350]: ./postinstall: Bootstrap failed: 5: Input/output error
2024-10-08 15:01:04-07 HOSTNAME package_script_service[80350]: ./postinstall: Failed to bootstrap system /Library/LaunchDaemons/com.fleetdm.orbit.plist
```
If I then enable the launch daemon...
```
sudo launchctl enable system/com.fleetdm.orbit  
```
```
launchctl print system | grep fleetdm                           
		"com.fleetdm.orbit" => enabled
```
... then the postinstall in the pkg works fine:
```
sudo installer -pkg ~/Desktop/fleet-osquery-1.18.3.pkg -target /
installer: Package name is Fleet osquery
installer: Installing at base path /
installer: The install was successful.
```
So, yeah, the enabling has to be before the launching of the launch
daemon.
2024-10-23 13:54:41 -03:00
..
wix Fixed macOS MSI package -- using local wine and wix (#16307) 2024-01-30 11:08:21 -06:00
certs.pem Update Orbit CA certs [automated] (#20148) 2024-07-02 15:22:52 -03:00
deb.go update documentation of orbit/pkg/packaging (#6819) 2022-07-25 20:14:20 -03:00
linux_shared.go Add support for Linux ARM64 (#19931) 2024-07-17 16:07:59 -04:00
macos.go chore: remove refs to deprecated io/ioutil (#14485) 2023-10-27 15:28:54 -03:00
macos_notarize.go Update to latest gon with notarytool until we find a better solution (#14918) 2023-11-03 18:56:30 -05:00
macos_rcodesign.go device_token endpoint improvements (#15849) 2023-12-28 14:20:36 -06:00
macos_templates.go Enable launch daemon before trying to bootstrap it (#22764) 2024-10-23 13:54:41 -03:00
mk-ca-bundle.pl Update mk-ca-bundle.pl tool in repository (#8184) 2022-10-12 12:01:18 -03:00
packaging.go Add support for Linux ARM64 (#19931) 2024-07-17 16:07:59 -04:00
rpm.go update documentation of orbit/pkg/packaging (#6819) 2022-07-25 20:14:20 -03:00
windows.go Fix backward compatibility bug with Windows MSI END_USER_EMAIL (#20116) 2024-07-01 10:49:59 -05:00
windows_templates.go Fix backward compatibility bug with Windows MSI END_USER_EMAIL (#20116) 2024-07-01 10:49:59 -05:00
windows_test.go Add support for pre-release on Windows orbit builder (#18102) 2024-04-05 18:41:46 -03:00