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
sudo vi /etc/systemd/system/rc-local.service
[ 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
sudo vi /etc/rc.local
#! /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
sudo chmod +x /etc/rc.local
sudo systemctl enable rc-loca
sudo systemctl start rc-local.service
sudo systemctl status rc-local.service
cat /usr/local/test.log