0

I have the following service:

[Unit]
Description=foo

[Service]
Type=oneshot
RemainAfterExit=true
ExecStop=/opt/script/bar.sh

[Install]
WantedBy=multi-user.target

And bar.sh:

#!/bin/bash
echo 1 > /sys/bus/workqueue/devices/writeback/cpumask
cat /sys/bus/workqueue/devices/writeback/cpumask > /tmp/writeback

Then after I rebooted, cat /tmp/writeback looks good: 000000,00000000,00000000,00000000,00000000,00000000,00000000,00000001

But /sys/bus/workqueue/devices/writeback/cpumask got overwritten back to default:

ffffff,ffffffff,ffffffff,ffffffff,ffffffff,ffffffff,ffffffff,ffffffff

Thought?

HCSF
  • 245
  • 3
  • 14
  • Be aware that a malicious local user might create a symlink from `/tmp/writeback` to `/etc/passwd` or `/sbin/init` and deny service to users. The output file should be created in a directory writable only by root. – Anderson Medeiros Gomes Feb 15 '20 at 19:22
  • @AndersonMedeirosGomes thanks. was trying to debug only. will fix. :) – HCSF Feb 16 '20 at 02:40

1 Answers1

2

maybe use ExecStart instead of ExecStop?

natxo asenjo
  • 5,739
  • 2
  • 26
  • 27
  • That's fine according to the [manual](https://www.freedesktop.org/software/systemd/man/systemd.service.html). And `/tmp/writeback` was written and so we know the `/opt/script/bar.sh` had been executed (successfully). – HCSF Feb 16 '20 at 02:43
  • 2
    in the link you send you can clearly read: "Commands to execute to stop the service started via ExecStart=.", so it's never going to run after starting the service. Only after stopping it, and only if it had successfully started. I just tried, when you start the service, it does nothing but the service starts (doing nothing), when you stop the service, the command runs, and the file gets written, and the value of cpumask gets set to 1 – natxo asenjo Feb 16 '20 at 09:05