Translate

Thursday 1 November 2018

Service that allow to run a program on boot (Linux Platforn)



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 service
Description=om service
[Service]
#User is as root, the program will run as root user
User=root
# The configuration file application.properties should be here:
#change this to your workspace
WorkingDirectory=/home/om/workplace
#path to executable. 
#put the executable file
ExecStart=/home/om/workplace/myprog
SuccessExitStatus=143
TimeoutStopSec=10
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
--------------------------------------------------------------------------------------------------------------------------

Step 4- Enable the service

$ sudo systemctl daemon-reload
$ sudo systemctl enable sample.service
$ sudo reboot
If 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