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


Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Bookmarks
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

Cloudron Forum

Apps | Demo | Docs | Install
  1. Cloudron Forum
  2. Support
  3. Run cron once on after app update

Run cron once on after app update

Scheduled Pinned Locked Moved Solved Support
cron
5 Posts 2 Posters 748 Views 2 Watching
  • 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.
  • LanhildL Offline
    LanhildL Offline
    Lanhild
    App Dev
    wrote on last edited by girish
    #1

    Hi,

    How would I go about running a cron in an application after its update?

    How can we see it's correctly loaded?

    girishG 1 Reply Last reply
    1
    • LanhildL Offline
      LanhildL Offline
      Lanhild
      App Dev
      wrote on last edited by
      #2

      Also, in the same cronjob, how can I restart my application?

      girishG 1 Reply Last reply
      1
      • LanhildL Lanhild

        Hi,

        How would I go about running a cron in an application after its update?

        How can we see it's correctly loaded?

        girishG Offline
        girishG Offline
        girish
        Staff
        wrote on last edited by girish
        #3

        @Lanhild said in Run cron once on after app update:

        How would I go about running a cron in an application after its update?

        There is no hook for update as such and most likely this is not the desired way to code either. Just having a simple update hook will cause issues - the cron could crash halfway (should the hook be called next restart?), clone/restore/import lifecycles etc.

        Similar to database migration scripts, your cron must be capable of being run and also figuring out that it has already done something. Migration scripts usually do this by tracking what changes have been completed in the last run (for example, a simple version number). The cron script can do the same. Save the state in some file in /app/data and then load it before it runs to check if it needs to do something.

        You can run the cron as a @service or @reboot . See https://docs.cloudron.io/apps/#cron

        1 Reply Last reply
        1
        • LanhildL Lanhild

          Also, in the same cronjob, how can I restart my application?

          girishG Offline
          girishG Offline
          girish
          Staff
          wrote on last edited by
          #4

          @Lanhild said in Run cron once on after app update:

          Also, in the same cronjob, how can I restart my application?

          The cronjob runs in the same pid space as the app itself. Meaning, the app can be controlled by the cronjob using linux signals. Maybe kill it or send it some friendly signal to reload/restart. If your app uses supervisor, you can just do supervisor restart app.

          1 Reply Last reply
          2
          • LanhildL Offline
            LanhildL Offline
            Lanhild
            App Dev
            wrote on last edited by
            #5

            Thanks, that solves it!

            1 Reply Last reply
            0
            • girishG girish marked this topic as a question on
            • girishG girish has marked this topic as solved on
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Bookmarks
            • Search