3 \¼mež ã @sÂUdZddlZddlZddlmZddlmZddlmZddl m Z ddl m Z m Z ddlmZdd lmZd Zd d d eegeedƒgdgdœZe e eƒZejeƒZee eeddœdd„ZdS)zERuncmd: run arbitrary commands at rc.local with output to the consoleéN)Údedent)Úutil)ÚCloud)ÚConfig)Ú MetaSchemaÚ get_meta_doc)Ú ALL_DISTROS)Ú PER_INSTANCEaRun arbitrary commands at a rc.local like time-frame with output to the console. Each item can be either a list or a string. The item type affects how it is executed: * If the item is a string, it will be interpreted by ``sh``. * If the item is a list, the items will be executed as if passed to execve(3) (with the first arg as the command). Note that the ``runcmd`` module only writes the script to be run later. The module that actually runs the script is ``scripts_user`` in the :ref:`Final` boot stage. .. note:: all commands must be proper yaml, so you have to quote any characters yaml would eat (':' can be problematic) .. note:: when writing files, do not use /tmp dir as it races with systemd-tmpfiles-clean LP: #1707222. Use /run/somedir instead. Z cc_runcmdZRuncmdzRun arbitrary commandsa runcmd: - [ ls, -l, / ] - [ sh, -xc, "echo $(date) ': hello world!'" ] - [ sh, -c, echo "=========hello world'=========" ] - ls -l /root - [ wget, "http://example.org", -O, /tmp/index.html ] Úruncmd)ÚidÚnameÚtitleÚ descriptionZdistrosZ frequencyZexamplesZactivate_by_schema_keys)r ÚcfgÚcloudÚargsÚreturncCsŒd|krtjd|ƒdStjj|jdƒdƒ}|d}ytj|ƒ}tj||dƒWn6t k r†}zt |ƒdj ||ƒƒ‚WYdd}~XnXdS)Nr z:Skipping module named %s, no 'runcmd' key in configurationÚscriptsiÀz"Failed to shellify {} into file {}) ÚLOGÚdebugÚosÚpathÚjoinZ get_ipathrZshellifyZ write_fileÚ ExceptionÚtypeÚformat)r rrrZout_fnÚcmdZcontentÚe©rú/usr/lib/python3.6/cc_runcmd.pyÚhandleQs r )Ú__doc__ZloggingrÚtextwraprZ cloudinitrZcloudinit.cloudrZcloudinit.configrZcloudinit.config.schemarrZcloudinit.distrosrZcloudinit.settingsr ZMODULE_DESCRIPTIONÚmetaZ getLoggerÚ__name__rÚstrÚlistr rrrrÚ s,