I want to start a script I have on when the system start and looking for the best way, my way is:
vi /etc/systemd/system/myscript.service
[Service] Type=simple ExecStart=/usr/bin/myscript CPUSchedulingPolicy=rr CPUSchedulingPrioty=27 [Install] WantedBy=multi-user.target graphical.target
systemctl daemon-reload; systemctl enable myscript; systemctl start rmyscript
it's working good but just wondered if there another and better way.
There are a couple of ways to achieve this, but you will need root privileges for any the following. To get root, open a terminal and run the command:
and the command prompt will change to '#' indicating that the terminal session has root privileges.
Alternative #1. Add an initscript
Create a new script in
/etc/init.d/myscript
:(Obviously it doesn't have to be called "myscript".) In this script, do whatever you want to do. Perhaps just run the script you mentioned:
Make it executable:
Configure the init system to run this script at startup:
Alternative #2. Add commands to /etc/rc.local
with content like the following:
Alternative #3. Add an Upstart job
Create
/etc/init/myjob.conf
:with the following content:
BTW:
You don't need to be root if you can edit your crontab
(crontab -e)
and create an entry like this:This way, you can run it as a regular user. @reboot just means it's run when the computer starts up (not necessarily just when it's rebooted).