0

I'm trying to run Nginx using Systemd as a process manager.

When I run sudo service nginx start and then type ps -aux | grep nginx it appears to be the same process running as when I started it using sudo systemctl start nginx.

Is this the case, that service could be mapped to systemctl? How can I tell?

When I look at /etc/init.d/nginx the script is very different from the config at /lib/systemd/system/nginx.service.

However, if I start nginx using the systemctl command and then stop it using the service command that works fine. Same in the reverse order.

0
sudo strace -f -e trace=process service nginx status 2>&1 | grep systemctl
| improve this answer | |
0

As the saying goes, "There's more than one way to cat a file". In this case, it's not absolutely clear what you mean by 'the same process running', so I'll explain both possible issues.

If what you mean is that you have the same process ID running if you first do a 'systemctl ngix start', and then do a 'service ngix start'. This would be because if a daemon is already running, a 'start' process will not shut it down and start a new one. In such a situation, the result should be a no-op. Do a stop before you do a subsequent start, or use a restart command instead.

If you did do a stop (or a reboot) between the two start commands, and you're seeing ngix running in both cases -- with the same parameters to the command, even though the process IDs are different, then the 'problem' is that in both cases, the ultimate goal is to get ngix running. The locations of content and configuration files don't change. The options you want to use don't change just because different programs start them. It's pretty much just a case of 'all roads lead to Rome'.

Finally, if you suspect that systemctl and service are links to the same file, then try.

cmp `which systemctl` `which service` 

That will tell you if systemctl and service both contain exactly the same code (and/or are links to the same file).

| improve this answer | |
0

I'd start with which systemctl and which service, and then look at the output of ls -l for both to see if they are the same file (via symlink) or look similar (size, etc).

At least here (Fedora 23) /usr/bin/systemctl is a binary, /usr/sbin/service is a shell script that uses systemd commands to emulate the SysVinit command.

| improve this answer | |
  • What do you mean by "a shell script that uses systemd commands to emulate the SysVinit command"? I believe what's happening is that service nginx start is running this shell script that invokes the systemctl command...plus a lot of other stuff. systemctl start nginx seems to just start the SystemD process. Probably a separate question, but is one way of running nginx better than the other? – YPCrumble Jan 27 '16 at 3:57
  • @YPCrumble, just that here service uses the very same systemd machinery to offer the legacy functionality. – vonbrand Jan 28 '16 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.