devbox icon indicating copy to clipboard operation
devbox copied to clipboard

Mariadb service not starting on macOS

Open JoyceBabu opened this issue 1 year ago • 3 comments

What happened?

mariadb service fails to start on macOS. The following command is not working

mysqld --log-error=$MYSQL_HOME/mysql.log & MYSQL_PID=$! && echo 'Starting mysqld... check mariadb_logs for details'

It works if I remove the & MYSQL_PID=$! assignment

Steps to reproduce

Command

services

devbox.json

{
  "packages": [
    "path:devbox.d/php#php",
    "path:devbox.d/php#php.packages.composer",
    "apacheHttpd@latest",
    "mariadb@latest",
    "nodejs-18_x@latest",
    "yarn@latest",
    "jq@latest",
    "redis@latest",
    "podman@4"
  ],
  "env": {
    "DEVBOX_COREPACK_ENABLED": "true",
    "DOCUMENT_ROOT": "$PWD/public_html",
    "HTTPD_PID_FILE": "$PWD/.devbox/virtenv/apacheHttpd/apache2.pid",
    "HTTPD_PORT": "8080",
    "HTTPD_SECURE_PORT": "8443",
    "HTTPD_SSLDIR": "$PWD/.devbox/virtenv/apacheHttpd/ssl",
    // Redis fails to starts without this
    "LANG": "",
    // "MYSQL_HOME": "$PWD/devbox.d/mysql",
    // "MYSQL_PID_FILE": "$PWD/.devbox/virtenv/mariadb/run/mysql.pid",
    // "MYSQL_UNIX_PORT": "$PWD/.devbox/virtenv/mariadb/run/mysql.sock",
    "PHP_CONFDIR": "$PWD/conf/php",
    "PHPFPM_ERROR_LOG_FILE": "$PWD/logs/php-fpm.log",
    "PHPFPM_PORT": "9001",
    "PROJECT_DIR": "$PWD"
  },
  "shell": {
    "init_hook": [
      // "source conf/set-env.sh"
    ]
  },
  "nixpkgs": {
    "commit": "f80ac848e3d6f0c12c52758c0f25c10c97ca3b62"
  },
  "include": [
    "plugin:php",
    "path:devbox.d/podman/plugin.json"
  ]
}

Devbox version

0.10.5

Nix version

nix (Nix) 2.22.0

What system does this bug occur on?

macOS (Intel)

Debug logs

No response

JoyceBabu avatar Apr 25 '24 14:04 JoyceBabu

Interestingly, the command works when directly executed in terminal.

Usually MYSQL_PID is immediately defined, when you need to wait on the process, or to call killall $MYSQL_PID after calling mysqlshutdown. Since devbox is using neither of them, is it required?

JoyceBabu avatar Apr 26 '24 17:04 JoyceBabu

Can you please look into this? @mikeland73 @savil @Lagoja

JoyceBabu avatar Jul 25 '24 13:07 JoyceBabu

The issue is with the background operator &. It works correctly if I change the mariadb process definition to

  mariadb:
    command: "echo 'Starting mysqld... check mariadb_logs for details' && mysqld --log-error=$MYSQL_HOME/mysql.log"
    shutdown:
      command: "mysqladmin -u root shutdown"
    availability:
      restart: "always"

process-compose process hangs on exiting, if is_daemon is true.

JoyceBabu avatar Jul 29 '24 16:07 JoyceBabu

Hi @JoyceBabu I'm having the same problem : mariadb won't start on MacOS :/ Did you find a workaround ?

chibani avatar Feb 06 '25 10:02 chibani

@chibani Just saw your message.

Hi @JoyceBabu I'm having the same problem : mariadb won't start on MacOS :/ Did you find a workaround ?

I fixed the process-compose.yaml by replacing the default plugin with a custom one.

// devbox.json
{
  "packages": {
    "php":                     "8.3",
    "apacheHttpd":             "latest",
    "mariadb": {
      "version":        "latest",
      "disable_plugin": true
    }
  },
...
  "include": [
    "path:devbox.d/mariadb/plugin.json"
  ]
}
// devbox.d/mariadb/plugin.json
{
  "name": "mariadb",
  "version": "0.0.4",
  "description": "",
  "env": {
    "MYSQL_BASEDIR": "{{ .DevboxProfileDefault }}",
    "MYSQL_HOME": "{{ .Virtenv }}/run",
    "MYSQL_DATADIR": "{{ .Virtenv }}/data",
    "MYSQL_UNIX_PORT": "{{ .Virtenv }}/run/mysql.sock",
    "MYSQL_PID_FILE": "{{ .Virtenv }}/run/mysql.pid"
  },
  "create_files": {
     // "{{ .Virtenv }}/run": "",
    "{{ .Virtenv }}/run/my.cnf": "my.cnf",
    "{{ .Virtenv }}/setup_db.sh": "setup_db.sh",
    "{{ .Virtenv }}/process-compose.yaml": "process-compose.yaml",
  },
  "packages": [
  ],
  "__remove_trigger_package": true,
  "shell": {
    "init_hook": [
      "bash {{ .Virtenv }}/setup_db.sh"
    ]
  }
}
// devbox.d/mariadb/process-compose.yaml
version: "0.5"

processes:
  mariadb:
    command: "echo 'Starting mariadbd... check mariadb_logs for details' && mariadbd-safe --datadir='$MYSQL_DATADIR' --pid-file='$MYSQL_PID_FILE' --socket='$MYSQL_UNIX_PORT' --log-error=$MYSQL_HOME/mysql.log"
    shutdown:
      command: "mariadb-admin -u root shutdown"
    availability:
      restart: "always"
  mariadb_logs:
    command: "tail -f $MYSQL_HOME/mysql.log"
    availability:
      restart: "always"

The above files might be outdated, since I haven't updated in a while. You can compare to the original version on GitHub to pull in any latest changes to the original files.

I also faced another issue on macOs where mariadbd-safe installed by nix is corrupted. To fix the script, I run the following after a fresh install. You need to install gnu-sed with brew install gnu-sed.

sudo gsed -e 's/    if $$/    if ps -ef | grep -v mysqld_safe | grep -- \$$MYSQLD | grep \$$PID > \/dev\/null/' -i .devbox/nix/profile/default/bin/mariadbd-safe

HTH

JoyceBabu avatar Feb 21 '25 10:02 JoyceBabu