Deleting RConnect apps via command-line?

I'm upgrading to new hardware and migrating content but I have a lot of apps that are no longer relevant and can be removed. These are mainly from people who were testing their publishing connection, or were just looking at the capabilities of RConnect, or have left the company. I have about 40 apps to delete, is there a method of deleting apps from RConnect via command-line? Or is there a "best" way of doing it other than manually clicking "delete" in the web interface? Can I just delete the app folders from /var/lib/rstudio-connect/apps , /var/lib/rstudio-connect/jobs, and /var/lib/rstudio-connect/bundles ? How do I flush the packrat cache for that app?

For those of you interested, this is how I get a list of all the apps and their ownership:

/opt/rstudio-connect/bin/usermanager audit --csvlog 2>/dev/null | grep 'deploy_application,Deployed bundle' | sed -e 's;/var/lib/rstudio-connect/bundles/app-;;' -e 's;\-[0-9]*\.tar\.gz;;'  |  awk -F, '{printf"%s %s\n" ,$4 ,$6}' | sort -u

Which gives me this nice output:

Russell Smithies (rsmithies) Deployed bundle 26 to application biopython_test-1556572668149
Russell Smithies (rsmithies) Deployed bundle 27 to application biopython_test-1556572744566
Russell Smithies (rsmithies) Deployed bundle 28 to application biopython_test2-1556573616556
Russell Smithies (rsmithies) Deployed bundle 35 to application 1-example
Russell Smithies (rsmithies) Deployed bundle 36 to application treeio_example
Russell Smithies (rsmithies) Deployed bundle 37 to application treeio_test

As someone who spends most of their time on command-line some better management tools for RStudio and RConnect would be greatly appreciated :slight_smile:

--Russell

As someone who loves a good CLI, I definitely appreciate your work here! A couple of best practices to note:

  • please do not delete things out of /var/lib/rstudio-connect/apps, /var/lib/rstudio-connect/bundles or /var/lib/rstudio-connect/jobs. Ultimately, these directories also have components in the database, so you will be potentially leaving cruft scattered throughout your system that could cause problems and weird edge cases
  • Also, today there is not a way to purge the packrat cache for a given application. The reason here is that the packrat cache creates potentially complex build dependencies / build trees, and we want to be very careful about creating problems.

Ultimately, if either of these directories are becoming concerning, there are many "ReapFrequency" settings that you can tweak / change inside of Connect (how long are reports maintained, how long are bundles maintained, etc.). We have several environments that we maintain internally to keep an eye out for places that are becoming concerning with respect to disk size. If something seems concerning to you, please share that feedback with us so that we can take a look at how to expose that functionality in the product in a safe fashion!

https://docs.rstudio.com/connect/admin/appendix/configuration/#Applications.BundleReapFrequency
https://docs.rstudio.com/connect/admin/appendix/configuration/#Applications.RenderingSweepLimit

That said, to your topic of a CLI to delete content. Today, I would recommend your having a look at the RStudio Connect Server API, a REST API that can be used for this type of operation. In particular, we have a publicly documented "content delete" endpoint that you can use for this task with curl. Unfortunately, the reference here is with GUIDs, which will be challenging to retrieve from disk.

https://docs.rstudio.com/connect/api/#deleteContent

There are also two common clients for this REST API. One is for use less as a CLI and more in R: https://github.com/rstudio/connectapi

The other is written in python and has a CLI associated with it: https://pypi.org/project/rsconnect-python/

However, I am not sure that it has a content delete implementation either.

What I would recommend is using the experimental "content list" endpoint if you need to get IDs and GUIDs. Since we do not have public API documentation for this endpoint, you can either look at the client implementation here:

Or build a CSV with the mapping using something like this in R:

remotes::install_github("rstuido/connectapi")
library(connectapi)
client <- connect(host = "https://myconnect.com", api_key = "my-api-key")
all_content <- get_content(client, limit = Inf)
readr::write_csv(all_content, "myfile.csv")

More details on using the RStudio Connect Server API is here: https://docs.rstudio.com/connect/cookbook/

We are definitely looking forward to improving this story by publicly documenting more of our API and increasing coverage in the various API clients. I hope this helps!! Please let us know if you run into any issues or have any follow-up questions! I will ensure this use case is shared with developers as they are taking a look at improving this part of the management ecosystem!

Hi Cole,
Thanx for the quick reply - I promise not to delete anything in the apps or bundles dirs :wink:
I think just tweaking my reap settings will do most of what I want and your link to the admin appendices is very useful .

--Russell

1 Like