In this tutorial I will show you how you can run a program on boot (startup) using Linux platform this will work on all Linux distros
This service can run all type of executable file.
If you want to run you ".c" file, first compile it and put the compiled file name with the directory as written in Step-3 "ExecStart = "..........." and change the working directory directory in Step-3 WorkingDirectory= " ................" this directory is your executable file directory.
This is tested on Ubuntu 18.
Step 1- Go to system directory
$ cd /etc/systemd/system
Step 2- Open vi Edititor and write the service
$ vim myservice.service
Step 3- Paste the following code as instructed
--------------------------------------------------------------------------------------------------------------------------
[Unit]# This is the name of serviceDescription=om service[Service]#User is as root, the program will run as root userUser=root# The configuration file application.properties should be here:#change this to your workspaceWorkingDirectory=/home/om/workplace#path to executable.#put the executable fileExecStart=/home/om/workplace/myprogSuccessExitStatus=143TimeoutStopSec=10Restart=on-failureRestartSec=5[Install]WantedBy=multi-user.target
--------------------------------------------------------------------------------------------------------------------------
Step 4- Enable the service
$ sudo systemctl daemon-reload $ sudo systemctl enable sample.service
$ sudo rebootIf You need any further query please send a message or comment.
Give Something to the world and it will never let you down.
Onkar Dubey
No comments:
Post a Comment