Apache restarting : "Graceful restart requested, doing restart"

22

Solution 1

This is likely due to log rotation that is scheduled to run regularly. In Debian and derived distributions, you can look at /etc/logrotate.d for the log rotation scripts for Apache.

Log rotation is a good practice, this way the log files won't fill up your hard disks.

Solution 2

Graceful restart requested is normal in Apache -- part of crontab rotation. If you poke around in your /var/log/auth.log (or equivalent on your distribution) you will see the crontabs being run regularly.

Poke around further by looking at your crontabs: with ls -l /etc/cron* or equivalent on your distro you will find a list of all your crontabs run by root automatically. One of them will be /etc/cron.daily/logrotate which will run the equivalent of

/usr/sbin/logrotate /etc/logrotate.conf 

which in turn has a line within it:

include /etc/logrotate.d

which has a list of log rotation scripts, one of them being /etc/logrotate.d/apache which on mine starts off:

/var/log/apache2/*.log {
    daily

You can adjust it to run more or less frequently if you like, but the base settings on my server are good enough.

Share:
22

Related videos on Youtube

Vuyi
Author by

Vuyi

Updated on September 18, 2022

Comments

  • Vuyi
    Vuyi almost 2 years

    So I was working on the login and logout part of the site, it was working perfectly until I implemented protected routes and now it renders empty pages. What I was doing was that, an un-logged in user cannot have access to any page of the site but the login page so if the user logs in, it is directed to the home page(which is a protected route) and then when it logs out, it is directed to the login page but the moment I logged out, it has been giving me empty pages with this error below

    Cannot destructure property 'user' of 'JSON.parse(...)' as it is null at Nav (Nav.js:8:1)

    in my console. I know my solution has something to do with setting the property with null with a default value but I do not know how to do that as I have spent a lot of time trying to so I am stuck.

    This is what my code looks like starting with the App.js file

    import './App.css';
    import Home from './pages/Home';
    import Register from './pages/Register';
    import Login from './pages/Login';
    import Cart from './pages/Cart';
    import ProductInfo from './pages/ProductInfo';
    import { BrowserRouter, Navigate, Route, Routes } from 'react-router-dom';
    
    function App() {
      return (
        <div className="App">
          <BrowserRouter>
            <Routes>
              <Route path='/' exact element={<ProtectedRoutes><Home /></ProtectedRoutes>} />
              <Route path='/productinfo/:id' exact element={<ProtectedRoutes><ProductInfo /></ProtectedRoutes>} />
              <Route path='/register' exact element={<Register />} />
              <Route path='/login' exact element={<Login />} />
              <Route path='/cart' element={<ProtectedRoutes><Cart /></ProtectedRoutes>} />
            </Routes>
          </BrowserRouter>
        </div>
      );
    }
    
    export default App;
    
    export const ProtectedRoutes = ({children}) => {
      if(localStorage.getItem("currentUser")){
        return children;
      } else {
        return <Navigate to="/login" />
      }
    }
    

    Then followed by the Login.js file

    import { getAuth, signInWithEmailAndPassword } from "firebase/auth";
    import Layout from '../components/Layout';
    import React, {useState} from 'react';
    import "../styles/login.css";
     
     export default function Login() {
      const [email, setemail] = useState("");
      const [password, setpassword] = useState("");
      const auth = getAuth();
      
      const loginUser = async (e) => {
        e.preventDefault();
        try {
          const result = await signInWithEmailAndPassword(auth, email, password);
          localStorage.setItem("currentUser", JSON.stringify(result));
          window.location.href = "/";
        } catch (error) {
          console.log("Something must've went wrong in your code:", error.message);
        }
      }
    
       return (
         <Layout>
          <div className="container">
              <form action="" className='login-form' onSubmit={loginUser}>
                <input type="email" value={email} name="email" id="username-field" class="login-form-field" placeholder="email" onChange={e => setemail(e.target.value)} />
                <input type="password" value={password} name="password" id="password-field" class="login-form-field" placeholder="password" onChange={e => setpassword(e.target.value)} />
                <button id="login-form-submit">Register</button>
              </form>
          </div>
         </Layout>
       )
     }
     
    

    and lastly the Nav.js file which is the navigation bar and has the logout logic on it

    import React from 'react'
    import { Link } from 'react-router-dom'
    import "../styles/navbar.css"
    import { useSelector } from 'react-redux'
    
    const Nav = () => {
      const {cartItems} = useSelector(state => state.cartReducer);
      const {user} = JSON.parse(localStorage.getItem("currentUser"))
    
      const logOut = () => {
        localStorage.removeItem("currentUser");
        window.location.reload();
      }
    
      return (
        <nav className="navbar navbar-expand-lg navbar-light raw">
      <div className="container-fluid">
        <Link className="navbar-brand" to="/">Firecommerce</Link>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="/navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>
        <div className="collapse navbar-collapse" id="navbarSupportedContent">
          <ul className="navbar-nav me-auto mb-2 mb-lg-0 ms-auto">
            <li className="nav-item">
              <Link className="nav-link active" to="/">Home</Link>
            </li>
            <li className="nav-item">
              <Link className="nav-link active" to="/orders">Orders</Link>
            </li>
            <li className="nav-item">
              <Link className="nav-link active" to="/">{user.email.substring(0, user.email.length - 10)}</Link>
            </li>
            <li className="nav-item">
              <Link className="nav-link active" to="/login">Login</Link>
            </li>
            <li className="nav-item">
              <Link className="nav-link active" to="/login" onClick={logOut}>LogouT</Link>
            </li>
            <li className="nav-item">
              <Link className="nav-link active" to="/cart">Cart <span style={{color: "red"}}>{cartItems.length}</span> </Link>
            </li>
          </ul>
          <form className="d-flex">
          </form>
        </div>
      </div>
    </nav>
      )
    }
    
    export default Nav