Skip to content

Instantly share code, notes, and snippets.

@TehPeGaSuS
Last active November 27, 2022 23:38
Show Gist options
  • Save TehPeGaSuS/13d0e00f354f787c392d72411dc59c31 to your computer and use it in GitHub Desktop.
Save TehPeGaSuS/13d0e00f354f787c392d72411dc59c31 to your computer and use it in GitHub Desktop.
#--------------------------------------------------#
# Systemd unit tested on Ubuntu 18.04 and newer #
#--------------------------------------------------#
#----------------------------------------------------------------------------#
# This script will start the bot and make it fork afterwards, as a normal #
# `./eggdrop botname.conf` would do. #
#----------------------------------------------------------------------------#
[Unit]
#------------------------------------------------------------------#
# Set here the description to be shown on systemd control commands #
## ##
# Example: Description=Micaela (Eggdrop) #
#------------------------------------------------------------------#
Description=Micaela (Eggdrop)
#-------------------------------------------------------------#
# DO NOT EDIT THIS OPTION UNLESS YOU KNOW WHAT YOUR'RE DOING! #
#-------------------------------------------------------------#
After=default.target
[Service]
#----------------------------------------------#
# Path to your bot folder #
## ##
# Example: WorkingDirectory=/home/bots/Micaela #
#----------------------------------------------#
WorkingDirectory=/home/bots/Micaela
#------------------------------------------------------------#
# Command to start the bot #
## ##
# Example: ExecStart=/home/bots/Micaela/eggdrop micaela.conf #
#------------------------------------------------------------#
ExecStart=/home/bots/Micaela/eggdrop micaela.conf
#----------------------------------#
# Rehash the bot on reload #
#----------------------------------#
ExecReload=/usr/bin/kill -HUP $MAINPID
#---------------------------------------------------------------------------------------------------------------#
# DON'T TOUCH ANYTHING BELOW UNLESS YOU KNOW WHAT YOU ARE DOING! #
## ##
# If you touch the code below and then complain the script "suddenly stopped working", I'll touch you at night. #
#---------------------------------------------------------------------------------------------------------------#
Type=forking
Restart=always
[Install]
WantedBy=default.target
@TehPeGaSuS
Copy link
Author

TehPeGaSuS commented Oct 17, 2022

Instructions

This was tested on Ubuntu 18.04 and newer but should work in every distro with systemd. Check your distro docs to be sure.

  • Enable lingering for your user with:
    loginctl enable-linger

  • Create the .config/systemd/user directory:

    • Manually with:
      mkdir -p ~/.config/systemd/user
    • Or with the following command:
      systemctl --user enable systemd-tmpfiles-clean.timer && systemctl --user disable systemd-tmpfiles-clean.timer
  • Enter the .config/systemd/user directory with:
    cd ~/.config/systemd/user

  • Download the user unit (replacing <botname>_user.service with your bot name) with:
    wget https://gist.github.com/PeGaSuS-Coder/13d0e00f354f787c392d72411dc59c31/raw/38e1b45667b487d8a4e63295dc05c061c46afcb9/eggdrop_user.service -O <botname>_user.service

  • Edit the user unit to fit your install

  • Reload the user systemd daemon (so your new user unit is loaded) with:
    systemcl --user daemon-reload

  • Start the bot with:
    systemctl --user start <botname>_user.service

  • Stop the bot with:
    systemctl --user stop <botname>_user.service

  • Restart the bot with:
    systemctl --user restart <botname>_user.service

  • Rehash the bot with:
    systemctl --user reload <botname>_user.service

  • Enable the bot to start automatically after a system reboot/restart with:
    systemctl --user enable <botname>_user.service

@TehPeGaSuS
Copy link
Author

TehPeGaSuS commented Oct 17, 2022

Examples

Actual valid user unit for example purposes:

#--------------------------------------------------#
# Systemd unit tested on Ubuntu 18.04 and newer    #
#--------------------------------------------------#

