Skip to main content

Schedule a task using systemd services and timer

Project description

SchedulerX

Authors

Installation

pip install SchedulerX

Setting ROOT_PASSWORD to env variable

Handling systemd needs root privilege so this why we export it. so, you need to run this command and change the <your-root-password> with your root password

export ROOT_PASSWORD="<your-root-password>"

Usage/Examples

For simple usage, you have to know how to set onCalendar in systemd

from schedulerx import SimpleScheduler

scheduler = SimpleScheduler(
    title="shutdown at midnight",
    command="shutdown now",
    on_calendar=@daily
)

scheduler.schedule()

for more complex usage you have to know about how we create a timer and a service in systemd
And then you can use ServiceTimerManager

from schedulerx import ServiceTimerManager

service_timer = ServiceTimerManager(
    service_filename="shutdown.service",
    service_description="shutdown at midnight",
    command="shutdown now",
    timer_filename="shutdown.timer",
    timer_description="shutdown at midnight timer",
    on_calendar="@daily",
)

service_timer.schedule()

License

MIT

Class Diagram of SchedulerX

classDiagram

class PasswordHelper{
    +get_root_password()
}

class CommandHandler{
    +run_shell_command_with_input(command: string, password: string): string
    +run_shell_command_as_root(command: string)
}

class PermissionManager{
    -command_handler: CommandHandler
    +change_path_permissions(path: string, permissions: string)
    +is_writable(path: string): boolean
}

class FileManager{
    filename: string
    overwrite: string = False
    -permission_manager: PermissionManager
    <<property>> +file_full_path(): string
    -save_origin_systemd_writable_permission()
    +create_file(content: string)
    +is_file_exist(): boolean
    +check_permissions()
}

class ServiceManager{
    +filename: string
    +command: string
    +description: string = ""
    +overwrite: boolean = False
    +create_service_file()
    -get_service_text(): string
}

class TimerManager{
    +filename: string
    +description: string = ""
    +on_calendar: string
    +service_manager: ServiceManager
    -file_manager: FileManager
    -command_handler: CommandHandler
    -get_timer_text(): string
    +create_timer()
    +start_timer()
}

class ServiceTimerManager{
    +service_filename: string
    +service_description: string = ""
    +command: string

    +timer_filename: string
    +timer_description: string = ""
    +on_calendar: string
    +overwrite: boolean = False
    -service_manager: ServiceManager
    -timer_manager: TimerManager
    +schedule()
    -create_service()
    -create_timer()
}

class SimpleSchedule{
    +title: string
    +command: string
    +on_calendar: string
    +overwrite: boolean = False
    +schedule()
}
CommandHandler --> PasswordHelper
PermissionManager --> CommandHandler
FileManager --> PermissionManager
ServiceManager --> FileManager
TimerManager --> ServiceManager
TimerManager --> FileManager
TimerManager --> CommandHandler
ServiceTimerManager --> ServiceManager
ServiceTimerManager --> TimerManager
SimpleSchedule --> ServiceTimerManager

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

SchedulerX-0.0.3.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

SchedulerX-0.0.3-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file SchedulerX-0.0.3.tar.gz.

File metadata

  • Download URL: SchedulerX-0.0.3.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for SchedulerX-0.0.3.tar.gz
Algorithm Hash digest
SHA256 31b1a970a3c7f13726be17f0fc518ce3dc54804785b51620d81c25570460a103
MD5 91735627729b3d76e01dbd9a36c57f41
BLAKE2b-256 8b83b26aef6bf220fb67c9e45603b4c78ee87f152795dbad072453f0f7bd0627

See more details on using hashes here.

File details

Details for the file SchedulerX-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: SchedulerX-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for SchedulerX-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8b1a96d82205d7965eb2c8b01f1ae913b0feb160fab1943664fb90752cbcd12b
MD5 5d05d8fd813b6bd2e2bef46fbc806757
BLAKE2b-256 5d3cf21b5273ac1333b25b31e3ad3cb96b7e73872e552e2afb6cf838c0ecc6d2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page