Manage my redis service with systemctl

Author: @hackedunit
I just fixed a bug.

  1. Install pre-requisities

    1
    
    $ sudo apt-get install  tcl8.6-dev
    1. Install Redis

      1
      2
      3
      4
      5
      6
      7
      8
      
      $ cd /tmp  
      $ wget http://download.redis.io/redis-stable.tar.gz  
      $ tar xzvf redis-stable.tar.gz  
      $ cd redis-stable  
      $ make  
      $ make test  
      $ sudo make install  
        
      1. Configure Redis

        1
        2
        3
        4
        
        $ sudo mkdir /etc/redis  
        $ sudo cp /tmp/redis-stable/redis.conf /etc/redis  
        $ sudo vi /etc/redis/redis.conf  
          

        In the file, change the supervised directive’s value to systemd.

        1
        2
        3
        4
        
        ...  
        supervised systemd  
        ...  
          

        Next, specify the working directory for Redis. This is the directory that Redis will use to dump persistent data. We can use

        1
        2
        3
        4
        5
        6
        
        /var/lib/redis
        ``````
        ...  
        dir /var/lib/redis  
        ...  
          

        Save and close the file. 4. Configure systemd to start Redis on boot

         1
         2
         3
         4
         5
         6
         7
         8
         9
        10
        11
        12
        13
        14
        15
        
        $ sudo vi /etc/systemd/system/redis.service  
        [Unit]  
        Description=Redis In-Memory Data Store  
        After=network.target  
          
        [Service]  
        User=redis  
        Group=redis  
        Type=forking  
        ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf  
        ExecStop=/usr/local/bin/redis-cli shutdown  
        Restart=always  
          
        [Install]  
        WantedBy=multi-user.target  
        1. Create Redis user, group and directories

          1
          2
          3
          4
          
          $ sudo adduser --system --group --no-create-home redis  
          $ sudo mkdir /var/lib/redis  
          $ sudo chown redis:redis /var/lib/redis  
            
          1. Start the Redis service and set Redis to start on boot

            1
            2
            3
            4
            
            $ sudo systemctl start redis  
            $ sudo systemctl enable redis  
            $ sudo systemctl status redis