How to run Houdini as a Service on Ubuntu 18

Hi!
In this tutorial, I’ll show you how to run Houdini as a Service on Ubuntu 18.

Why?

Having houdini as a service makes it easier to start, stop, and restart it. It also lets you autostart it when your server starts up.

Prerequisites & Notes

  • You’ve already installed Houdini Legacy on Ubuntu following the official tutorial.
  • You are following the tutorial on a non-root user account with sudo privileges. Click here to learn how to make one
  • Houdini is accessing the database using a MySQL/MariaDB account other than root. To make one, you can enter the MySQL commandline sudo mysql and run the following queries:
    • CREATE USER 'Houdini'@'localhost' IDENTIFIED BY 'PASSWORD_HERE'; (Replace PASSWORD_HERE with a password. You can use this site to generate a password. Use a “Fort Knox” password and make sure it doesn’t have any 's or ;s.
    • GRANT ALL PRIVILEGES ON '*'.'Houdini' TO 'Houdini'@'localhost';
  • In this tutorial, I use vim as my text editor. You can use whatever editor you want.
    • Basic tutorial how to use vim:
      • When you open vim, press I to go into insert mode (contrary to the name, this is the normal mode where you can write stuff, erase stuff, etc like in notepad).
      • To save and exit, press ESC then write :x and press Enter

The Tutorial

Installation

  1. Create a user account that will run the Houdini service.
  • adduser houdini --disabled-password
  1. Move your Houdini installation to the new account’s home folder.
  • mkdir /home/houdini/h
  • mv ~/houdini/* /home/houdini/h
  1. Navigate to the new location and make a new folder called service, then navigate into it.
  • cd /home/houdini/h
  • mkdir service
  • cd service
  1. Make a new script called start.sh
  • vim start.sh
  1. and paste the following code into it
#!/bin/bash
cd ~/h
python Login.py &
python World.py
  1. If you have more than one server, for example World.py and Marshmallow.py, add lines to the script above but replace World.py with the other filename. Make sure every python line except the last one has a & at the end, or else it won’t work. Like this:
#!/bin/bash
cd ~/h
python Login.py &
python World.py &
python Marshmallow.py
  1. Save and exit, then make the file executable
  • sudo chmod +x start.sh
  1. Navigate to /etc/systemd/system and make a file called houdini.service:
  • cd /etc/systemd/system
  • sudo vim houdini.service
  1. Then paste the following code into it
[Unit]
Description=Club Penguin AS2 server written in Python.
Wants=mysqld.service
[Service]
User=houdini

WorkingDirectory=/home/houdini/h
ExecStart=/bin/bash /home/houdini/h/service/start.sh

Type=simple
  • Save and exit.
  1. Now that we’re done, go back into cd /home/houdini/h then run these commands to give it ownership of the files.
  • sudo chown -R houdini:houdini /home/houdini/h
  • sudo chmod -R u=rw,g=rw,o=rw /home/houdini/h Optional: Change permissions on the houdini folder so that other users can edit files too. This is so that you can change stuff without having to sudo su houdini.
  1. Reload the systemctl daemon
  • systemctl daemon-reload
  1. Optionally, enable automatically starting the houdini service when the VPS/server starts
  • systemctl enable houdini.service
  1. Start Houdini to see if it works. service houdini start

Usage

  • To start Houdini, run service houdini start
  • To stop Houdini, run service houdini stop
  • To restart Houdini, run service houdini restart
  • To enable automatically starting when the server starts, run systemctl enable houdini.service
  • To disable automatically starting when the server starts, run systemctl disable houdini.service

The End

If you need help or think I forgot something, PM me on discord at daniel11420#0069 or reply to this thread. Hope this helps someone. Thanks for reading.

2 Likes