airflow systemd fails due to gunicorn - gunicorn

I am unable to start the airflow webserver using systemd even though it starts and functions properly outside of systemd like so:
export AIRFLOW_HOME=/path/to/my/airflow/home ; airflow webserver -p 8080
The systemd log leads me to believe that the issue comes from gunicorn, even though gunicorn starts without issue when I run the above command (i.e. it's only an issue in systemd). I have configured the following systemd files according to the airflow docs (running Ubuntu 16).
/etc/default/airflow
AIRFLOW_HOME=/path/to/my/airflow/home
SCHEDULER_RUNS=5
/lib/systemd/system/airflow-webserver.service
[Unit]
Description=Airflow webserver daemon
After=network.target
[Service]
EnvironmentFile=/etc/default/airflow
User=ubuntu
Group=ubuntu
Type=simple
ExecStart=/bin/bash -c "export AIRFLOW_HOME=/path/to/my/airflow/home ; airflow webserver -p 8080 "
Restart=on-failure
RestartSec=5s
PrivateTmp=true
[Install]
WantedBy=multi-user.target
/etc/tmpfiles.d/airflow.conf
D /run/airflow 0755 airflow airflow
This results in the following error when I start the service with systemctl.
systemctl start airflow-webserver.service
Jul 15 22:41:27 ip-172-31-19-64 systemd[1]: Started Airflow webserver daemon.
Jul 15 22:41:27 ip-172-31-19-64 bash[31494]: [2018-07-15 22:41:27,555] {driver.py:120} INFO - Generating grammar tables from /usr/lib/python3.5/lib2to3/Grammar.txt
Jul 15 22:41:27 ip-172-31-19-64 bash[31494]: [2018-07-15 22:41:27,592] {driver.py:120} INFO - Generating grammar tables from /usr/lib/python3.5/lib2to3/PatternGrammar.txt
Jul 15 22:41:27 ip-172-31-19-64 bash[31494]: [2018-07-15 22:41:27,729] {__init__.py:45} INFO - Using executor SequentialExecutor
Jul 15 22:41:28 ip-172-31-19-64 bash[31494]: ____________ _____________
Jul 15 22:41:28 ip-172-31-19-64 bash[31494]: ____ |__( )_________ __/__ /________ __
Jul 15 22:41:28 ip-172-31-19-64 bash[31494]: ____ /| |_ /__ ___/_ /_ __ /_ __ \_ | /| / /
Jul 15 22:41:28 ip-172-31-19-64 bash[31494]: ___ ___ | / _ / _ __/ _ / / /_/ /_ |/ |/ /
Jul 15 22:41:28 ip-172-31-19-64 bash[31494]: _/_/ |_/_/ /_/ /_/ /_/ \____/____/|__/
Jul 15 22:41:28 ip-172-31-19-64 bash[31494]:
Jul 15 22:41:28 ip-172-31-19-64 bash[31494]: [2018-07-15 22:41:28,042] {models.py:189} INFO - Filling up the DagBag from /path/to/my/airflow/home/dags
Jul 15 22:41:28 ip-172-31-19-64 bash[31494]: /home/ubuntu/.local/lib/python3.5/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.cache is deprecated, use flask_cach
Jul 15 22:41:28 ip-172-31-19-64 bash[31494]: .format(x=modname), ExtDeprecationWarning
Jul 15 22:41:28 ip-172-31-19-64 bash[31494]: Running the Gunicorn Server with:
Jul 15 22:41:28 ip-172-31-19-64 bash[31494]: Workers: 4 sync
Jul 15 22:41:28 ip-172-31-19-64 bash[31494]: Host: 0.0.0.0:8080
Jul 15 22:41:28 ip-172-31-19-64 bash[31494]: Timeout: 120
Jul 15 22:41:28 ip-172-31-19-64 bash[31494]: Logfiles: - -
Jul 15 22:41:28 ip-172-31-19-64 bash[31494]: =================================================================
Jul 15 22:41:28 ip-172-31-19-64 bash[31494]: Traceback (most recent call last):
Jul 15 22:41:28 ip-172-31-19-64 bash[31494]: File "/usr/local/bin/airflow", line 27, in <module>
Jul 15 22:41:28 ip-172-31-19-64 bash[31494]: args.func(args)
Jul 15 22:41:28 ip-172-31-19-64 bash[31494]: File "/usr/local/lib/python3.5/dist-packages/airflow/bin/cli.py", line 788, in webserver
Jul 15 22:41:28 ip-172-31-19-64 bash[31494]: gunicorn_master_proc = subprocess.Popen(run_args)
Jul 15 22:41:28 ip-172-31-19-64 bash[31494]: File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
Jul 15 22:41:28 ip-172-31-19-64 bash[31494]: restore_signals, start_new_session)
Jul 15 22:41:28 ip-172-31-19-64 bash[31494]: File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
Jul 15 22:41:28 ip-172-31-19-64 bash[31494]: raise child_exception_type(errno_num, err_msg)
Jul 15 22:41:28 ip-172-31-19-64 bash[31494]: FileNotFoundError: [Errno 2] No such file or directory: 'gunicorn'
Jul 15 22:41:28 ip-172-31-19-64 systemd[1]: airflow-webserver.service: Main process exited, code=exited, status=1/FAILURE
Is there some configuration I need to do to make gunicorn compatible with systemd?
Edit:
Following suggestions that this was a permission issue, I installed gunicorn via:sudo apt-get install gunicornand upon re-running the systemctl got the following error Error: No module named airflow.www.gunicorn_config. I figured that this was due to an inconsistency between the gunicorn that I had just installed and the gunicorn my ubuntu user was using to run airflow, so I replaced the gunicorn in /usr/bin/ with the former. This hotfix is likely not the best way to make the fix, but afterwards I was successfully able to run airflow via systemd.

