Cloudron makes it easy to run web apps like WordPress, Nextcloud, GitLab on your server. Find out more or install now.


    Cloudron Forum

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular

    Solved How to delete app at a scheduled time on a certain date?

    Discuss
    4
    10
    358
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • d19dotca
      d19dotca last edited by d19dotca

      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? πŸ˜„

      --
      Dustin Dauncey
      www.d19.ca

      robi 1 Reply Last reply Reply Quote 1
      • infogulch
        infogulch last edited by

        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.

        https://docs.cloudron.io/apps/#cron

        1 Reply Last reply Reply Quote 2
        • robi
          robi @d19dotca last edited by robi

          @d19dotca Yah, you can use N8N to orchestrate it via the cron module and HTTP API call all in their GUI.

          Then share the workflow for others as well.

          Life of Advanced Technology

          1 Reply Last reply Reply Quote 2
          • girish
            girish Staff last edited by girish

            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
            
            d19dotca infogulch 2 Replies Last reply Reply Quote 3
            • d19dotca
              d19dotca @girish last edited by

              @girish oh that’s a lot easier than I thought! Perfect - I’ll try that. πŸ™‚ Thank you so much.

              --
              Dustin Dauncey
              www.d19.ca

              1 Reply Last reply Reply Quote 0
              • infogulch
                infogulch @girish last edited by infogulch

                @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
                  • Note: CLOUDRON_API_ORIGIN is already supported
                • 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?

                girish 1 Reply Last reply Reply Quote 1
                • girish
                  girish Staff @infogulch last edited by

                  @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.

                  1 Reply Last reply Reply Quote 2
                  • d19dotca
                    d19dotca last edited by

                    @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. πŸ™‚

                    --
                    Dustin Dauncey
                    www.d19.ca

                    d19dotca 1 Reply Last reply Reply Quote 2
                    • d19dotca
                      d19dotca @d19dotca last edited by

                      Just to be clear, I suppose the cron time needs to be in UTC? Or does it respect the local time zone instead taken from Cloudron settings?

                      --
                      Dustin Dauncey
                      www.d19.ca

                      girish 1 Reply Last reply Reply Quote 0
                      • girish
                        girish Staff @d19dotca last edited by

                        @d19dotca yes, UTC

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post
                        Powered by NodeBB