[LINUX] I want to restart CentOS 8 on time every day.

Something went wrong, so I restarted for the time being

The daily rsync (file server backup) I've been running on CentOS lately sometimes fails ... (´ ・ ω ・ `)

I don't know the cause yet, but I decided to restart it every day for the time being.

Reboot shell script

this.

python


shutdown -r now

-rIs the "restart" option. -hNote that is an option to "turn off the power". (If you turn off the power, you have to go to the front of the machine and click the power button)

Register periodic execution in cron

First, edit the cron configuration file with vi with the following command.

python


crontab -e

Added the following contents.

python


0 3 * * * /usr/sbin/shutdown -r now

Minute, hour, day, month, day of the week command

In the above case, run "/ usr/sbin/shutdown" at 3:00 every day! The option is "-r now"! Meaning.

Why is/usr/sbin/prepended to shutdown?

This is to avoid the exception of "command not found" in cron.

Some commands ** can be executed on a terminal but not with cron **. (The reason is that the path does not pass when executing with cron)

So, I added ```/usr/sbin /` `` to make it ** a command specified with an absolute path ** instead of just a command.

If you want to know the absolute path of shutdown, use the following command.

python


which shutdown

Really? Did you really restart?

You can easily check it with the following command.

python


last reboot

The result looks like this. image.png It restarted at 4:51 on Friday, January 1, meaning that it has been working since then.

It will restart at 3:00 or in the middle of the night, so let's know how to check it later.

Make sure that the necessary services are started as soon as they are started.

For example, the following is a command to start Samba (file server service) at the same time.

python


systemctl enable smb

Periodic restarting with systemd is not allowed!

At first, I tried to execute it regularly with this ↓. ~~ I want to specify the date, day of the week, and time on CentOS and execute it regularly ~~

systemctl enable restart serviceBecause I've done that

Scheduled restart ⇒ ** Restart service starts at the same time as CentOS starts ** ⇒Restart ⇒ ** Restart service starts at the same time as CentOS starts ** ⇒Restart ⇒ ………

It has become an infinite loop ☆ (・ ω <)

"You guys, I'll start restarting in 0 minutes"

If you set `` `-k``` in the shutdown option, you can ** notify the connected terminal ** that it will be restarted **. This is used infrequently but convenient.

Hmmm, I thought I could remember that kind of thing.

Serpentine

I wanted to create a mechanism to notify Line at the same time as starting up or skip mail!

When I restart, the network drive on my Mac mini is unmounted ... (´ ・ ω ・ `) (Tico = file server built with Samba on CentOS) image.png It seems necessary to set a regular execution script on the Mac side or set it so that it will not be unmounted. Well, this is a remaining task.

Reference site

https://eng-entrance.com/linux-command-shutdown https://rainbow-engine.com/linux-scheduled-reboot-script/ https://teratail.com/questions/75302 https://gist.github.com/koudaiii/49ac3f8b7c207f0da31f https://netacore.jp/restart-automatically-centos-server/

version

CentOS Linux release 8.3.2011

Recommended Posts

I want to restart CentOS 8 on time every day.
I want to use Linux on mac
I want to develop Android apps on Android
I want to be cursed by a pretty girl every time I sudo! !!
I want to manage systemd by time zone! !!
I want to do pyenv + pipenv on Windows
I want to log file I / O on Linux
I made a LINE Bot that sends recommended images every day on time
I want to develop an Android application on Android (debugging)
I want to find a popular package on PyPi
I want to AWS Lambda with Python on Mac!
I want to use OpenJDK 11 on Ubuntu Linux 18.04 LTS / 18.10
I want to do Wake On LAN fully automatically
I tried LeetCode every day 121 Best Time to Buy and Sell Stock (Python, Go)
I raised the Python version from 2 to 3, but every time I restart the ubuntu terminal, the version remains 2.
I tried LeetCode every day 13. Roman to Integer (Python, Go)
I want to move selenium for the time being [for mac]
I want to disable interrupts on Raspberry Pi (≒ DI / EI)
I want to announce my graduation thesis on IPython Notebook
I want to convert an ISO-8601 character string to Japan time
I want to create a Dockerfile for the time being.
I tried LeetCode every day 122. Best Time to Buy and Sell Stock II (Python, Go)
I want to use the Ubuntu desktop environment on Android for the time being (Termux version)
I want to use Ubuntu's desktop environment on Android for the time being (UserLAnd version)
Day 65 I installed matplotlib to draw graphs on my Jupyter notebook.
I want to record the execution time and keep a log.
Steps to deploy EMLauncher on CentOS 8
Steps to install MySQL 8.0 on CentOS 8.1
I want to use shortcut translation like DeepL app on Linux
I want to understand systemd roughly
The day Chainer runs on GPU CentOS edition (up to CPU)
Steps to install VirtualBox on CentOS
I want to know if you install Python on Mac ・ Iroha
[Linux] I installed CentOS on VirtualBox
How to install PyPy on CentOS
How to install TensorFlow on CentOS 7
For the time being, I want to convert files with ffmpeg !!
I want to do ○○ with Pandas
I want to copy yolo annotations
How to install Maven on CentOS
I want to debug with Python
I want to use Ubuntu's desktop environment on Android for the time being (Termux version-Japanese input in desktop environment)
For the time being using FastAPI, I want to display how to use API like that on swagger
I want to tweet on Twitter with Python, but I'm addicted to it
I want to separate the processing between test time and production environment
I want to display an image on Jupyter Notebook using OpenCV (mac)
I want to format and check Python code to my liking on VS Code
Python: I want to measure the processing time of a function neatly
I want to detect objects with OpenCV
I want to print in a comprehension
I want to scrape them all together.
I want to know how LINUX works!
I want to blog with Jupyter Notebook
I want to use jar from python
I want to build a Python environment
I want to pip install with PythonAnywhere
I want to analyze logs with Python
Connecting from python to MySQL on CentOS 6.4
I was addicted to Flask on dotCloud
How to switch mouse operations on CentOS
I want to use IPython Qt Console