Skip to main content
Version: 2.0.11

How to Restart a Service Automatically with a Cron Job

Sometimes you want a service restarted on a schedule - for example PHP-FPM every night, or a Node.js app that slowly leaks memory. In OpenPanel you can do this with a regular cron job, no terminal access needed.


How It Works​

Every service in your OpenPanel account (web server, PHP, MySQL, Redis, your apps, ...) runs in its own container with a restart policy. When the container's main process stops, the container is started again automatically.

The main process of a container always has the process ID 1. So to restart a service, a cron job only needs to stop PID 1 inside that container:

kill 1

The service shuts down and comes straight back up a moment later.


Create the Cron Job​

  1. Go to OpenPanel → Cron Jobs and click Create New.
  2. Container: select the service you want to restart, e.g. php-fpm-8.3, nginx, mysql or your app's container.
  3. Schedule: choose when it should run, e.g. Daily, or a cron expression like 0 0 4 * * * for every day at 04:00 (OpenPanel cron schedules have 6 fields - the first one is seconds).
  4. Command:
kill 1
  1. Save.

Create Cron Job form with the container, schedule, common schedules, command and comment fields Create Cron Job form with the container, schedule, common schedules, command and comment fields

Use the Run button next to the job to test it right away - the service should restart within a few seconds.

See Cron Jobs for all options.


kill 1 or kill -9 1?​

CommandWhat it doesWhen to use
kill 1Asks the service to shut down cleanly (SIGTERM)Default - lets databases and apps finish what they're doing
kill -9 1Stops the process immediately (SIGKILL)Only if the service is stuck and ignores kill 1

Prefer kill 1, especially for MySQL/MariaDB and PostgreSQL - a forced stop can interrupt writes.


Tips​

  • Schedule restarts at a quiet time, such as early morning - visitors get an error for the few seconds the service is down.
  • Restarting a web server or PHP container briefly takes all sites that use it offline, not just one site.
  • A service you stopped manually from the Services page stays stopped - the restart policy only brings back services that stopped on their own.
  • If a service needs regular restarts because it runs out of memory, consider raising its limits instead - see Services.