-1

I'm new to this process, so bear with me please.

The server is my own socket server, it parses data from connected clients and saves it to a database. It won't serve data in the form of web pages or anything, at the very most it'll retrieve data from the database and send that back to the connected client. I want to set up the server to run as a service, so it will start when the server is booted and I can manage it from the command line more easily. my hardware is running CentOS.

I really don't know where to begin. I've seen a tomcat user, and www-data on other Linux distros, which I believe is also a tomcat user. I imagine these users also have their own folders for storing settings and data, etc.

As you can imagine, searching for this type of information on the internet it's pretty tricky.

I've been reading about the passwd file here and looking at the tomcat user in my passwd file, but it's not making a lot of sense to me. Any pointers you might have would be great!

mal
  • 137
  • 6

1 Answers1

1

Creating a user:

At the simplest level it's a case of using the useradd command, with certain flags. You'll probably want to make sure you create a "system" user so that it doesn't appear on login windows, and if possible give it the shell /sbin/nologin, for security reasons. Also, try and avoid giving it sudo access unless it absolutely needs it - again, for security.

So, you'll need to create the user with something like:

sudo useradd -d /var/lib/socketuser -m -r -s /sbin/nologin socketuser

Which will tell the system to use /var/lib/socketuser as the home directory, create that directory, and apply the two security flags I mentioned.

More generally:

As to making your socket server run at startup as a service, that's a bit more complicated. You probably want to look at packaging your software as an RPM for CentOS, which would manage all the setup required, including creating the user, creating directories that might need creating, placing the service script in the right folder, and enabling it at boot time. If this seems like too much work, then at the bare minimum you'll need to write/copy/hack a service script together and place it in a folder.

Useful resources:

The second of the links mentions looking at the init.d folder for more info on service scripts: this is an excellent idea. The JBoss or Tomcat service scripts bundled with the software should be similar to what you're trying to achieve.

shearn89
  • 3,143
  • 2
  • 14
  • 39