Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating 'wings service-install' command #136

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"crypto/tls"
"errors"
"fmt"
"github.com/pterodactyl/wings/internal/cron"
"github.com/pterodactyl/wings/internal/database"
log2 "log"
"net/http"
_ "net/http/pprof"
Expand All @@ -30,6 +28,8 @@ import (

"github.com/pterodactyl/wings/config"
"github.com/pterodactyl/wings/environment"
"github.com/pterodactyl/wings/internal/cron"
"github.com/pterodactyl/wings/internal/database"
"github.com/pterodactyl/wings/loggers/cli"
"github.com/pterodactyl/wings/remote"
"github.com/pterodactyl/wings/router"
Expand Down Expand Up @@ -87,6 +87,7 @@ func init() {

rootCommand.AddCommand(versionCommand)
rootCommand.AddCommand(configureCmd)
rootCommand.AddCommand(serviceCmd)
rootCommand.AddCommand(newDiagnosticsCommand())
}

Expand Down
70 changes: 70 additions & 0 deletions cmd/service_install.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package cmd

import (
"fmt"
"os"
"os/exec"

"github.com/apex/log"
"github.com/spf13/cobra"
)

var (
serviceFile = "/etc/systemd/system/wings.service"
serviceContent = `[Unit]
Description=Pterodactyl Wings Daemon
After=docker.service
Requires=docker.service
PartOf=docker.service

[Service]
User=root
WorkingDirectory=/etc/pterodactyl
LimitNOFILE=4096
PIDFile=/var/run/wings/daemon.pid
ExecStart=/usr/local/bin/wings
Restart=on-failure
StartLimitInterval=180
StartLimitBurst=30
RestartSec=5s

[Install]
WantedBy=multi-user.target`
serviceCmd = &cobra.Command{
Use: "service-install",
Short: "Use to install wings.service automatically",
Run: installService,
}
)

func installService(cmd *cobra.Command, args []string) {
if _, err := os.Stat(serviceFile); err == nil {
log.WithField("error", "service file exists").Fatal("service aready installed")
return
}

f, cf_err := os.Create(serviceFile)

if cf_err != nil {
log.WithField("error", cf_err).Fatal("error while creating service file")
return
}

content := []byte(serviceContent)

_, wf_err := f.Write(content)

if wf_err != nil {
log.WithField("error", wf_err).Fatal("error while write service file")
return
}

command := exec.Command("systemctl", "enable", "--now", serviceFile)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are missing a systemctl daemon-reload after adding the systemd files. You need to reload after creating the file before you can start the service

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes i did really forget that, thanks.

cmd_err := command.Start()

if cmd_err != nil {
log.WithField("error", wf_err).Fatal("error while enabling service")
return
}
fmt.Println("service created success!")
}