#------------------------------------------------------------#
# This script will start the bot and make it fork afterwards #
# as a normal `./eggdrop botname.conf` would do.             #
#------------------------------------------------------------#

[Unit]
#------------------------------------------------------------------#
# Set here the description to be shown on systemd control commands #
##                                                                ##
# Example: Description=Micaela (Eggdrop)                           #
#------------------------------------------------------------------#
Description=Subzero (Eggdrop)

#-------------------------------------------------------------#
# DO NOT EDIT THIS OPTION UNLESS YOU KNOW WHAT YOUR'RE DOING! #
#-------------------------------------------------------------#
After=default.target

[Service]
#----------------------------------------------#
# Path to your bot folder                      #
##                                            ##
# Example: WorkingDirectory=/home/bots/Micaela #
#----------------------------------------------#
WorkingDirectory=/home/bnc/bot

#------------------------------------------------------------#
# Command to start the bot                                   #
##                                                          ##
# Example: ExecStart=/home/bots/Micaela/eggdrop micaela.conf #
#------------------------------------------------------------#
ExecStart=/home/bnc/bot/eggdrop bot.conf

#----------------------------------#
# Rehash the bot on reload         #
#----------------------------------#
ExecReload=/usr/bin/kill -HUP $MAINPID

#---------------------------------------------------------------------------------------------------------------#
# DON'T TOUCH ANYTHING BELOW UNLESS YOU KNOW WHAT YOU ARE DOING!                                                #
##                                                                                                             ##
# If you touch the code below and then complain the script "suddenly stopped working", I'll touch you at night. #
#---------------------------------------------------------------------------------------------------------------#
Type=forking
Restart=always

[Install]
WantedBy=default.target

Example output of systemctl --user status botname_user.service:

$ systemctl --user status subzero_user.service 
● subzero_user.service - Subzero (Eggdrop)
     Loaded: loaded (/home/bnc/.config/systemd/user/subzero_user.service; disabled; vendor preset: enabled)
     Active: active (running) since Mon 2022-10-17 20:13:42 CEST; 1min 23s ago
    Process: 26653 ExecStart=/home/bnc/bot/eggdrop bot.conf (code=exited, status=0/SUCCESS)
   Main PID: 26655 (eggdrop)
      Tasks: 1 (limit: 2238)
     Memory: 2.8M
        CPU: 46ms
     CGroup: /user.slice/user-1000.slice/[email protected]/app.slice/subzero_user.service
             └─26655 /home/bnc/bot/eggdrop bot.conf

Oct 17 20:13:42 stuff eggdrop[26653]: Loading dccwhois.tcl...
Oct 17 20:13:42 stuff eggdrop[26653]: Loaded dccwhois.tcl
Oct 17 20:13:42 stuff eggdrop[26653]: Userinfo TCL v1.08 loaded (URL BF GF IRL EMAIL DOB PHONE ICQ YOUTUBE TWITCH).
Oct 17 20:13:42 stuff eggdrop[26653]: use '.help userinfo' for commands.
Oct 17 20:13:42 stuff eggdrop[26653]: Userfile loaded, unpacking...
Oct 17 20:13:42 stuff eggdrop[26653]: === Subzero: 1 channels, 7 users.
Oct 17 20:13:42 stuff eggdrop[26653]: Eggdrop v1.9.3+gotmsg (C) 1997 Robey Pointer (C) 2010-2022 Eggheads
Oct 17 20:13:42 stuff eggdrop[26653]: Launched into the background  (pid: 26655)
Oct 17 20:13:42 stuff systemd[1145]: Started Subzero (Eggdrop).
Oct 17 20:13:42 stuff eggdrop[26655]: Eggdrop v1.9.3+gotmsg (C) 1997 Robey Pointer (C) 2010-2022 Eggheads

After this, you can use telnet to login to the bot, as usual.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment