Transcript
  • Servers and Tools

Installing a Service

From the class:  Managing Processes with systemd

Now we're going to install our service. So change into the Vagrant folder and take a look at its contents. Make sure the hello.service file is in there. And what we can do is pseudo-copy that file, hello.service. And we're going to put it into the lib/systemd/system folder.

Simply by having this unit configuration file in this folder, system D will know about our service. And so we don't need to do anything else. It's going to be aware of that folder because it's part of a look-up path. So system D will automatically look in this folder for any configuration files. But we haven't enabled the service yet. And we can confirm that by saying system control is enabled hello.

And we should get back that it's disabled because we haven't actually enabled it yet. And again, we could say system control status hello. And it says that it knows about it. Notice that it's even giving us the descriptions. So it knows that that configuration file is there. And it's loaded, but it's disabled. And it's currently in an inactive state or dead.

Let's go ahead and enable it. We'll use pseudo privileges and say system control enable hello. And again, we're leaving off the service because it's just assumed. And notice the message that we get here. System control is telling us that what it did on our behalf was it created a symlink. A symlink is just a file that points to another file.

And it created a symlink from this file that we just put in here. So we put this hello.service file into the systemd/system folder under lib. And inside of the et cetera system D system. And then this weird folder that got created, multiusertarget.wants. And then inside of that folder, a file hello.service which just points-- it's just a pointer-- to this file.

What this is doing is when we reboot the system, any of the files that are inside of here, inside of this folder here, will automatically get started as the system boots up when the system reaches a state of multi-user target. So this could be something else.

It could be networking, for example, in which case our service would automatically be started when we reach the state of networking being turned on. Or it might be graphical user interface, in which case it'll wait until the graphical user interface has started up, and then it'll start our service.

And so this symlink is really the only magic that was performed when we enabled this service. Now we should be able to start up our service just like Nginx or Mongo. I'll just type pseudo system control start hello.

We didn't get any error messages, so it looks like things are OK. But just to make sure, we can say system control status hello. And it looks like it succeeded. So we see this message here, active, and that it's running. And we have an active PID, or process ID, of 8131 running with the review program.

And if you want to see it in the process tree, we can say psajxf. And notice it down there at the bottom. So we are indeed running our program, hello rb. And it's got a PID and it's attached to the parent process of init.