Use functions inside the installation script to make the installation more reliable #5504
sneak
started this conversation in
Improvement Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Error Message and Logs
The recommended install method:
Downloads the install.sh script and executes it. But, if the download fails part of the way through, it may truncate a command and cause unexpected behavior, for example, the command
systemctl start sshdin install.sh could instead runsystemctl start ssif the script gets truncated there, causing unwanted behavior (and it's run as root!).rm -rf /path/to/filecan becomerm -rf /.The solution to this is to wrap all of the logic in the script in a function, then call it at the bottom, ensuring the whole script has loaded. I usually use the function name "main" for this purpose, e.g.:
Additionally, this sort of paves the way to further modularize the installation into functions grouping sections of commands (e.g.
installDocker,checkSSH, etc) which can then be called from main, e.g.:This was actually the inspiration for this, as the install script is approaching 900 lines of commands aligned with the far left margin, making one have to read the entire thing line by line to get a high-level overview of the code. I was hoping such a large script would be broken into sections/functions.
Steps to Reproduce
Example Repository URL
No response
Coolify Version
main
Are you using Coolify Cloud?
No (self-hosted)
Operating System and Version (self-hosted)
na
Additional Information
No response
Beta Was this translation helpful? Give feedback.
All reactions