-
Notifications
You must be signed in to change notification settings - Fork 0
/
cron.py
51 lines (40 loc) · 1.03 KB
/
cron.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from fabdeploy.lib.utils import _AttrDict, _is_host
from fabric.api import run,sudo,env,task
from fabric.contrib import files
from fabdeploy.servers import get_server
from pdb import set_trace as brake
@task
def configure():
"""
configures cron jobs
"""
env.log_path = env.log_path + '/cron/execution.log',
generate_cron_file()
set_crontab()
remove_cron_file()
@task
def append():
"""
adds cron job
"""
# create tmp cron file
generate_cron_file()
# append existing crontab
run('crontab -l >>%s' % env.crontab_path_tmp)
set_crontab()
remove_cron_file()
def set_crontab():
run('crontab %s' % env.crontab_path_tmp)
def generate_cron_file():
"""
creates temporary cron file
"""
import os
files.upload_template(
filename = os.path.abspath(env.crontab_origin_relative_path),
destination = env.crontab_path_tmp,
use_sudo = env.use_sudo,
context = env
)
def remove_cron_file():
run('rm %s' % env.crontab_path_tmp)