Centos – Start a program with systemd

centosproftpdsystemd

I'm trying to install the latest version of ProFTPd (1.3.5) onto a CentOS 7 box, and wound up having to configure and install manually. The reason is that EPEL's version of proftpd doesn't include mod_sftp (although it does include mod_tls). This is the output of proftpd -l when EPEL's version is installed:

[root@blah /]# proftpd -l
Compiled-in modules:
  mod_core.c
  mod_xfer.c
  mod_rlimit.c
  mod_auth_unix.c
  mod_auth_file.c
  mod_auth.c
  mod_ls.c
  mod_log.c
  mod_site.c
  mod_delay.c
  mod_facts.c
  mod_dso.c
  mod_ident.c
  mod_readme.c
  mod_auth_pam.c
  mod_tls.c
  mod_memcache.c
  mod_cap.c
  mod_ctrls.c
  mod_lang.c

Using this guy's method where I think he was using CentOS 6, I configured proftpd with the following:

./configure --prefix=/usr --with-includes=/usr/local/ssl/include --with-libraries=/usr/local/ssl/lib --enable-openssl --with-modules=mod_sftp --enable-dso

And then I was able to run make and make install successfully.

The issue is that it doesn't look like it create any systemd scripts:

[root@localhost]# systemctl start proftpd.service
Failed to issue method call: Unit proftpd.service failed to load: No such file or directory.

However, the binary exists, and the system knows about it:

[root@localhost]# which proftpd
/sbin/proftpd

Additionally, there doesn't seem to be any init scripts for this in /etc/init.d nor in /usr/etc/init.d.

When I run the binary stand alone, it stars up just fine.

But I'd like to get some sort of working init or systemd script working for this, so that it'll start on boot (and I'll have an easier time of managing the service).

Any thoughts on how this is done?

[Disclaimer: I posted this same question on Stack Overflow a couple days ago, thinking this was a more programming-centric question, but that hasn't seen any activity, and I think that this is related enough to system administration that its relevant here too]

Best Answer

The systemd unit would look something like this:

$ cat /etc/systemd/system/proftpd.service

[Unit]
Description=ProFTPd FTP Server
After=syslog.target network.target

[Service]
Type=forking
ExecStart=/usr/sbin/proftpd
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target

Then you could do:

$ sudo systemctl enable /etc/systemd/system/proftpd.service
$ sudo systemctl start proftpd.service

man systemctl should get you on the right track.