1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-12-22 09:00:10 +00:00

add "systemd" command to generate a .service file

never got around to adding this from jellyfin-accounts for some reason.
This commit is contained in:
Harvey Tindall 2021-04-24 18:54:31 +01:00
parent 90a2c1f2e7
commit 886ae64feb
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2
3 changed files with 43 additions and 6 deletions

View File

@ -94,6 +94,8 @@ copy:
$(info copying static data) $(info copying static data)
-mkdir -p $(DATA)/web -mkdir -p $(DATA)/web
cp -r static/* $(DATA)/web/ cp -r static/* $(DATA)/web/
$(info copying systemd service)
cp jfa-go.service $(DATA)/
$(info copying language files) $(info copying language files)
cp -r lang $(DATA)/ cp -r lang $(DATA)/
cp LICENSE $(DATA)/ cp LICENSE $(DATA)/

View File

@ -8,8 +8,6 @@
--- ---
jfa-go is a user management app for [Jellyfin](https://github.com/jellyfin/jellyfin) (and now [Emby](https://emby.media/)) that provides invite-based account creation as well as other features that make one's instance much easier to manage. jfa-go is a user management app for [Jellyfin](https://github.com/jellyfin/jellyfin) (and now [Emby](https://emby.media/)) that provides invite-based account creation as well as other features that make one's instance much easier to manage.
I chose to rewrite the python [jellyfin-accounts](https://github.com/hrfee/jellyfin-accounts) in Go mainly as a learning experience, but also to slightly improve speeds and efficiency.
#### Features #### Features
* 🧑 Invite based account creation: Sends invites to your friends or family, and let them choose their own username and password without relying on you. * 🧑 Invite based account creation: Sends invites to your friends or family, and let them choose their own username and password without relying on you.
* Send invites via a link and/or email * Send invites via a link and/or email
@ -26,8 +24,8 @@ I chose to rewrite the python [jellyfin-accounts](https://github.com/hrfee/jelly
* 📣 Announcements: Bulk email your users with announcements about your server. * 📣 Announcements: Bulk email your users with announcements about your server.
* Authentication via Jellyfin: Instead of using separate credentials for jfa-go and Jellyfin, jfa-go can use it as the authentication provider. * Authentication via Jellyfin: Instead of using separate credentials for jfa-go and Jellyfin, jfa-go can use it as the authentication provider.
* Enables the usage of jfa-go by multiple people * Enables the usage of jfa-go by multiple people
* 🌓 Customizable look * 🌓 Customizations
* Edit emails with variables and markdown * Customize emails with variables and markdown
* Specify contact and help messages to appear in emails and pages * Specify contact and help messages to appear in emails and pages
* Light and dark themes available * Light and dark themes available
@ -71,8 +69,6 @@ Otherwise, full build instructions can be found [here](https://github.com/hrfee/
#### Usage #### Usage
Simply run `jfa-go` to start the application. A setup wizard will start on `localhost:8056` (or your own specified address). Upon completion, refresh the page. Simply run `jfa-go` to start the application. A setup wizard will start on `localhost:8056` (or your own specified address). Upon completion, refresh the page.
Note: jfa-go does not run as a daemon by default. You'll need to figure this out yourself.
``` ```
Usage of ./jfa-go: Usage of ./jfa-go:
-config string -config string
@ -89,6 +85,11 @@ Usage of ./jfa-go:
Enable swagger at /swagger/index.html Enable swagger at /swagger/index.html
``` ```
#### Systemd
jfa-go does not run as a daemon by default. Run `jfa-go systemd` to create a systemd `.service` file in your current directory, which you can copy into `~/.config/systemd/user` or somewhere else.
---
If you're switching from jellyfin-accounts, copy your existing `~/.jf-accounts` to: If you're switching from jellyfin-accounts, copy your existing `~/.jf-accounts` to:
* `XDG_CONFIG_DIR/jfa-go` (usually ~/.config/jfa-go) on \*nix systems, * `XDG_CONFIG_DIR/jfa-go` (usually ~/.config/jfa-go) on \*nix systems,

34
main.go
View File

@ -739,6 +739,40 @@ func main() {
fmt.Println("Sent.") fmt.Println("Sent.")
} else if flagPassed("daemon") { } else if flagPassed("daemon") {
start(true, true) start(true, true)
} else if flagPassed("systemd") {
service, err := fs.ReadFile(localFS, "jfa-go.service")
if err != nil {
fmt.Printf("Couldn't read jfa-go.service: %v\n", err)
os.Exit(1)
}
absPath, err := filepath.Abs(os.Args[0])
if err != nil {
absPath = os.Args[0]
}
command := absPath
for i, v := range os.Args {
if i != 0 && v != "systemd" {
command += " " + v
}
}
service = []byte(strings.Replace(string(service), "{executable}", command, 1))
err = os.WriteFile("jfa-go.service", service, 0666)
if err != nil {
fmt.Printf("Couldn't write jfa-go.service: %v\n", err)
os.Exit(1)
}
fmt.Print(info(`If you want to execute jfa-go with special arguments, re-run this command with them.
Move the newly created "jfa-go.service" file to ~/.config/systemd/user (Creating it if necessary).
Then run "systemctl --user daemon-reload".
You can then run:
`))
color.New(color.FgGreen).PrintFunc()("To start: ")
fmt.Print(info("systemctl --user start jfa-go\n\n"))
color.New(color.FgRed).PrintFunc()("To stop: ")
fmt.Print(info("systemctl --user stop jfa-go\n\n"))
color.New(color.FgYellow).PrintFunc()("To restart: ")
fmt.Print(info("systemctl --user stop jfa-go\n"))
} else { } else {
RESTART = make(chan bool, 1) RESTART = make(chan bool, 1)
start(false, true) start(false, true)