Understanding “Fake Run As”

Cron and Supervisor are tools that allow you to schedule and manage tasks on your server. However, due to the technical limitation of containerized architecture, they cannot execute php, composer, and wp commands as a specific user. These commands need to run docker exec -it <container_id> /bin/php, which requires root privileges.

To overcome this limitation, we provide a feature called “Fake Run As“. This feature simulates running the commands as the user you specify, while actually running them as root. This way, you can execute php, composer, and wp commands using Cron and Supervisor.

However, you should be careful not to use “Fake Run As” for other commands that are not php, composer, or wp. This is because running them as root could cause unwanted or dangerous effects on your server.

For example, suppose you have a file /tmp/script.sh with the following content:

rm -rf /

This command deletes all the files on your server! If you run this file using Cron or Supervisor as a normal user, it would only delete the files that belong to that user. But if you use “Fake Run As“, it would run the file as root – and delete the whole server. Therefore, you should avoid using “Fake Run As” for such commands.

Creating a Cron Job

To create a cron job on the RunCloud dashboard, follow these steps:

  1. Gather the details for creating your cron job. If you are creating a cron job for WordPress, note down the system user, PHP version, and the public path of your application.
WordPress application overview RunCloud
  1. After this, navigate to the Cron Jobs menu. You can find this in the sidebar when you open the Server Settings. On this page, you can see all your existing cron jobs. Click on “Add New Job” to create a new job.
List cron jobs in RunCloud docker
  1. On the next screen, enter a label for the cron job in the Job Label field. This is a name that helps you identify the job.
  2. Enter the name of the system user that we noted down in step 1. This is the system user that executes the command.
  3. If your command uses php, composer, or wp; check the “Fake Running User” option. This option allows the user to run the command as root, which is required for these commands.
  4. Select a vendor binary from the Vendor Binary dropdown menu. This is the path to the executable file that runs the command. If you are using PHP, select the version of PHP that you noted down in step 1.
  5. Enter the path of the script that you want to run in the command field. This is the script or program that performs the task. For example, if you want to configure the wp-cron, you can enter the public path of your application that you noted down in step 1, followed by /wp-cron.php.
Creating a cron job in RunCloud.

In the above example, the public path was /home/runcloud/webapps/app-koelpin and the resulting command is /home/runcloud/webapps/app-koelpin/wp-cron.php.

  1. Finally, select a schedule for the job from the Run In dropdown menu. This is how often you want the job to run. You can choose from predefined options or enter a custom cron expression.
  2. Review the content of your cron job in the box below. This is how your cron job will look in the crontab file.
  3. Click on “Create Cron Job” to save and activate your cron job.
  4. If you are creating a cron job for a CMS system such a WordPress, you need to turn off its in-built cron functionality after creating the cron job – otherwise your server will keep executing the jobs twice.

Creating a Supervisor Job

Supervisor is a tool that allows you to monitor and control processes on your server. You can use Supervisor with Docker to run and manage your containerized applications. Here are the steps to create a Supervisor with Docker:

  1. Go to the Supervisor section and click on Add New Job.
list supervisor jobs in RunCloud
  1. In the Job Details section, enter the following details for the job:
    • The name of the job in the “Job Name” field.
    • If your command or vendor binary uses PHP, composer, or wp; check the “Fake Running User” option. This option allows the user to run the command as root, which is required for these commands.
    • The user to run this job as (owner of the application).
    • The number of processes to run in the Numprocs field.
    • The vendor binary in the Vendor Binary field. This is the program that will be used to execute your job. If you don’t want to use any of the predefined options, you can specify your binary in the command filed.
    • The directory to run the command in the Directory field (optional).
    • The Command field contains the command that will be executed.
    • In the Auto Restart section, check or uncheck the Auto Restart option. This option determines whether to restart the job automatically if it exits unexpectedly.
    • In the Auto Start section, check or uncheck the Auto Start option. This option determines whether to start the job automatically when the server boots up.
Creating a supervisor job in RunCloud
  1. Finally, click the “Save Supervisor Job” button to add the job to your server.

If you have any other questions or need help – please feel free to get in touch with our 24/7 support team. We’re here to help!