Expand variables in upstart script
I have written several upstart scripts to start transmission-daemon
for several users. The script is this:
start on (local-filesystems and net-device-up IFACE=eth0 and runlevel [235])
stop on runlevel [016]
kill timeout 50
respawn
env USER=user
env PIDFILE=/var/run/transmission-user.pid
script
DAEMON=$(which transmission-daemon) || exit 0
CONFIGDIR=/home/$USER/.config/transmission-daemon
exec start-stop-daemon --start --quiet --chuid $USER --pidfile $PIDFILE --make-pidfile --exec $DAEMON -- -f --config-dir $CONFIGDIR --logfile $CONFIGDIR/daemon.log
end script
post-stop exec rm -f $PIDFILE
I would convert this:
env USER=user
env PIDFILE=/var/run/transmission-user.pid
To this:
env USER=user
env PIDFILE=/var/run/transmission-$USER.pid
But upstart doesn't allow. I can do it if I move those lines to the script section:
script
USER=user
PIDFILE=/var/run/transmission-$USER.pid
...
end script
But in this case, the PIDFILE, in post-stop section, is empty.
Is there any way to do this?
Solution 1:
This is a fairly old bug in upstart:
https://bugs.launchpad.net/upstart/+bug/328366
To get the variable in post-stop and script... you'll just have to set it both times to work around the bug.