I have a few upstart
scripts which are run as a non-priviledged user using setuid
. Pid files should be created in /var/run/my-service
: /var/run/my-service/v1.pid
, /var/run/my-service/v2.pid
and so on.
The upstart scripts are created by a script, which also creates /var/run/my-service
and sets the permissions, so everything works initially. But this folder will be gone after a reboot, and services will fail.
I tried this:
pre-start script
[ -n $PID_DIR ] && [ ! -d $PID_DIR ] && mkdir $PID_DIR
sudo chown my-user:my-group $PID_DIR
end script
setuid my-user
But it doesn't work:
sudo: no tty present and no askpass program specified
my-user is not in the sudoers file. This incident will be reported.
I guess it's because setuid
affects all processes, even though it's after the pre-start
and sudo start my-service
was used.
How can I create the folder and set permissions, before the service is started ?