5

I'm running the following commands in Ubuntu 14.04:

root@ubuntu:~# service rpki-ca restart 
stop: Unknown job: rpki-ca
start: Unknown job: rpki-ca
root@ubuntu:~# sudo service rpki-ca restart 
rpki-ca stop/waiting
rpki-ca start/running
root@ubuntu:~#

What's the effect of sudo in the second command? Why does root need sudo?

9
  • 2
    See unix.stackexchange.com/questions/178980/…
    – Mitch
    Jun 22, 2015 at 14:49
  • 1
    How did you become root? by direct login? I don't think so... Jun 22, 2015 at 15:13
  • Cannot reproduce.
    – muru
    Jun 22, 2015 at 15:15
  • @muru , it depends on how he became root in the first place. Jun 22, 2015 at 15:26
  • @user3073656 indeed. But without that, the question is meaningless.
    – muru
    Jun 22, 2015 at 15:26

2 Answers 2

3

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.

1
  • To fix this, always use login shells: su - or sudo -i.
    – muru
    Jun 22, 2015 at 16:28
0

In that context, it means nothing and should be removed. Without specifying some other user, sudo tries to become root, and so if you are already root, that is a no-op, other than creating an additional process ( for sudo itself ) which occupies some resources until the command it is running finishes.

1
  • 2
    The problem is that apparently without sudo the service won't restart: root@ubuntu:~# service rpki-ca restart; stop: Unknown job: rpki-ca; start: Unknown job: rpki-ca
    – kos
    Jun 22, 2015 at 15:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .