2

As you can see from the following output(not limited to mysql, other service gives similar result), when run service/status with sudo, it gives correct result, but gives 'Unknown job' when run directly with root.

I googled a lot, but key words like 'status/service' have multiple meaning, so i found nothing related to this problem, only some similar questions answering why 'unknown job' when run with 'sudo service...'.

root@ubuntu-user:/etc/init# status mysql
status: Unknown job: mysql

root@ubuntu-user:/etc/init# sudo status mysql
mysql stop/waiting

root@ubuntu-user:/etc/init# service mysql status
status: Unknown job: mysql

root@ubuntu-user:/etc/init# sudo service mysql status
mysql stop/waiting

I have checked with strace, didn't find anything(output is too long), and I think it's the restriction of status and service, but nothing in man page about root or sudo.

Question: why service gives Unknown job when runs service without sudo?

OS: Ubuntu 14.04 LTS

D3Hunter
  • 1,329
  • 10
  • 21

2 Answers2

0

If you use upstart v1.4+, try setuid and setgid. More details here:http://upstart.ubuntu.com/cookbook/#run-a-job-as-a-different-user and http://upstart.ubuntu.com/cookbook/#setuid

BAE
  • 8,550
  • 22
  • 88
  • 171
0

This is probably because initctl (which is part of upstart and is sometimes called behind the scenes) is looking on the user session rather than the system session for service scripts that are system only. Try using sudo -s or su - to become root and then running your service command as this will cause the UPSTART_SESSION variable to be removed...

See the Running initctl as root broken bug for details.

Anon
  • 339
  • 5
  • 8