Forceu / Gokapi

Lightweight selfhosted Firefox Send alternative without public upload. AWS S3 supported.
GNU Affero General Public License v3.0
1.71k stars 69 forks source link

Install Gokapi as a systemd service #152

Closed masoncfrancis closed 7 months ago

masoncfrancis commented 7 months ago

For now, I only implemented code to install the software as a service for systems using systemd because that is very common in most linux distributions. Right now it doesn't support Windows or Mac. With that said, here is how the code works:

The user passes in the --install-service flag. The sofware:

  1. Checks to make sure --install-service and --uninstall-service flags aren't both present, tells the user if there's a problem
  2. Checks if the user is running this command using sudo (required for this action), tells the user if not
  3. Checks if systemd is present on the system, tells the user if not
  4. Drafts the systemd service file contents
  5. Writes the file to /lib/systemd/system/gokapi.service
  6. Reloads systemd
  7. Enables the gokapi service in systemd so it can run on boot
  8. Starts the gokapi service in systemd

It is important to note that the systemd service file points to the path of the gokapi executable we are using to run this

The user can also uninstall the systemd service by using the --uninstall-service flag. When they do that, the software:

  1. Checks to make sure --install-service and --uninstall-service flags aren't both present, tells the user if there's a problem
  2. Checks if the user is running this command using sudo (required for this action), tells the user if not
  3. Checks if systemd is present on the system, tells the user if not
  4. Checks if the service file is present, if not it says so and exits
  5. Stops the gokapi service in systemd
  6. Disables the gokapi service in systemd so it no longer runs on boot
  7. Removes the gokapi service file from /lib/systemd/system
  8. Reloads systemd

I added a section of docs as well, let me know your thoughts.

I will admit, I wasn't entirely sure how your tests work and had issues getting them to work on my system, so I only touched the flag tests but not much else.

Forceu commented 7 months ago

Thank you very much! I refactored a little bit of code and merged it :)

Forceu commented 7 months ago

Also the code always runs the systemd service as root, I added some code to lookup the user invoking sudo in 30e02c1. Maybe have a look at your instance to make sure that it is not ran as root

masoncfrancis commented 7 months ago

Your changes look good. Thanks for accepting the pr!