<s> from __future__ import absolute_import , division , with_statement <EOL> from revolver import contextmanager as ctx <EOL> from revolver import core , file <EOL> def add_upstart ( name , content ) : <EOL> if name . endswith ( "<STR_LIT>" ) : <EOL> name = name [ : - <NUM_LIT:5> ] <EOL> upstart_file = "<STR_LIT>" % name <EOL> with ctx . sudo ( ) : <EOL> with ctx . unpatched_state ( ) : <EOL> file . write ( upstart_file , content ) <EOL> def command ( name , command ) : <EOL> initd_file = "<STR_LIT>" % name <EOL> upstart_file = "<STR_LIT>" % name <EOL> if file . exists ( upstart_file ) : <EOL> cmd = "<STR_LIT>" % ( command , name ) <EOL> elif file . exists ( initd_file ) : <EOL> cmd = "<STR_LIT>" % ( initd_file , command ) <EOL> else : <EOL> cmd = "<STR_LIT:false>" <EOL> with ctx . unpatched_state ( ) : <EOL> core . sudo ( cmd ) <EOL> def start ( name ) : <EOL> command ( name , "<STR_LIT:start>" ) <EOL> def stop ( name ) : <EOL> command ( name , "<STR_LIT>" ) <EOL> def restart ( name ) : <EOL> command ( name , "<STR_LIT>" ) <EOL> def reload ( name ) : <EOL> command ( name , "<STR_LIT>" ) <EOL> def is_running ( name ) : <EOL> with ctx . settings ( warn_only = True ) : <EOL> res = core . sudo ( "<STR_LIT>" % name ) <EOL> return res . succeeded </s>
