SystemdConfigFileOptions

class aws_cdk.aws_ec2.SystemdConfigFileOptions(*, command, after_network=None, cwd=None, description=None, group=None, keep_running=None, user=None)

Bases: object

Options for creating a SystemD configuration file.

Parameters:
  • command (str) – The command to run to start this service.

  • after_network (Optional[bool]) – Start the service after the networking part of the OS comes up. Default: true

  • cwd (Optional[str]) – The working directory for the command. Default: Root directory or home directory of specified user

  • description (Optional[str]) – A description of this service. Default: - No description

  • group (Optional[str]) – The group to execute the process under. Default: root

  • keep_running (Optional[bool]) – Keep the process running all the time. Restarts the process when it exits for any reason other than the machine shutting down. Default: true

  • user (Optional[str]) – The user to execute the process under. Default: root

ExampleMetadata:

infused

Example:

# vpc: ec2.Vpc
# instance_type: ec2.InstanceType


ec2.Instance(self, "Instance",
    vpc=vpc,
    instance_type=instance_type,
    machine_image=ec2.MachineImage.latest_amazon_linux2023(),

    init=ec2.CloudFormationInit.from_elements(
        # Create a simple config file that runs a Python web server
        ec2.InitService.systemd_config_file("simpleserver",
            command="/usr/bin/python3 -m http.server 8080",
            cwd="/var/www/html"
        ),
        # Start the server using SystemD
        ec2.InitService.enable("simpleserver",
            service_manager=ec2.ServiceManager.SYSTEMD
        ),
        # Drop an example file to show the web server working
        ec2.InitFile.from_string("/var/www/html/index.html", "Hello! It's working!"))
)

Attributes

after_network

Start the service after the networking part of the OS comes up.

Default:

true

command

The command to run to start this service.

cwd

The working directory for the command.

Default:

Root directory or home directory of specified user

description

A description of this service.

Default:
  • No description

group

The group to execute the process under.

Default:

root

keep_running

Keep the process running all the time.

Restarts the process when it exits for any reason other than the machine shutting down.

Default:

true

user

The user to execute the process under.

Default:

root