Ubuntu set system environment variables and power-on self starter

Source: Internet
Author: User
Tags chmod numeric value
Ubuntu System environment variable detailed

Refer to this article, speak very detailed boot from boot

There are three ways to set up software automatically on Linux:

1. Automatically start Application--rc.local script
2, automatic start service--UPDATE-RC.D
3, start the application preferences
3. Use Systemd

Here are three ways to interface: First, automatically start the application--rc.local script

The rc.local script is a script that is automatically executed by Ubuntu when it is powered on, adding a command line to the script and automatically executing it when it is powered on.

Script Path/etc/rc.local

Root permission is required to modify. Add Command

Open the file and add the command to execute before exit 0, where you can write commands directly or execute the shell script file sh.

as follows, add 5 lines of command

1th, line 2 is for output log
4th, 5 lines, is the start of the program

#!/bin/sh-e # # rc.local # # This script is executed in the end of each
multiuser runlevel.
# Make sure that script would ' exit 0 ' on success or any other
# value On error.
# in order to
-enable or disable this script just change the execution
# bits.
# by
Default this script does nothing.:
/bin/bash/usr/local/xx-net-3.10.4/xx_net.sh 1>>/etc/mylog<  c12/># send stderr from rc.local to a log file 
2>&1   # Send stdout to the same log file 
set-x    # Tell SH to display commands before execution 
sudo miredo
sudo/usr/local/xx-net-3.10.4/xx_net.sh start
Exit 0

Here's the set up automatically execute sudo command is also able to execute the rc.local command does not execute, the program does not start the problem

1, as shown below, add log, view program performance

2, rc.local file head/bin/sh modified to/bin/bash

3, if it is the execution of SH file, then to give execution permission sudo chmod +x xxx.sh, and then start with sudo sh xxx.sh II, automatic start service--update-rc.d

Use UPDATE-RC.D to increase the boot up service and add a boot script to Ubuntu, as follows:

1. Create a new script file new_service.sh

#!/bin/bash
# command content

exit 0

2, set permissions

sudo chmod 755 new_service.sh
#或者
sudo chmod +x new_service.sh

3. Put the script in the boot directory

sudo mv new_service.sh/etc/init.d/

4, add the script to the boot script

Execute the following instruction, where 90 indicates a priority, the higher the later the execution

cd/etc/init.d/
sudo update-rc.d new_service.sh defaults 90

5. Remove Boot boot script

sudo update-rc.d-f new_service.sh Remove

6, through the sysv-rc-conf to manage the start of the service starting level, etc., whether the boot started

7, Update-rc.d of the detailed parameters

You use the UPDATE-RC.D command to specify the script name and some parameters, and the format looks like this (requires root permissions):

UPDATE-RC.D [-n] [f] <basename> remove
update-rc.d [-n] <basename> defaults
update-rc.d [-n] < Basename> disable|enable [s|2|3|4|5]
update-rc.d <basename> start|stop <NN> <runlevels>
-n:not really

-f:force

Disable|enable: Represents the script also in/ETC/INIT.D and sets whether the current state is started manually or automatically.

Start|stop: On behalf of the script also in the/ETC/INIT.D, power on, and set the current state whether to start or stop running. (Configurable to start or not if enabled)

NN: is a two-digit numeric value that determines the boot order. (for example 90 is greater than 80, so 80 corresponding scripts start first or stop first)

Runlevels: The run level is specified.

Instance:

(1), add a new startup script Sample_init_script, and specify the default boot order, default run level:

UPDATE-RC.D sample_init_script Defaults
the previous command is equivalent to (an English period symbol in the middle):
update-rc.d sample_init_script start 20 2 3 4 5. Stop 20 0 1 6

(2), install a startup script Sample_init_script, specify the default run level, but the startup order is 50:

UPDATE-RC.D Sample_init_script Defaults 50

(3), install two boot scripts A, B, let a start before B, after B stop:

UPDATE-RC.D A
update-rc.d B 20 30

(4), delete a startup script Sample_init_script, if the script does not exist, skip directly:

Update-rc.d-f Sample_init_script Remove

What this command actually does is one by one delete all links in the/ETC/RCX.D directory pointing to Sample_init_script in/ETC/INIT.D (there may be multiple linked files), UPDATE-RC.D just simplifies this step.

(5) Prohibit apache/mysql related components from starting:

Update-rc.d-f apache2 Remove
update-rc.d-f mysql Remove

8, the service start stop state

sudo service XXX status
sudo service xxx start
sudo service xxx stop
sudo service xxx restart

9, see the full list of services

sudo service--status-all
Third, start the application preferences

You can run gnome-session-properties on the console
will open the following window, corresponding to the startup application on the desktop
iv. use of Systemd

The use of systemd is somewhat complicated and has not been tried in person. Interested partners, you can come here to learn some systemd introductory tutorials: command posts

Reference:
Ubuntu Add boot Auto Script

2 ways to add a boot entry under Ubuntu

Ubuntu Add the Boot automatic Start program method

Ubuntu 16.04 set rc.local boot Start command/script method

How Ubuntu uses the Self starter software, the one that starts with root (sudo)

How Ubuntu uses the Self starter software, the one that starts with root (sudo)

Ubuntu setup sudo boot entry without entering a password

How to manage startup application in Ubuntu

Xx-net Ubuntu 16.04 power-on self-starter settings help

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.