Is it possible to have cron job running on Amazon lightsail instance?

前端 未结 2 2283
醉话见心
醉话见心 2021-02-20 14:54

I would like to set up periodic jobs on an Amazon Lightsail instance, but I can find no information on it - only for Amazon EC2.

Is it possible to issue cron jobs on a l

2条回答
  •  死守一世寂寞
    2021-02-20 15:38

    If you are using node.js, you can do this by adding a few lines to your crontab. First, open the crontab

    crontab -e
    

    Add these three lines at the end of the file. I'm assuming you are using forever.

    PATH=/usr/bin:/bin:/opt/bitnami/nodejs/bin:
    @reboot cd /home/bitnami/**THISISYOURFOLDER** && /opt/bitnami/nodejs/bin/forever **NAMEOFYOURAPP.JS**
    0 1 * * * sudo reboot
    

    This will run your app that is in THISISYOURFOLDER when the system reboots. In addition, I'm setting it up to reboot at 1am everyday with this setting.

    To test this, you can use

    * * * * * cd /home/bitnami/**THISISYOURFOLDER** && touch myfile.txt
    

    in your crontab. This needs to create myfile.txt in your target folder after a minute. If it doesn't you need to change your path setting. There is also a difference between

    sudo crontab -e
    crontab -e
    

    Find time settings at https://crontab.guru/

提交回复
热议问题