Re: [Proftpd-user] How do you set environment variables?

Ryan Nation <[email protected]> Tue, 31 Jan 2023 17:18:10 +0000
Newsgroups gmane.network.proftpd.user
Message-ID <CH3PR19MB78740EEA0321522A37ECD8C4E4D09@CH3PR19MB7874.namprd19.prod.outlook.com>
I had previously tried editing the init.d script at /etc/init.d/proftpd. Whether that is the correct place, or I failed to use the correct syntax, it didn't work.

Per your suggestion I added a new file at  /etc/systemd/system/proftpd.service and placed the variables directly in the config (no external env file). I restarted the service using systemctl and proftpd still failed to inherit the environment variables properly. After a little more Googling I ended up editing /etc/default/proftpd and adding my variable there:

export PROFTPD_DB_PASSWORD=......

I restarted the service using systemctl again and this time it worked as expected.

Thanks for the help.

Ryan

________________________________
From: TJ Saunders <[email protected]>
Sent: Monday, January 30, 2023 9:52 AM
To: ProFTPD Users <[email protected]>
Subject: Re: [Proftpd-user] How do you set environment variables?

> The problem is when I run ProFTPD as a service. It doesn't pick up the
> environment variable and I ultimately get an error in my sql.log:
>
> message: 'Access denied for user 'proftpd'@'localhost' (using password: YES)'
>
> So where is the best place to set the environment variable and how do
> you pass it to the service? I'm managing the service using systemctl if
> that helps.

systemd is annoying, in that it breaks the traditional Unix behavior where new processes automatically inherit the environment variables of their parents, i.e. environment variables are *not passed* by system to the started applications.

Instead, systemd needs to be explicitly configured to provide environment variables, either directly or by reading a file that will then be used to provide environment variables for the application.  In the systemd unit file for ProFTPD, you'd need to add something like this:

  [Service]
  Environment=PROFTPD_DB_PASSWORD=...

Or:

  [Service]
  EnvironmentFile=-/etc/proftpd/env

And in that specified EnvironmentFile, you'd set your environment variables:

  PROFTPD_DB_PASSWORD=...

Note: If you're curious about the "-" prefix on that EnvironmentFile path, it tells systemd to ignore any errors reading that file, such as when that file is absent.

After you edit your ProFTPD systemd unit file, make sure you reload systemd, so that it sees these changes:

  $ sudo systemd daemon-reload

Hope this helps,
TJ


_______________________________________________
ProFTPD Users List   <[email protected]>
Unsubscribe problems?
http://www.proftpd.org/list-unsub.html

_______________________________________________
ProFTPD Users List   <[email protected]>
Unsubscribe problems?
http://www.proftpd.org/list-unsub.html