Skip to content

Instantly share code, notes, and snippets.

@JosiahKerley
Created December 16, 2016 16:29
Show Gist options
  • Save JosiahKerley/c99c07eafc045f5b878d853b5af73263 to your computer and use it in GitHub Desktop.
Save JosiahKerley/c99c07eafc045f5b878d853b5af73263 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import argparse
parser = argparse.ArgumentParser(description='Libvirt based VM builder')
parser.add_argument('--name', '-n', action="store", dest="name", required=True, help='Name of the service')
parser.add_argument('--description', '-d', action="store", dest="description", default=None, required=False, help='Descriprion of the service')
parser.add_argument('--command', '-c', action="store", dest="command", required=True, help='Bash command to execute')
results = parser.parse_args()
if results.description == None:
results.description = results.name
template = '''
[Unit]
Description={}
[Service]
Type=simple
User=root
Restart=always
ExecStart={}
[Install]
WantedBy=multi-user.target
'''
unit_filepath = '/etc/systemd/system/{}.service'.format(results.name)
unit_string = template.format(results.description,results.command)
with open(unit_filepath,'w') as f:
f.write(unit_string)
print('writing into {}'.format(unit_filepath))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment