From 8a5857967a61958269e7f58a93913ab7fdab7bb8 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 28 Nov 2020 23:08:23 +0100 Subject: [PATCH] Add a systemd service and timer for updatedb, obsoleting the cron entry. --- README | 3 ++- meson.build | 12 ++++++++++++ meson_options.txt | 3 ++- plocate-updatedb.service.in | 14 ++++++++++++++ plocate-updatedb.timer | 9 +++++++++ 5 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 plocate-updatedb.service.in create mode 100644 plocate-updatedb.timer diff --git a/README b/README index 75da95b..df4b07a 100644 --- a/README +++ b/README @@ -16,10 +16,11 @@ do not have an SSD. Installation is run as: cd obj ninja sudo ninja install + sudo addgroup plocate + sudo systemctl enable plocate-updatedb.timer To build the database for the first time after install, you can do - sudo addgroup mlocate sudo updatedb The initial run of updatedb needs to scan the entire filesystem. diff --git a/meson.build b/meson.build index 31f51d8..b963c03 100644 --- a/meson.build +++ b/meson.build @@ -63,6 +63,18 @@ endif install_man('plocate.1') install_man('plocate-build.8') +if get_option('install_systemd') + systemd = dependency('systemd', required: false) + if systemd.found() + unitdir = systemd.get_pkgconfig_variable('systemdsystemunitdir') + updatedb_service = configure_file(input: 'plocate-updatedb.service.in', + output: 'plocate-updatedb.service', + configuration: conf_data) + install_data(updatedb_service, install_dir: unitdir) + install_data('plocate-updatedb.timer', install_dir: unitdir) + endif +endif + # Requires having TurboPFor checked out, so not built by default. # Unless you have a recent Meson, there's no apparently good way # of calling into that directory to run make, and we're not diff --git a/meson_options.txt b/meson_options.txt index 3e2f6cc..f261155 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,2 +1,3 @@ -option('install_cron', type: 'boolean', value: true, description: 'Install update script into /etc/cron.daily') +option('install_cron', type: 'boolean', value: false, description: 'Install mlocate conversion script into /etc/cron.daily') +option('install_systemd', type: 'boolean', value: true, description: 'Install systemd service and timer for updatedb, if systemd is installed') option('locategroup', type: 'string', value: 'plocate', description: 'Group that the install script will use for the .db file') diff --git a/plocate-updatedb.service.in b/plocate-updatedb.service.in new file mode 100644 index 0000000..8db7dba --- /dev/null +++ b/plocate-updatedb.service.in @@ -0,0 +1,14 @@ +[Unit] +Description=Update the plocate database +ConditionACPower=true + +[Service] +Type=oneshot +ExecStart=@sbindir@/updatedb +LimitNOFILE=131072 +IOSchedulingClass=idle + +PrivateTmp=true +PrivateDevices=true +PrivateNetwork=true +ProtectSystem=full diff --git a/plocate-updatedb.timer b/plocate-updatedb.timer new file mode 100644 index 0000000..1f69330 --- /dev/null +++ b/plocate-updatedb.timer @@ -0,0 +1,9 @@ +[Unit] +Description=Update the plocate database daily + +[Timer] +OnCalendar=daily +Persistent=true + +[Install] +WantedBy=timers.target -- 2.39.2