ubuntu-18.04 boot script

Not like other linux settings unsuccessful reasons##

As from ubuntu-16.10, ubuntu no longer uses initd management system, use systemd instead
After looking at the use of systemd, I found that the changes are a bit big, including replacing the functions of service and chkconfig with the systemctl command.
For example, to start the mysql service before:
Sudo is the administrative authority, if the current user is an administrator, please ignore it.

sudo service mysql start

Now use:

sudo systemctl start mysqld.service

In fact, this change is not too big, the main reason is that booting is more complicated than before. systemd reads the configuration files under /etc/systemd/system by default, and the files under this directory will link to the files under /lib/systemd/system/.
Execute ls /lib/systemd/system and you can see that there are many startup scripts, among which are the rc.local.service we need
Open the script content:

# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1of the License, or
# ( at your option) any later version.

# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if/etc/rc.local is executable.[Unit]
Description=/etc/rc.local Compatibility
ConditionFileIsExecutable=/etc/rc.local
After=network.target

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

Generally normal startup files are mainly divided into three parts
[ Unit] section: startup sequence and dependencies
[ Service] section: start behavior, how to start, start type
[ Install] section: Define how to install this configuration file, that is, how to boot up
It can be seen that the startup sequence of /etc/rc.local is behind the network, but obviously it lacks the Install section, and there is no definition of how to boot it, so obviously this configuration is invalid. Therefore, we need to add the [Install] section to him:

[ Install]  
WantedBy=multi-user.target  
Alias=rc-local.service

It should be noted here that ubuntu-18.04 does not have the file /etc/rc.local by default, so you need to create it yourself

The following is an overall description of how to set the ubuntu-18.04 startup script##

1. Create rc-local.service file####

sudo vi /etc/systemd/system/rc-local.service

2. Copy the following content into the rc-local.service file####

[ Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
 
[ Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99[Install]
WantedBy=multi-user.target

3. Create file rc.local

sudo vi /etc/rc.local

4. Copy the following content into the rc.local file####

#! /bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By defaultthis script does nothing.
echo  java -jar /home/intel/XXX.jar --spring.config.location=/home/intel/config/application.properties >/home/intel/XXXX.log &>/usr/local/test.log
exit 0

5. Add permissions to rc.local####

sudo chmod +x /etc/rc.local

6. Enable service

sudo systemctl enable rc-loca

7. Start the service and check the status

sudo systemctl start rc-local.service
sudo systemctl status rc-local.service

8. Restart and check the test.log file

cat /usr/local/test.log

Recommended Posts

ubuntu-18.04 boot script
Ubuntu software
Linux (ubuntu 12.04)