Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add logrotate script and update log location #1963

Merged
merged 1 commit into from
Mar 20, 2019
Merged

feat: Add logrotate script and update log location #1963

merged 1 commit into from
Mar 20, 2019

Conversation

alexjurkiewicz
Copy link
Contributor

@alexjurkiewicz alexjurkiewicz commented Mar 20, 2019

Write to /var/log/proxysql.log by default, and add a logrotate script
which manages this path.

Unfortunately, the logrotate script can't use PROXYSQL FLUSH LOGS; to
tell ProxySQL to rotate file handles*, so we use copytruncate instead.
It would be nice if ProxySQL could rotate file handles following a
signal in future...

* For two reasons:

  1. There's no safe / standard way to find admin credentials
  2. mysql(1) client may not be installed

Write to /var/log/proxysql.log by default, and add a logrotate script
which manages this path.

Unfortunately, the logrotate script can't use `PROXYSQL FLUSH LOGS;` to
tell ProxySQL to rotate file handles*, so we use copytruncate instead.
It would be nice if ProxySQL could rotate file handles following a
signal in future...

* For two reasons:
1. There's no safe / standard way to find admin credentials
2. mysql(1) client may not be installed
@pondix
Copy link
Contributor

pondix commented Mar 20, 2019

Automated message: PR pending admin approval for build testing

@renecannao
Copy link
Contributor

I like it, thanks!
Assigning to @pondix that normally takes care of packaging.

@pondix pondix merged commit ee219f4 into sysown:v2.0.3 Mar 20, 2019
@BhuviTheDataGuy
Copy link

BhuviTheDataGuy commented Mar 28, 2019

I have installed Proxysql 2.0.3 on Ubuntu 18.04. But after installation, the log file was not generated.
I checked at /var/lib/proxysql/(previous version location) and /var/log.

But Im not able to find the log file. Tried to manually created with chown proxysql:proxysql /var/log/proxysql.log , but thats not working.

Workaroud: (Im using the old log file location)

vi /etc/proxysql.cnf
errorlog="/var/lib/proxysql/proxysql.log"

Save
Edit log rotate file:

vi /etc/logrotate.d/proxysql/proxysql
/var/lib/proxysql/proxysql.log {
    compress
    daily
    rotate 10
    missingok
    notifempty
    copytruncate
}

restart proxysql

@alexjurkiewicz
Copy link
Contributor Author

alexjurkiewicz commented Mar 28, 2019 via email

@BhuviTheDataGuy
Copy link

Manually added the log file location as /var/lib/proxysql/proxysql.log

Then

lsof -u proxysql | grep log
(sd-pam 5773 proxysql mem REG 8,1 14432 2073 /lib/x86_64-linux-gnu/security/pam_loginuid.so
proxysql 5799 proxysql 1w REG 8,1 4554 258360 /var/lib/proxysql/proxysql.log
proxysql 5799 proxysql 2w REG 8,1 4554 258360 /var/lib/proxysql/proxysql.log

Default config (/var/log/proxysql.log)

root@proxysql-01:/home/pankaj_kumar# service proxysql restart
root@proxysql-01:/home/pankaj_kumar# lsof -u proxysql | grep log
(sd-pam 6547 proxysql mem REG 8,1 14432 2073 /lib/x86_64-linux-gnu/security/pam_loginuid.so
root@proxysql-01:/home/pankaj_kumar#

@alexjurkiewicz
Copy link
Contributor Author

I understand the issue(s):

  • Log file is not pre-created, and proxysql has no permission to create it
  • Logrotate is deployed to incorrect directory (/etc/logrotate.d/proxysql/proxysql.conf)

I'm not sure why it failed once you created the log file by hand. I performed the same test and things worked.

I'm testing a fix locally now...

@BhuviTheDataGuy
Copy link

Hey @alexjurkiewicz

Thanks for your effort. I tried to reproduce one more time on a fresh VM.
OS Version:

cat /etc/*-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.10
DISTRIB_CODENAME=cosmic
DISTRIB_DESCRIPTION="Ubuntu 18.10"
NAME="Ubuntu"
VERSION="18.10 (Cosmic Cuttlefish)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.10"
VERSION_ID="18.10"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=cosmic
UBUNTU_CODENAME=cosmic

Below are the steps I have done.

apt-get update
apt-get upgrade
wget https://github.com/sysown/proxysql/releases/download/v2.0.3/proxysql_2.0.3-ubuntu18_amd64.deb
dpkg -i proxysql_2.0.3-ubuntu18_amd64.deb 
wget https://dev.mysql.com/get/mysql-apt-config_0.8.12-1_all.deb
dpkg -i mysql-apt-config_0.8.12-1_all.deb 
apt-get update
apt-get install mysql-client
service proxysql start

But Im not able to find the log file. Then manually creating the log file.

service proxysql stop
touch proxysql.log
chown proxysql:proxysql proxysql.log 
usermod -a -G syslog proxysql
service proxysql start

But still the log file is empty.

@alexjurkiewicz
Copy link
Contributor Author

I've pushed a branch fix-logs-deb to my fork which should fix the issue.
Unfortunately I'm getting a build error which doesn't seem related and I'll
be away this weekend, so haven't been able to completely test it:

Build error log snippet from make ubuntu18 MAKE=make

ubuntu18_build_1       | [ 99%] Built target view
ubuntu18_build_1       | [100%] Linking C executable result
ubuntu18_build_1       | make[4]: Leaving directory
'/opt/proxysql/deps/mariadb-client-library/mariadb-connector-c-3.0.2-src'
ubuntu18_build_1       | [100%] Built target result
ubuntu18_build_1       | make[3]: Leaving directory
'/opt/proxysql/deps/mariadb-client-library/mariadb-connector-c-3.0.2-src'
ubuntu18_build_1       | make[2]: Leaving directory
'/opt/proxysql/deps/mariadb-client-library/mariadb-connector-c-3.0.2-src'
ubuntu18_build_1       | make[1]: Leaving directory '/opt/proxysql/deps'
ubuntu18_build_1       | make: *** empty string invalid as file name.  Stop.
proxysql_ubuntu18_build_1 exited with code 2

@BhuviTheDataGuy
Copy link

BhuviTheDataGuy commented Mar 29, 2019

One more update:

Same issue found on CentOs7. But we can run this to fix it.

Fix:

touch /var/log/proxysql.log
chown proxysql:proxysql proxysql.log 
service proxysql restart

@pondix
Copy link
Contributor

pondix commented Apr 1, 2019

@BhuviTheDataGuy / @alexjurkiewicz

We've discussed internally and decided to move the default path back to /var/lib/proxysql/proxysql.log in the default config file. Feel free to customise as you wish in your local installations making sure that "proxysql" has suitable permissions to write to the file (as @BhuviTheDataGuy pointed out).

I've also added some additional fixes for the logrotate location in this PR: #1991

@BhuviTheDataGuy
Copy link

Hey @pondix

Thanks for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants