Просмотр исходного кода

added a script that installs the timers in the correct location. And updated the readme in that folder

master
Wouter Horlings 6 лет назад
Родитель
Сommit
413f687c9e
2 измененных файлов: 63 добавлений и 4 удалений
  1. +8
    -4
      systemd_timer_files/README.md
  2. +55
    -0
      systemd_timer_files/settimer.sh

+ 8
- 4
systemd_timer_files/README.md Просмотреть файл

@@ -1,9 +1,13 @@
# Installation of timer files
Easiest way is to run `settimer.sh` from inside the git repo.
The scripts expect that the virtual environment for python is already setup correctly in `.venv`

# Setting the correct path


## Setting the correct path
In `pythontaskcheck.timer` replace `[[path_to_repo]]` with the absolute path to the repo root.

# Setting up systemd.timer
## Setting up systemd.timer
Move `pythontaskcheck.timer` and `pytontaskcheck.service` to the `$XDG_RUNTIME_DIR/systemd/user/` dir.
Run the following commands to enable the scheduled execution.
```
@@ -12,7 +16,7 @@ $ systemctl --user enable pythontaskcheck.timer
$ systemctl --user start pythontaskcheck.timer
```

# Check if everything is working
## Check if everything is working
```
$ systemctl --user start pythontaskcheck.service
```
@@ -22,6 +26,6 @@ $ systemctl list-timers --user
```
shows the list with timers. Yours should be listed here.

# updating the time.
## updating the time.
Current setup will trigger the script every 5 minutes from 9:00 till 17:55


+ 55
- 0
systemd_timer_files/settimer.sh Просмотреть файл

@@ -0,0 +1,55 @@
#!/bin/bash

# Function to set the path correct in the config files and store them in the correct location.
replace_and_move() {
# The ${GIT_DIR//\//\\\/} replaces '/' with '\/' as '/' is a control char in regex
REPLACE_STR="s/\[\[path_to_repo\\]\\]/${GIT_DIR//\//\\\/}/g"
OUTDIR="$DIRECTORY/$1"
# Parse the file trough `sed` and write output to correct directory
sed $REPLACE_STR $2/$1 > $OUTDIR
echo "$1 script placed at $OUTDIR"
}

###################
# START OF SCRIPT #
###################
# Check if XDG_CONFIG_HOME is set and select correct config file location.
# See also: systemd.unit manual - section: UNIT FILE LOAD PATH
if [[ -e $XDG_CONFIG_HOME ]]; then
DIRECTORY=$XDG_CONFIG_HOME/systemd/user
else
DIRECTORY=$HOME/.config/systemd/user
fi
echo "The scripts will be put in $DIRECTORY"
# The following git command will give the root of the current repo.
GIT_DIR=`git rev-parse --show-toplevel`
echo "Root of this git repo is: $GIT_DIR"
if [[ -e $GIT_DIR/.venv/bin/python3 ]]; then
echo "Found a virtual environment for Python in the repo"
else
echo "Pythons virtual environment not found at '$GIT_DIT/.venv'. "
#There should be a setup.sh file in the directory that setups the virtual environment for python
if [[ -f $GIT_DIR/setup.sh ]]; then
echo "Have you tried running '$GIT_DIR/setup.sh'?"
fi
echo "I could install config files, but they whould not work. Aborting now"
exit
fi

FILENAME="pythontaskcheck"
FOLDERNAME="systemd_timer_files"
MAPPATH="$GIT_DIR/$FOLDERNAME/"
TIMERNAME="$FILENAME.timer"
SERVICENAME="$FILENAME.service"
replace_and_move $TIMERNAME $MAPPATH
replace_and_move $SERVICENAME $MAPPATH

echo "Enable $TIMERNAME for systemd"
`systemctl --user enable $TIMERNAME`
echo "Start $TIMERNAME for systemd"
`systemctl --user start $TIMERNAME`






Загрузка…
Отмена
Сохранить