How to delete app at a scheduled time on a certain date?
-
Quick question: Is there a way to delete an app at a scheduled time on a certain date in the future?
For example, I have one app I want to go away on December 31, 2021 this year. While I know I can just do this manually, I thought since it's far into the future maybe I can come up with a geeky way to schedule this task in advance.
I suppose the best way is using the Cloudron API, right? So I guess it'd be best if I installed the Cloudron API on the server itself (since I won't necessarily have anything running all the time at home here) / CLI, and just set that command in a script and let it run once in cron at the specified time? Any alternatives? Am I overcomplicating this?
-
Maybe you could disable the app from the inside with a cron job and then clean it up later at your leisure? I'm not exactly sure how you would stop or otherwise disable the app from within without triggering a restart, but maybe there's something in there.
-
If this is some WordPress app or equivalent, maybe there is some plugin which puts WP in maintenance mode at a particular time.
But I like @infogulch's idea. Put a cron job inside the app to kill itsef To uninstall an app it's a simple curl request:
curl -X POST https://my.example.com/api/v1/apps/appid/uninstall?access_token=apitoken
-
@girish Actually, with a couple improvements, CRON+API could be a wonderfully generalizable app management automation tool.
Three feature requests:
- Cloudron doc page on roles should mention the new App Operator role and describe its permissions
- Add a new environment variable inside each app container,
CLOUDRON_APP_ID
, which contains the id of the currently running app. This should apply to CRON as well - Add a new CRON-only environment variable
CLOUDRON_APP_OPERATOR_TOKEN
which is a temporary "App Operator"-role token that is only valid for the current app and for the duration of the cron run.- Depending on how the CRON feature is implemented (is this the cron from inside the container or on the host?) this may not work exactly how I'm thinking.
With these features, this idea could be implemented much more generally:
# From this: (user must customize api domain, app id, and token) curl -X POST https://my.example.com/api/v1/apps/appid/uninstall?access_token=apitoken # To this: (this is ready to copy/paste for any app in any cloudron, but it stops instead of uninstalls) curl -X POST $CLOUDRON_API_ORIGIN/api/v1/apps/$CLOUDRON_APP_ID/stop?access_token=$CLOUDRON_APP_OPERATOR_TOKEN
Thoughts?
-
@infogulch I mentioned them in the User and the Admin role subsections now.
Not too sure about new environment variables. It does make sense to add them if there were broad use cases (like other addons), so maybe if more use cases come up, we can add this.
I like the idea of having some scope for tokens. Restricting them to just specific apps(s) would make things more secure.
-
@girish said in How to delete app at a scheduled time on a certain date?:
curl -X POST https://my.example.com/api/v1/apps/appid/uninstall?access_token=apitoken
Just wanted to say that I ran the above command as a test in a new app for this purpose and it worked like a charm! Thank you so much for that geeky yet easy solution.