Ubuntu 18.04 rc.local systemd settings

Ubuntu 16.04

ubuntu16.04 system can add tasks directly, just edit vim/etc/rc.local

#! /bin/sh -e
# docker-compose start automatically/usr/local/bin/docker-compose -f /home/www/dnmp/dnmp/docker-compose.yml up -d
exit 0

Ubuntu 18.04

ubuntu18.04 no longer uses initd management system, use systemd instead. However, systemd is difficult to use, and the changes are too large, completely different from the previous ones. Use systemd to set boot up. In order to set the startup program in /etc/rc.local as before, the following steps are required:

1、 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/.

Generally, after the system is installed, there will be a rc-local.service file under /lib/systemd/system/, which is the configuration file we need. Link here:

ln -fs /lib/systemd/system/rc-local.service /etc/systemd/system/rc-local.service

View file content

cd /etc/systemd/system/  cat rc-local.service

rc-local.service content

# SPDX-License-Identifier: LGPL-2.1+  ##  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  Documentation=man:systemd-rc-local-generator(8)  ConditionFileIsExecutable=/etc/rc.local  After=network.target
[ Service]  Type=forkingExecStart=/etc/rc.local startTimeoutSec=0  RemainAfterExit=yesGuessMainPID=no  
[ Install]  WantedBy=multi-user.targetAlias=rc-local.service
  1. [ Unit] block: startup sequence and dependencies.

  2. [ Service] block: start behavior, how to start, start type.

  3. [ Install] block, define how to install this configuration file, that is, how to boot up.

2、 Create /etc/rc.local file

touch /etc/rc.local  

3、 Grant executable permissions

chmod 755/etc/rc.local  

4、 Edit rc.local, add tasks that need to be started

#! /bin/bash  echo "test rc ">/var/test.log

5、 Execute reboot to restart the system, and then check test.log

Recommended Posts

Ubuntu 18.04 rc.local systemd settings
Ubuntu16.04 installation partition settings
Ubuntu audio parameter settings
Ubuntu Xfce desktop system settings
How to change PHP settings on Ubuntu 14.04