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.2.tar.gz (7.0 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.2-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: SchedulerX-0.0.2.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0rc1

File hashes

Hashes for SchedulerX-0.0.2.tar.gz
Algorithm Hash digest
SHA256 606b48dcd5c784b6f27de01dec9af15fd062e74a8b1e2f35ee8b3bf8f734085e
MD5 dd82293fcba1ad1cc5b58266344c03f3
BLAKE2b-256 9a198574141058a91d912c28bb5adf84615a213e8f7d2fa0799301100f2d0f20

See more details on using hashes here.

File details

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

File metadata

  • Download URL: SchedulerX-0.0.2-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.11.0rc1

File hashes

Hashes for SchedulerX-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a82d1a3b7d607561beeb41836a82d1595ca685fb69446d2646183603e1f6bb45
MD5 aab5273c9cc6545bad2a7d024a086c1f
BLAKE2b-256 22fe80d0b478cf209f93fa2774744db2e43f225355dc3c842a04f2ec8494bb20

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