I tried all the suggestions in this and some locations on the web I could find. None worked except the wrapper. I added the SETUID
bit, copied the .so
file first to /tmp
, then to /usr/lib/x86_64-linux-gnu
, then tried to include the library without slashes, i.e.
...
[Service]
Environment="MARK=10 LD_PRELOAD=mark.so"
...
Still no-go. An interactive run, however, worked as expected (I was setting up a route-jail for nginx
). The LD_PRELOAD
also could not be placed in front of the executable name on the ExecStart
line, as it resulted in an error.
In the end, creating a wrapper worked, and the systemctl
operation still seems to be normal, i.e., systemctl
brings up the service, shows its status, and shuts it down as expected. I ended up with:
...
[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -q -g 'daemon on; master_process on;'
ExecStart=/tmp/testnginx.sh
ExecReload=/usr/sbin/nginx -g 'daemon on; master_process on;' -s reload
ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid
TimeoutStopSec=5
KillMode=mixed
...
The only line modified in the systemd
script is ExecStart
. The wrapper (which I'll move to some more sensible location from /tmp
), is simple:
#!/bin/bash
MARK=10 LD_PRELOAD=mark.so /usr/sbin/nginx -g 'daemon on; master_process on;'
The wrapper is just chmod 755
; it doesn't have the SETUID
bit set.
This is on Ubuntu 22.04.