Skip to content

Include systemd scheduling instructions #1

@I33Buckler

Description

@I33Buckler

Would be useful to include systemd scheduling information for those who wish to use the scheduler. These are the steps that I have noted after copying magichosts to /usr/local/bin and modifying as required

  1. cd to /etc/systemd/system
  2. Create the file magichosts.service as follows
[Unit]
Description=Script to swith /etc/hosts when connected to LAN at home

[Service]
Type=oneshot
ExecStart=/usr/local/bin/magichosts

  1. For scheduling create the file magichosts.timer with the following which will run the magichosts.service every minute.
[Unit]
Description=Check for wireless connection every minute

[Timer]
OnCalendar=*-*-* *:*:00
Persistent=Ttrue

[Install] 
WantedBy=timers.target

Confirm the details of the scheduling parameters. This will show the next 5 scheduled instances according to the parameters for OnCalendar.

systemd-analyze calendar --iterations=5 '*-*-* *:*:00'

Information on systemd timers at https://wiki.archlinux.org/title/Systemd/Timers
4. Enable the systemd timer with the following
i) Reload systemd

sudo systemctl daemon-reload

ii) Enable the timer to run on boot

sudo systemctl enable magichosts

iii) Start the timer immediately

sudo systemctl start magichosts

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions