开发者

How to run script on startup of a Fedora 14 machine

开发者 https://www.devze.com 2023-02-23 03:14 出处:网络
I have an AWS AMI with Fedora 14 installed. I do not have root access but I can do pretty much anything using sudo. I have a script that I want to run on machine startup - myScript.sh.

I have an AWS AMI with Fedora 14 installed. I do not have root access but I can do pretty much anything using sudo. I have a script that I want to run on machine startup - myScript.sh.

开发者_开发问答

This script is called by calling sudo /dir/dir/myScript.sh start. It also supports the commands stop and status which I use very often.

What is the ideal way to run such a script at startup?


I think the simplest and most universal method (although less flexible than @sarnold's suggestions) is to add /dir/dir/myScript.sh start to /etc/rc.local. The script will then be run on boot after all the other start-up scripts have run.


You have a few mechanisms easily available:

The two most common mechanisms:

Adding an upstart job definition file. This looks easy, but does limit the distributions that can use your provided script to a handful of newer ones (Ubuntu, Google's Chrome distribution, Fedora, probably RHEL?).

Adding a sysv-init initscript. init-scripts are harder to write, but have much more flexibility in providing more command line arguments for sysadmins to use. They are also supported nearly everywhere, even distros which have switched (some or most) of their initscripts over to Upstart jobs.

I don't see it often, it is more a system-administrator choice than a software developer choice, but you can also use the system Vixie cron(8) facility to start programs at boot.

You can add entries to the system crontab in /etc/cron.d/*; Vixie cron supports a @reboot specifier which is excellent for this task.

Or, you can add an entry to your own personal crontab(5) file; again, Vixie cron's @reboot works for users too, but you cannot run an interactive sudo(8) from a crontab(5). See the NOPASSWD documentation in sudoers(5) if you want to use your own personal crontab(5) file, but be warned the other admins on the machine may hate this idea.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号