Ok, Googling this, finding this U&L answer, checking its revisions history and following the quoted source in the revision #1, this happens to be an Upstart bug; the problem is that when switching to root running su
the $UPSTART_SESSION
environment variable is carried from the previous environment instead of being set again.
After much banging my head and googling, I've found a post (https://unix.stackexchange.com/questions/120050/sudo-service-vsftpd-returns-unknown-job-vsftpd) showing that
sudo service xxxx start
(or stop, or restart)
works, while
`service xxxx start (in a su session)
does not work.
So the culprit was clearly the environment: If you go root with "su" instead of "sudo su" or "su -", "service" does not to work correctly either, as "su" will carry most of your normal user environment to the root session.
After some testings, I found that the culprit is the UPSTART_SESSION environment variable, which comes set when you "su", but not set when you "sudo su" or "su -". Here are some test results:
-- does not work
jsveiga@dell:~$ su
Password:
root@dell:/home/jsveiga# service smbd restart
stop: Unknown job: smbd
start: Unknown job: smbd
-- works even from a su session
root@dell:/home/jsveiga# sudo service smbd restart
smbd stop/waiting
smbd start/running, process 3823
-- works
root@dell:/home/jsveiga# exit
jsveiga@dell:~$ sudo su
root@dell:/home/jsveiga# service smbd restart
smbd stop/waiting
smbd start/running, process 3862
-- works
root@dell:/home/jsveiga# exit
jsveiga@dell:~$ su -
Password:
root@dell:~# service smbd restart
smbd stop/waiting
smbd start/running, process 3905
-- going su then unsetting the UPSTART_SESSION works
root@dell:/home/jsveiga# exit
jsveiga@dell:~$ su
Password:
root@dell:/home/jsveiga# service smbd restart
stop: Unknown job: smbd
start: Unknown job: smbd
root@dell:/home/jsveiga# unset UPSTART_SESSION
root@dell:/home/jsveiga# service smbd restart
smbd stop/waiting
smbd start/running, process 4244
So the start/stop scripts are failing somehow simply by the presence of the UPSTART_SESSION
environment variable.
BR,
Joao S Veiga
To fix this, just unset $UPSTART_SESSION
:
unset UPSTART_SESSION
or switch to root by other means, like su -
, sudo su
or sudo -i
.