Skip to content

Instantly share code, notes, and snippets.

@TehPeGaSuS
Last active October 17, 2022 18:21
Show Gist options
  • Save TehPeGaSuS/177325c0cb14564bc45a7ba1885d9862 to your computer and use it in GitHub Desktop.
Save TehPeGaSuS/177325c0cb14564bc45a7ba1885d9862 to your computer and use it in GitHub Desktop.
#--------------------------------------------------#
# Be sure to have screen installed in your machine #
# Systemd unit tested on Ubuntu 18.04 and newer #
#--------------------------------------------------#
#----------------------------------------------------------------------------#
# This script will start the bot under a dettached screen session so you can #
# attach to the session and use the terminal to simulate DCC chat #
# You can still use telnet to connect to the bot, nonetheless #
#----------------------------------------------------------------------------#
[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, using a screen session. #
## #
# Example: ExecStart=/usr/bin/screen -L -U -dmS Micaela /home/bots/Micaela/eggdrop -t micaela.conf #
# Explanation of the options used here: #
# -L = logs the entire screen session on a file named screenlog.0 in the bot folder. #
# -U = Tell screen to use UTF-8 encoding. #
# -dmS <name> = Start as daemon: Screen session in detached mode. #
#------------------------------------------------------------------------------------------------------------------------------------#
ExecStart=/usr/bin/screen -L -U -dmS Micaela /home/bots/Micaela/eggdrop -t micaela.conf
#---------------------------------------------------------------------------------------------------#
# Command to stop the bot #
## #
# Unfortunatelly seems I have to send a `quit` to the screen session, otherwise it will error with: #
# Main process exited, code=exited, status=1/FAILURE #
## #
# Example: ExecStop=/usr/bin/screen -XS Micaela quit #
#---------------------------------------------------------------------------------------------------#
ExecStop=/usr/bin/screen -XS Micaela quit
#---------------------------------------------------------------------------------------------------------------#
# 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=on-failure
[Install]
WantedBy=default.target
@TehPeGaSuS
Copy link
Author

TehPeGaSuS commented Dec 4, 2021

Examples

Actual valid user unit for example purposes:

#--------------------------------------------------#
# Be sure to have screen installed in your machine #
# Systemd unit tested on Ubuntu 18.04 and newer    #
#--------------------------------------------------#

#----------------------------------------------------------------------------#
# This script will start the bot under a dettached screen session so you can #
# attach to the session and use the terminal to simulate DCC chat            #
# You can still use telnet to connect to the bot, nonetheless                #
#----------------------------------------------------------------------------#

[Unit]
#------------------------------------------------------------------#
# Set here the description to be shown on systemd control commands #
##                                                                 #
# Example: Description=Micaela (Eggdrop)                           #
#------------------------------------------------------------------#
Description=Scheherazade (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/Scheherazade

#------------------------------------------------------------------------------------------------------------------------------------#
# Command to start the bot, using a screen session.                                                                                  #
##                                                                                                                                   #
# Example: ExecStart=/usr/bin/screen -L -U -dmS Micaela /home/bots/Micaela/eggdrop -t micaela.conf                                   #
# Explanation of the options used here:                                                                                              #
#	-L = logs the entire screen session on a file named screenlog.0 in the bot folder.                                               #
#	-U = Tell screen to use UTF-8 encoding.                                                                                          #
#	-dmS <name> = Start as daemon: Screen session in detached mode.                                                                  #
#------------------------------------------------------------------------------------------------------------------------------------#
ExecStart=/usr/bin/screen -L -U -dmS Scheherazade /home/bots/Scheherazade/eggdrop -t scheherazade.conf

#---------------------------------------------------------------------------------------------------#
# Command to stop the bot                                                                           #
##                                                                                                  #
# Unfortunatelly seems I have to send a `quit` to the screen session, otherwise it will error with: #
# Main process exited, code=exited, status=1/FAILURE                                                #
##                                                                                                  #
# Example: ExecStop=/usr/bin/screen -XS Micaela quit                                                #
#---------------------------------------------------------------------------------------------------#
ExecStop=/usr/bin/screen -XS Scheherazade quit

#---------------------------------------------------------------------------------------------------------------#
# 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=on-failure

[Install]
WantedBy=default.target

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

$ systemctl --user status scheherazade_screen_user.service 
● scheherazade.service - Scheherazade (Eggdrop)
     Loaded: loaded (/home/bots/.config/systemd/user/scheherazade_screen_user.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2022-10-02 22:43:27 CEST; 5min ago
    Process: 1465372 ExecStart=/usr/bin/screen -U -dmS Scheherazade /home/bots/Scheherazade/eggdrop -t scheherazade.conf (code=exited, status=0/SUCCESS)
   Main PID: 1465373 (screen)
      Tasks: 3 (limit: 4554)
     Memory: 13.6M
        CPU: 3.611s
     CGroup: /user.slice/user-1001.slice/user@1001.service/app.slice/scheherazade_screen_user.service
             ├─1465373 /usr/bin/SCREEN -U -dmS Scheherazade /home/bots/Scheherazade/eggdrop -t scheherazade.conf
             └─1465374 /home/bots/Scheherazade/eggdrop -t scheherazade.conf

Oct 02 22:43:27 X3 systemd[1974]: Starting Scheherazade (Eggdrop)...
Oct 02 22:43:27 X3 systemd[1974]: Started Scheherazade (Eggdrop).

After this, you can use telnet to login to the bot or just use screen -r Scheherazade. To detach from a screen session, use Ctrl+A, D

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