0

I would like to know the proper way to setup the MySQL service in such a way that during reboot or shutdown, the system does not force it to close.

As it currently stands (default?), the system gives MySQL about 38 minutes to shutdown during a reboot or shutdown, and then forcibly exits the MySQL daemon process.

I'd like to configure Ubuntu's systemd/init in such a way that it knows that MySQL service (mysqld.service) can take a long time (forever) to shutdown, and that it will allow it.

I realize that I can execute a command prior to a shutdown such as setting the INNODB percentage to 0, which effectively forces MySQL to flush out memory prior to reboot. But I'd like a reboot or shutdown to allow MySQL to write out all 2TB of data prior to shutdown if needed.

0

1 Answer 1

2

A possible solution to your problem was adressed in the following Ubuntu/Linux post How to change systemd service timeout value?:

A small excerpt of the answer is posted below for your convenience. Please read the full answer over on Unix/Linux site.

  1. Edit your systemd file:

    • For modern versions of systemd: Run systemctl edit --full node.service (replace "node" with your service name).
      • This will create a system file at /etc/systemd/system/node.service.d/ that will override the system file at /usr/lib/systemd/system/node.service. This is the proper way to configure your system files. More information about how to use systemctl edit is here.
    • Directly editing system file: The system file for me is at /usr/lib/systemd/system/node.service. Replace "node" with your application name. However, it is not safe to directly edit files in /usr/lib/systemd/ (See comments)
  2. Use TimeoutStartSec, TimeoutStopSec or TimeoutSec (more info [here][2]) to specify how long the timeout should be for starting & stopping the process. Afterwards, this is how my systemd file looked:

    [Unit]
    Description=MyProject
    Documentation=man:node(1)
    After=rc-local.service
    
    [Service]
    WorkingDirectory=/home/myproject/GUIServer/Server/
    Environment="NODE_PATH=/usr/lib/node_modules"
    ExecStart=-/usr/bin/node Index.js
    Type=simple
    Restart=always
    KillMode=process
    TimeoutSec=900
    
    [Install]
    WantedBy=multi-user.target
    
    • You can also view the current Timeout status by running any of these (but you'll need to edit your service to make changes! See step 1). Confusingly, the associated properties have a "U" in their name for microseconds. See this Github issue for more information: - systemctl show node.service -p TimeoutStartUSec - systemctl show node.service -p TimeoutStopUSec - systemctl show node.service -p TimeoutUSec
  3. Next you'll need to reload the systemd with systemctl reload node.service
    ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.