I had the same problem on Ubuntu 18.04 LTS and Apache Airflow version 1.10.1 installed in a virtual environment under /srv/airflow. After lots of trial and errors I ended up with this working solution.
My airflow-webserver.service file:
[Unit]
Description=Airflow webserver daemon
After=network.target
[Service]
Environment="PATH=/srv/airflow/bin"
Environment="AIRFLOW_HOME=/srv/airflow"
User=airflow
Group=airflow
Type=simple
ExecStart=/srv/airflow/bin/airflow webserver --pid /srv/airflow/webserver.pid
Restart=on-failure
RestartSec=5s
PrivateTmp=true
[Install]
WantedBy=multi-user.target
I did this to install the service:
sudo cp airflow-webserver.service /lib/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable airflow-webserver.service
sudo systemctl start airflow-webserver.service

Yeah, ExecStart=..airflow/bin/airflow requires ..airflow/bin/python but systemd found system python instead. Airflow needs Environment="PATH=..airflow/bin", always.

In Ubuntu Bionic, I found that sudo apt-get install python3-gunicorn first and then sudo apt-get install gunicorn while in the root python environment resolves this problem.

Related

apt upgrade mysqlserver freezes and will not upgrade (ubuntu server 20.04)

I had to kill the session and then the databases are inaccessible until I reboot the server.
When I log back in and issue ‘apt upgrade’ i get the following error.
E: dpkg was interrupted, you must manually run 'dpkg --configure -a' to correct the problem.
I run ‘dpkg --configure -a’ and get the following and then it just freezes
Setting up mysql-server-8.0 (8.0.22-0ubuntu0.20.04.3) ...
mysqld will log errors to /var/log/mysql/error.log
mysqld is running as pid 86150
On another tty
journalctl -xe gives this when the upgrade freezes.
-- The unit mysql.service has successfully entered the 'dead' state.
Jan 13 22:18:12 arpradio systemd[1]: Stopped MySQL Community Server.
-- Subject: A stop job for unit mysql.service has finished
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- A stop job for unit mysql.service has finished.
--
-- The job identifier is 582 and the job result is done.
Jan 13 22:18:13 arpradio audit[6057]: AVC apparmor="STATUS" operation="profile_replace" info="same as current profile, skipping" profile="unconfined" name="/usr/sbin/mysqld" pid>
Jan 13 22:18:13 arpradio kernel: audit: type=1400 audit(1610572693.036:16): apparmor="STATUS" operation="profile_replace" info="same as current profile, skipping" profile="uncon>
When I reboot and login mysqld is running
I have tried the following.
# cp -r /etc/mysql /etc/mysql_old
# apt autoremove
E: dpkg was interrupted, you must manually run 'dpkg --configure -a' to correct the problem.
# dpkg --configure -a
Setting up mysql-server-8.0 (8.0.22-0ubuntu0.20.04.3) ...
mysqld will log errors to /var/log/mysql/error.log
mysqld is running as pid 7451
And we are back here with the freeze.
If I check the mysql processes I find no process 7451 but this is the output.
# ps aux | grep mysql
root 1679 0.0 0.0 8644 4688 ? Ssl 22:23 0:00 dockerize -template /tmp/db.cnf.tmpl:/etc/mysql/conf.d/db.cnf /usr/local/bin/docker-entrypoint.sh mysqld
systemd+ 2526 0.3 0.1 2446780 99836 ? Sl 22:23 0:03 mysqld
root 7370 0.3 0.0 27940 19836 pts/0 S+ 22:38 0:00 /usr/bin/perl -w /usr/share/debconf/frontend /var/lib/dpkg/info/mysql-server-8.0.postinst configure 8.0.22-0ubuntu0.20.04.2
root 7379 0.0 0.0 9756 3772 pts/0 S+ 22:38 0:00 /bin/bash /var/lib/dpkg/info/mysql-server-8.0.postinst configure 8.0.22-0ubuntu0.20.04.2
mysql 7657 1.9 0.5 1869164 358336 pts/0 Sl+ 22:39 0:01 mysqld --user=mysql --init-file=/var/lib/mysql-files/tmp.gQukBE7GtT --socket=/tmp/tmp.KUFQmDDseF/mysqld.sock --pid-file=/tmp/tmp.KUFQmDDseF/mysqld.pid
root 7759 0.0 0.0 9032 724 pts/1 S+ 22:39 0:00 grep --color=auto mysql
I checked the status of mysql.service
# systemctl status mysql.service
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Wed 2021-01-13 22:38:59 CET; 17min ago
Process: 649 ExecStart=/usr/sbin/mysqld (code=exited, status=0/SUCCESS)
Main PID: 649 (code=exited, status=0/SUCCESS)
Status: "Server shutdown complete"
Jan 13 22:21:43 arpradio systemd[1]: Starting MySQL Community Server...
Jan 13 22:21:45 arpradio systemd[1]: Started MySQL Community Server.
Jan 13 22:38:57 arpradio systemd[1]: Stopping MySQL Community Server...
Jan 13 22:38:59 arpradio systemd[1]: mysql.service: Succeeded.
Jan 13 22:38:59 arpradio systemd[1]: Stopped MySQL Community Server.
I fixed it, what I did was while the upgrade was hanging I ran
apt update && apt upgrade
on another tty and it upgraded everything, rebooted, I checked again after reboot and everything looks good.
# apt update
Hit:1 http://asi-fs-n.contabo.net/ubuntu focal InRelease
Hit:2 http://asi-fs-n.contabo.net/ubuntu focal-updates InRelease
Hit:3 http://archive.ubuntu.com/ubuntu focal InRelease
Hit:4 https://download.docker.com/linux/ubuntu focal InRelease
Hit:5 http://asi-fs-n.contabo.net/ubuntu focal-backports InRelease
Get:6 http://security.ubuntu.com/ubuntu focal-security InRelease [109 kB]
Fetched 109 kB in 1s (112 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.
root#arpradio:~# apt upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
root#arpradio:~# ps aux | grep mysql
mysql 657 1.2 0.6 2067208 378684 ? Ssl 23:09 0:02 /usr/sbin/mysqld
root 2148 0.1 0.0 9796 4784 ? Ssl 23:11 0:00 dockerize -template /tmp/db.cnf.tmpl:/etc/mysql/conf.d/db.cnf /usr/local/bin/docker-entrypoint.sh mysqld
systemd+ 2930 0.8 0.1 2380944 99508 ? Sl 23:11 0:00 mysqld
root 5507 0.0 0.0 9032 732 pts/0 S+ 23:12 0:00 grep --color=auto mysql
root#arpradio:~# systemctl status mysql.service
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2021-01-13 23:09:06 CET; 3min 26s ago
Process: 560 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 657 (mysqld)
Status: "Server is operational"
Tasks: 38 (limit: 72284)
Memory: 419.9M
CGroup: /system.slice/mysql.service
└─657 /usr/sbin/mysqld
Jan 13 23:09:04 arpradio systemd[1]: Starting MySQL Community Server...
Jan 13 23:09:06 arpradio systemd[1]: Started MySQL Community Server.

/usr/sbin/mysql code=exited status 203/EXEC ERROR

I don't know exactly what I did wrong, but it's likely some 'chown' operation that I did. I was trying to allow the user&group mysql:mysql access to a /media/usb drive, but may have inadvertently changed something else.
When I do sudo systemctl start mysql.service I get an error. Upon examining with sudo systemctl status mysqld, I get the following:
mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: activating (start-post) (Result: exit-code) since Fri 2020-06-19 08:11:01 EDT; 19s ago
Process: 15459 ExecStart=/usr/sbin/mysqld (code=exited, status=203/EXEC)
Process: 15444 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 15459 (code=exited, status=203/EXEC); : 15460 (mysql-systemd-s)
Tasks: 2
Memory: 2.4M
CPU: 175ms
CGroup: /system.slice/mysql.service
└─control
├─15460 /bin/bash /usr/share/mysql/mysql-systemd-start post
└─15687 sleep 1
Jun 19 08:11:01 apil-dlrig systemd[1]: Starting MySQL Community Server...
Jun 19 08:11:01 apil-dlrig systemd[1]: mysql.service: Main process exited, code=exited, status=203/EXEC
When I check ownership on /var/lib/mysql, I get the following, which seems reasonable. I.e. user mysql has full ownership on this folder.
apil#apil-dlrig:~$ sudo ls -la /var/lib/mysql
total 176212
drwx------ 7 mysql mysql 4096 Jun 19 07:34 .
drwxr-xr-x 79 root root 4096 Oct 30 2019 ..
-rw-r----- 1 mysql mysql 56 Oct 20 2019 auto.cnf
-rw------- 1 mysql mysql 1680 Nov 22 2019 ca-key.pem
-rw-r--r-- 1 mysql mysql 1112 Nov 22 2019 ca.pem
-rw-r--r-- 1 mysql mysql 1112 Nov 22 2019 client-cert.pem
-rw------- 1 mysql mysql 1676 Nov 22 2019 client-key.pem
-rw-r--r-- 1 mysql mysql 0 May 5 06:38 debian-5.7.flag
drwxr-x--- 2 mysql mysql 4096 Jun 6 13:44 foo
-rw-r----- 1 mysql mysql 665 Jun 19 07:34 ib_buffer_pool
-rw-r----- 1 mysql mysql 79691776 Jun 19 07:34 ibdata1
-rw-r----- 1 mysql mysql 50331648 Jun 19 07:34 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 Oct 20 2019 ib_logfile1
-rw-r----- 1 mysql mysql 155 Jun 16 07:23 keyring_backup
drwxr-x--- 2 mysql mysql 4096 May 5 06:38 mysql
-rw-r--r-- 1 mysql mysql 6 May 5 06:38 mysql_upgrade_info
drwxr-x--- 2 mysql mysql 4096 May 5 06:38 performance_schema
-rw------- 1 mysql mysql 1680 Nov 22 2019 private_key.pem
drwxr-x--- 2 mysql mysql 4096 Jun 16 07:25 prod
-rw-r--r-- 1 mysql mysql 452 Nov 22 2019 public_key.pem
-rw-r--r-- 1 mysql mysql 1112 Nov 22 2019 server-cert.pem
-rw------- 1 mysql mysql 1680 Nov 22 2019 server-key.pem
drwxr-x--- 2 mysql mysql 12288 Nov 22 2019 sys
The /etc/systemd/system/multi.user.wants.targets/mysql.service looks as the following. Nothing should've changed here, i.e. it is as default as MySQL comes.
# MySQL systemd service file
[Unit]
Description=MySQL Community Server
After=network.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
PermissionsStartOnly=true
ExecStartPre=/usr/share/mysql/mysql-systemd-start pre
ExecStart=/usr/sbin/mysqld
ExecStartPost=/usr/share/mysql/mysql-systemd-start post
TimeoutSec=600
Restart=on-failure
RuntimeDirectory=mysqld
RuntimeDirectoryMode=755
Wondering what could be going wrong. Any help would be appreciated.
Thanks
If you look at the original error, the issue is: ExecStart=/usr/sbin/mysqld (code=exited, status=203/EXEC). Looks like some kind of execution privilege for the mysqld file? Checked it too:
ls -la /usr/sbin/mysqld which returned
-rw-r--r-- 1 root root 24585896 Apr 30 10:52 /usr/sbin/mysqld
So the issue (I thought) was that user root didn't have the execute permission. Looks at the first three letters rw-. The last dash means no execution privilege.
So I simply ran the following chmod 777 /usr/sbin/mysqld, after which the ownership returns as
-rwxrwxrwx 1 root root 24585896 Apr 30 10:52 /usr/sbin/mysqld
Now, systemctl start mysql.service runs just fine.
It's amazing how simply the process of writing a question on stackoverflow actually helps me solve a problem 80% of the time. Thanks again, folks.

Unable to Run Odoo Service at Ubuntu 16.04

I am new to ubuntu but with the help of this tutorial , i am trying to run Odoo 11 from its source code .While i tried to run this command
sudo systemctl start odoo.service
And after that while i tried to check status of my service using command
sudo systemctl status odoo.service
then its replies in the Console
odoo.service - Odoo Open Source ERP and CRM
Loaded: loaded (/lib/systemd/system/odoo.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Thu 2018-03-29 15:28:38 PKT; 7s ago
Process: 4072 ExecStart=/opt/odoo/odoo-bin --config=/etc/odoo-server.conf --addons-path=/opt/odoo/addons/ (code=exited, status=1/FAILURE)
Main PID: 4072 (code=exited, status=1/FAILURE)
Mar 29 15:28:38 hassan-Latitude-E6420 odoo-server[4072]: File "/opt/odoo/odoo/modules/graph.py", line 10, in <module>
Mar 29 15:28:38 hassan-Latitude-E6420 odoo-server[4072]: import odoo.tools as tools
Mar 29 15:28:38 hassan-Latitude-E6420 odoo-server[4072]: File "/opt/odoo/odoo/tools/__init__.py", line 7, in <module>
Mar 29 15:28:38 hassan-Latitude-E6420 odoo-server[4072]: from . import pdf
Mar 29 15:28:38 hassan-Latitude-E6420 odoo-server[4072]: File "/opt/odoo/odoo/tools/pdf.py", line 4, in <module>
Mar 29 15:28:38 hassan-Latitude-E6420 odoo-server[4072]: from PyPDF2 import PdfFileWriter, PdfFileReader
Mar 29 15:28:38 hassan-Latitude-E6420 odoo-server[4072]: ImportError: No module named 'PyPDF2'
Mar 29 15:28:38 hassan-Latitude-E6420 systemd[1]: odoo.service: Main process exited, code=exited, status=1/FAILURE
Mar 29 15:28:38 hassan-Latitude-E6420 systemd[1]: odoo.service: Unit entered failed state.
Mar 29 15:28:38 hassan-Latitude-E6420 systemd[1]: odoo.service: Failed with result 'exit-code'.
But i had installed PyPDF2 Module already.
There was no issue with my service . I haven't installed Python module using pip3 package manager.So that's why python base modules wasn't available. So i simply install pip3 using command
pip install python3-pip
And then again started my odoo service using command
sudo systemctl start odoo
Finally it started working like charm.

what is proper mysql database connection string

i am using following connection string :
mysql://root:root#newserver/metro
where
username: root
password: root
server : newserver
database: metro
getting following error :
2017/08/19 06:10:02 default addr for network 'newserver' unknown
here are mysql server logs :
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Community Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2017-08-18 17:14:59 UTC; 12h ago
Process: 23510 ExecStartPost=/usr/bin/mysql-systemd-start post (code=exited, status=0/SUCCESS)
Process: 23447 ExecStartPre=/usr/bin/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 23509 (mysqld_safe)
CGroup: /system.slice/mysqld.service
├─23509 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
└─23676 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mysqld.log --pid-file=/var/run/...
Aug 18 17:14:58 newserver mysql-systemd-start[23447]: Support MySQL by buying support/licenses at http://shop.mysql.com
Aug 18 17:14:58 newserver mysql-systemd-start[23447]: Note: new default config file not created.
Aug 18 17:14:58 newserver mysql-systemd-start[23447]: Please make sure your config file is current
Aug 18 17:14:58 newserver mysql-systemd-start[23447]: WARNING: Default config file /etc/my.cnf exists on the system
Aug 18 17:14:58 newserver mysql-systemd-start[23447]: This file will be read by default by the MySQL server
Aug 18 17:14:58 newserver mysql-systemd-start[23447]: If you do not want to use this, either remove it, or use the
Aug 18 17:14:58 newserver mysql-systemd-start[23447]: --defaults-file argument to mysqld_safe when starting the server
Aug 18 17:14:58 newserver mysqld_safe[23509]: 170818 17:14:58 mysqld_safe Logging to '/var/log/mysqld.log'.
Aug 18 17:14:58 newserver mysqld_safe[23509]: 170818 17:14:58 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Aug 18 17:14:59 newserver systemd[1]: Started MySQL Community Server.
following are the contents of /etc/hosts
172.31.43.60 newserver
this configuration is there on single machine and i am trying to access using golang program.
here is the url for the same :
https://github.com/utronframework/tutorials/blob/master/create_todo_list_application_with_utron.md
the filename is config/app.json
here is my app.json file
{
"app_name": "utron web app",
"base_url": "http://localhost:8090",
"port": 8090,
"verbose": false,
"static_dir": "static",
"view_dir": "views",
"database": "mysql",
"database_conn": "mysql://root:root#newserver/metro",
"automigrate": true
}
please suggest
I have no clue about Go, but I can read the documentation, which suggests that you need to use this:
root:root#tcp(newserver)/metro
Or possibly:
mysql://root:root#tcp(newserver)/metro

Docker Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) Ubuntu

I was playing with docker and mounted my local mysql to a docker container and connected MySql-Workbench so I could view the DB (experimenting) here is the command I ran.
docker run -d --name alldb-mysql -v /var/lib/mysql:/var/lib/mysql -e MYSQL_USER=root -e MYSQL_PASSWORD=password -p 3306:3306 mysql:latest
after I stopped my container and removed it, I can't start/restart mysql (local install). when I run sudo /etc/init.d/mysql start it returns
[....] Starting mysql (via systemctl): mysql.serviceJob for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.
failed!
so I checked systemctl status mysql.service
mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: activating (start-post) (Result: exit-code) since Mon 2017-04-03 22:26:15 IST; 26s ago
Process: 5470 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE)
Process: 5465 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 5470 (code=exited, status=1/FAILURE); : 5471 (mysql-systemd-s)
Tasks: 2
Memory: 1.6M
CPU: 222ms
CGroup: /system.slice/mysql.service
└─control
├─5471 /bin/bash /usr/share/mysql/mysql-systemd-start post
└─6579 sleep 1
Apr 03 22:26:15 n mysqld[5470]: 2017-04-03T21:26:15.980564Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explici
Apr 03 22:26:15 n mysqld[5470]: 2017-04-03T21:26:15.980614Z 0 [Warning] Can't create test file /var/lib/mysql/n.lower-test
Apr 03 22:26:15 n mysqld[5470]: 2017-04-03T21:26:15.980638Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.17-0ubuntu0.16.04.1) starting as process 5470 .
Apr 03 22:26:15 n mysqld[5470]: 2017-04-03T21:26:15.981928Z 0 [Warning] Can't create test file /var/lib/mysql/n.lower-test
Apr 03 22:26:15 n mysqld[5470]: 2017-04-03T21:26:15.981936Z 0 [Warning] Can't create test file /var/lib/mysql/n.lower-test
Apr 03 22:26:15 n mysqld[5470]: 2017-04-03T21:26:15.982122Z 0 [ERROR] failed to set datadir to /var/lib/mysql/
Apr 03 22:26:15 n mysqld[5470]: 2017-04-03T21:26:15.982142Z 0 [ERROR] Aborting
Apr 03 22:26:15 n mysqld[5470]: 2017-04-03T21:26:15.982162Z 0 [Note] Binlog end
Apr 03 22:26:15 n mysqld[5470]: 2017-04-03T21:26:15.982213Z 0 [Note] /usr/sbin/mysqld: Shutdown complete
Apr 03 22:26:15 n systemd[1]:
I also tried to login mysql with my detail:
mysql -uroot -ppassword1 which returned
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
when I run the following command ls -la /var/lib/ | grep mysql on the var lib directory it returns.
drwx------ 12 root docker 4096 Apr 3 21:17 mysql
drwx------ 2 mysql mysql 4096 Feb 23 22:35 mysql-files
drwx------ 2 mysql mysql 4096 Feb 23 22:35 mysql-keyring
drwxr-xr-x 2 root root 4096 Jan 18 21:45 mysql-upgrade
By the looks of things I (well docker did) messed up my ownership on my mysql directory.
If I run ls -la /var/lib/mysql it returns
ls: cannot open directory '/var/lib/mysql': Permission denied
and running same command with sudo sudo ls -la /var/lib/mysql
it returns
total 188480
drwx------ 12 root docker 4096 Apr 3 21:17 .
drwxr-xr-x 80 root root 4096 Mar 29 19:28 ..
-rw-r----- 1 guest-okauxv docker 56 Feb 23 22:35 auto.cnf
drwxr-x--- 2 guest-okauxv docker 4096 Mar 24 23:51 concretepage
-rw-r--r-- 1 guest-okauxv docker 0 Feb 23 22:35 debian-5.7.flag
drwxr-x--- 2 guest-okauxv docker 4096 Mar 25 00:10 myfidser
drwxr-x--- 2 guest-okauxv docker 4096 Mar 4 00:54 myotherFliDB
drwxr-x--- 2 guest-okauxv docker 4096 Mar 1 12:33 testFFAPI
-rw-r----- 1 guest-okauxv docker 679 Apr 3 21:16 ib_buffer_pool
-rw-r----- 1 guest-okauxv docker 79691776 Apr 3 21:17 ibdata1
-rw-r----- 1 guest-okauxv docker 50331648 Apr 3 21:17 ib_logfile0
-rw-r----- 1 guest-okauxv docker 50331648 Feb 23 22:35 ib_logfile1
-rw-r----- 1 guest-okauxv docker 12582912 Apr 3 21:17 ibtmp1
drwxr-x--- 2 guest-okauxv docker 4096 Feb 23 22:35 mysql
drwxr-x--- 2 guest-okauxv docker 4096 Mar 25 16:58 NodeRestDB
drwxr-x--- 2 guest-okauxv docker 4096 Feb 23 22:35 performance_schema
drwxr-x--- 2 guest-okauxv docker 12288 Feb 23 22:35 sys
drwxr-x--- 2 guest-okauxv docker 4096 Mar 29 10:34 testDB
drwxr-x--- 2 guest-okauxv docker 4096 Mar 1 11:52 demoDB
By the looks of this, I (well docker did) managed to changed the owner and group of all the directories in mysql directory.
Do I need to do a complete reinstall of MySQL Server?
What is the simplest, easiest way to fix this?
your help will be much appreciated.
Updated with FIX
Just what Andy Shinn said in point one, I just ran sudo chown -R
mysql:mysql /var/lib/mysql to change the owner back and started mysql
by running sudo /etc/init.d/mysql start and mysql returned
[ ok ]Starting mysql (via systemctl): mysql.service.
G
Some more information will be needed. But two things come to mind.
It is likely the permission issue. Based on your output, why don't you first just try changing the owner and group back to mysql? This should be a simple sudo chown -R mysql:mysql /var/lib/mysql.
It is possible that running mysql:latest image is a different version of MySQL that you were running locally and it could have upgraded the MySQL data to newer formats which may be incompatible with older versions. Check that the version of MySQL you were running locally is the same that the mysql:latest image tag points to (at least the same minor version eg. 5.6 and 5.6).
What version is mysql:latest and what version were you running locally? Do you have any log output from the MySQL container that you started?