3 Wrap a command, setuid/setgid, change directory to the reddit
4 code, and send output to syslog.
6 The following environment variables may be used to control
7 the environment the wrapped command runs in:
11 The user to run the job as. Defaults to "reddit".
15 The group to run the job as. Defaults to $REDDIT_USER.
19 The root directory of the reddit package. It's where the makefile lives.
23 The syslog facility to write messages to.
34 CONSUMER_PREFIX
= "reddit-consumer-"
38 user
= os
.environ
.get("REDDIT_USER", "reddit")
39 group
= os
.environ
.get("REDDIT_GROUP", user
)
40 uid
= pwd
.getpwnam(user
).pw_uid
41 gid
= grp
.getgrnam(group
).gr_gid
46 # change directory to the reddit code root
47 root
= os
.environ
.get("REDDIT_ROOT", "/opt/reddit/lib/public/r2")
51 job_name
= os
.environ
.get("UPSTART_JOB", "-".join(sys
.argv
[1:]))
52 if job_name
.startswith(CONSUMER_PREFIX
):
53 # consumers are a bit different from crons, while crons want an
54 # ident of reddit-job-JOBNAME, we want consumers to have an ident
55 # of CONSUMERNAME_INSTANCE
56 job_name
= (job_name
[len(CONSUMER_PREFIX
):] +
58 os
.environ
.get("UPSTART_INSTANCE", ""))
59 facility
= getattr(syslog
, "LOG_" + os
.environ
.get("REDDIT_LOG_FACILITY", "CRON"))
60 syslog
.openlog(ident
=job_name
, facility
=facility
)
62 # run the wrapped command
63 child
= subprocess
.Popen(sys
.argv
[1:],
64 stdout
=subprocess
.PIPE
,
65 stderr
=subprocess
.STDOUT
,
70 line
= child
.stdout
.readline()
75 line
= line
.rstrip('\n')
76 syslog
.syslog(syslog
.LOG_NOTICE
, line
)
79 # our success depends on our child's success
81 sys
.exit(child
.returncode
)