maybe I have missed this in the past, but with com...
# box-products
f
maybe I have missed this in the past, but with commandox and running CF2021 I only want to install certain packages...right now I am spinning up the CB server and then going into cfadmin and manually installing the packages...can I automate that based on the export of the packages? if so how can I do that.....is it via command line and if so how? thanks all
s
Would love to know the answer to this; having to do the same thing, here.
a
@slcronin what do you mean you were wondering if this was possible? We do it on almost all of our projects.
s
@adam.euans I must be behind the times since I just have the one project, I didn't know the packages could be auto-loaded?
d
Copy code
"scripts":{
   "preServerStart":"recipe server-install-packages.boxr"
 }
and in my server-install-packages.boxr:
Copy code
cfpm install sqlserver,mail,cache
the list of packages are comma separated with no spaces.
f
here is the line I could put into the cmd window: cfpm>import C:\packages-to-import.txt but can I do this in just commandbox shell, or in VSCode as a script and if so how....OR how do I open up the CFPM using a Commandbox shell
d
obviously in this example, the recipe is not needed since its only a one liner. but showing you can have it in a separete file.
a
Copy code
"scripts":{
        "onServerInstall":"cfpm install axis,caching,document,ftp,mail,scheduler,spreadsheet,sqlserver,zip"
    },
Is what we use for a number of projects.
d
another good point Adam. I only do "onServerInstall" not "preServerStart" - its overkill to do it on every server start.
f
Adam, and the scripts block is in what file....server.json? sorry a bit slow on some of the back end of CB
d
yes, server.json
a
correct, server.json
d
Read the docs. Has all the info you need.
f
thanks both of you....I will add that to my server.json....and yes I would have gone to the docs about where the scripts block is but thought it was quicker to ask...can't wait to get this into my server.json and make my install complete πŸ™‚
πŸ‘πŸΎ 1
b
@Daniel Mejia FWIW: onServerInstall runs every time the server installation is verified to exist. There is an environment variable called initialinstall that is true for only the first time through
πŸ‘ 1
πŸ‘πŸΎ 1
You can do something like this:
Copy code
assertFalse ${interceptData.INSTALLDETAILS.INITIALINSTALL} || cfpm install ...
If the first command evaluates true, then the second command won't run
f
and you put this in the script area of server.json?
b
@fmdano Just in case it wasn't clear, CommandBox provides its own wrapper command called
cfpm
that is just a passthrough to the real cfpm.bat or cfpm.sh script inside the corresponding server home. So you can type
Copy code
cfpm ANY VALID CFPM THING HERE
from the root of the web server, and it will just work
Tying that up to some automated pacakge or server script is just another layer of automation if you want it to happen without human input
f
that helps a lot...I was wondering how to just run cfpm calls on the commandbox commandline...now I know
b
You can put it in β€’ a package script (the
scripts
block of a
box.json
file) in the web root of the server β€’ OR a server script (the
scripts
block of the server's
server.json
)
It's 6 of one, half a dozen of the other. Only server-related scripts will work in a
server.json
f
I knew I'd get help from the community and eventually you would jump in and give the extra info that we all did not know....you are the best as always πŸ™‚
πŸ‘ 1
b
@Daniel Mejia You know, I'm tired of putting that stupid initialInstall check in so I just added a new interception point (and corresponding package and server script) called
onServerInitialInstall
whcih ONLY fires on the initial install https://ortussolutions.atlassian.net/browse/COMMANDBOX-1539
πŸ‘ 2
πŸ‘πŸΎ 1
The main reason
onServerInstall
always fires is because modules like CFConfig need to run their logic on every server start, and they specifically just need to ensure the CF home exists at that point in time.
πŸ‘πŸΎ 1
But there really is a good use case for a one-time only sort of script. (And case anyone is wondering-- if you changed your
cfengine
to a new CF/Lucee version, the initial install will fire the FIRST time that version of CF/Lucee is installed.)
d
Wow dude. That’s so cool you just added that. Thank you!