To make a binary file run on boot, you can create a startup script that will run the binary file when the operating system starts. The exact process for creating a startup script depends on the operating system you’re using. Here’s an example for a Linux operating system using the systemd init system:

Create a new script file in the /etc/systemd/system directory. For example, you could name it mybinary.service.

Add the following content to the file, replacing /path/to/mybinary with the actual path to your binary file:

Demo file

[Unit]
Description=My Binary

[Service]
ExecStart=/path/to/mybinary
Restart=always
User=root

[Install]
WantedBy=multi-user.target
Alias=myService.service

Note: If you want to run a shell script file, you can use this code below

ExecStart=/bin/bash /path/to/myscript.sh

Or

ExecStart=/bin/bash /path/to/myscript.sh &

Reload the systemd manager configuration:

sudo systemctl daemon-reload

Enable the service to start at boot and then start it:

#Enable
sudo systemctl enable mybinary.service
#Start the service:
sudo systemctl start mybinary.service

After these steps, the binary file will run every time the operating system starts. You can use systemctl commands to manage the service, such as checking its status (systemctl status mybinary.service) or stopping it (systemctl stop mybinary.service).

Note: The process for creating a startup script may vary depending on the operating system and init system being used. If you’re using a different operating system or init system, you may need to follow different steps.

More guide on .service file

Or, if you want to run the script with nohup to run background and prevent it from being terminated , you might think of something like

ExecStart=nohup /path/to/myscript.sh &

or

ExecStart=nohup /bin/bash /path/to/myscript.sh &

it will both raise an error : Exec format error

The nohup command is used to run a command in the background and prevent it from being terminated when the terminal session ends. It is not a valid executable format for the ExecStart directive in a service file, which expects an executable binary or a script in a valid shell script format.

To resolve the issue, you can modify the ExecStart directive to run the script directly, without using nohup. For example, if your script is located at /path/to/script.sh, the ExecStart directive could be as follows: (with an & last)

ExecStart=/bin/bash /path/to/script.sh &

Another way to Make a binary file or script file run on startup on ubuntu

Use crontab
crontab -e
Add the following line at the end of the file, replacing /path/to/script.sh with the actual path to your script:

@reboot /bin/bash /path/to/script.sh &

REF

Bài viết khác

Use AWS to deploy your applications and services

Amazon Web Services (AWS) is a cloud computing platform that provides a wide range of services to help businesses and individuals build and deploy applications in the cloud. AWS offers a variety of services such as compute, storage, databases, networking, security, and more. In this guide, we will walk through the steps to get started […]

Use docker to run go project

Docker is a powerful tool that enables developers to create, deploy and run applications in a containerized environment. Using Docker to run Go projects has many advantages, including the ability to isolate your application from the underlying operating system, simplifying the deployment process, and allowing for greater scalability and flexibility. In this guide, we will […]

Install WSL for windows 10

1/ Enable feature Windows Subsystem for Linux Head to Control Panel > Programs > Turn Windows Features On Or Off. Enable the “Windows Subsystem for Linux” option in the list, and then click the “OK” button. Restart computer Now you can type on console: wsl –help 2/ Download ubuntu 18 from Microsoft Store or open […]

Explicit ssl bumping with Squid

To perform explicit SSL bumping with Squid, you need to perform the following steps: Generate a SSL certificate and key: You can either generate a self-signed certificate or obtain one from a certificate authority. The certificate and key will be used by Squid to encrypt and decrypt the traffic. Install and configure Squid: Squid is […]

Explicit ssl bumping with HAProxy

Basic guide About Explicit SSL bumping Explicit SSL bumping also known as “SSL interception,” is a feature of some reverse proxies and security appliances that allows the proxy to decrypt, inspect, and re-encrypt SSL/TLS encrypted traffic. The proxy acts as a man-in-the-middle, decrypting incoming SSL/TLS traffic and re-encrypting it before forwarding it to the destination […]

Nodes and Clusters

It is best practice to create clusters with at least three nodes to guarantee reliability and efficiency Every cluster has one master node, which is a unified endpoint within the cluster, and at least two worker nodes Here, we discover some points of nodes and clusters. Let’s begin Nodes and clusters are two of the […]