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.1.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.1-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: SchedulerX-0.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 fe3e23624378e9b20c6470e4b1f0123ce530728455eee6ab58adc1e7080aeefe
MD5 65d1302a714dff13cc6a565f2558f978
BLAKE2b-256 9339b8b7cffc3954f4fb89fa8aa2c110bca70c557f7d2b5b5f44f2e325d5b6f8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: SchedulerX-0.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d1dbbfa8b6e83fd0132cb5fa6e9f17f706bf6b2fa4e38eb84c5774848e1d0164
MD5 50992e79d66ec3b240701f8154aec2ed
BLAKE2b-256 81244014196b5b80e990b1d1f9ec960d3e2ae381037640efb90390c61febdd5b

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