3
\¼mež ã @ s U d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl m
Z
ddlmZm
Z
ddlmZ dd lmZ d
Zddd
eegeedƒgdgdœZee
eƒZ ejeƒ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_INSTANCEa Run 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Úreturnc C sŒ d|krt jd| ƒ d S tjj|jdƒdƒ}|d }ytj|ƒ}tj||dƒ W n6 t k
r† } zt
|ƒdj||ƒƒ‚W Y d d }~X nX d S )Nr
z:Skipping module named %s, no 'runcmd' key in configurationÚscriptsiÀ z"Failed to shellify {} into file {})ÚLOGÚdebugÚosÚpathÚjoinZ get_ipathr ZshellifyZ
write_fileÚ ExceptionÚtypeÚformat)r r r r Zout_fnÚcmdZcontentÚe© r ú/usr/lib/python3.6/cc_runcmd.pyÚhandleQ s
r )Ú__doc__Zloggingr Útextwrapr Z cloudinitr Zcloudinit.cloudr Zcloudinit.configr Zcloudinit.config.schemar r Zcloudinit.distrosr Zcloudinit.settingsr ZMODULE_DESCRIPTIONÚmetaZ getLoggerÚ__name__r ÚstrÚlistr r r r r Ú s,