HowTo Run A Script At Boot: Difference between revisions

From MediaWiki
Jump to navigationJump to search
(Created page with "When customizing a NST system, it is often desirable to run a script at boot time to perform some specific actions. In the past, you could simply edit the ''/etc/rc.d/rc.local''...")
 
No edit summary
 
(One intermediate revision by the same user not shown)
Line 30: Line 30:
* Make it executable.
* Make it executable.


Here is a example which starts up a VNC server for the root user:
Here is a example ''/etc/rc.d/rc.local'' file which starts up a VNC server for the ''pkb'' user account automatically at boot time:


  #!/bin/bash
  #!/bin/bash
  nstvncadmin --mode setup -d 6 --desktopmgr fluxbox
  /bin/su - pkb -c 'nstvncadmin --mode setup -d 6 --desktopmgr fluxbox';

Latest revision as of 07:00, 15 October 2012

When customizing a NST system, it is often desirable to run a script at boot time to perform some specific actions.

In the past, you could simply edit the /etc/rc.d/rc.local configuration file to run system specific commands. After Fedora moved to using systemd to manage system services, the /etc/rc.d/rc.local file is no longer present. However, the /etc/rc.d/rc.local script is still honored by systemd via the rc-local.service target.

You can verify that the rc-local.service is enabled at boot time using the following command:

[root@taco-dev32 nstboot]# systemctl is-enabled rc-local.service && echo yes
static
yes
[root@taco-dev32 nstboot]# 

At the time of this writing, the rc-local.service target looked something like the following:

[Unit]
Description=/etc/rc.d/rc.local Compatibility
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.d/rc.local start
TimeoutSec=0
RemainAfterExit=yes
SysVStartPriority=99

To run commands at boot time using the rc-local.service script you need to do the following:

  • Create the file: /etc/rc.d/rc.local.
  • Optionally check for the "start" argument (which is passed via the ExecStart parameter shown above).
  • Put the commands you want to run inside the file.
  • Make it executable.

Here is a example /etc/rc.d/rc.local file which starts up a VNC server for the pkb user account automatically at boot time:

#!/bin/bash
/bin/su - pkb -c 'nstvncadmin --mode setup -d 6 --desktopmgr fluxbox';