-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add GO-GIN Management script (#11)
* feat: Add GO-GIN Management script * chore: update file names in build and release workflows * Refactor installation script variables and paths * feat: add go-gin service and plist files, and install script * Update GG_REPO_BRANCH in install.sh * Update go-gin.service description and ExecStart command * Add sqlite package and update dependencies
- Loading branch information
Showing
14 changed files
with
657 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,10 +19,10 @@ If you want to develop with this project, you can follow the steps below. | |
git clone [email protected]:funnyzak/go-gin.git && cd go-gin | ||
``` | ||
|
||
2. Copy the `config.yaml.example` file to `config.yaml` and update the values. | ||
2. Copy the `config.example.yaml` file to `config.yaml` and update the values. | ||
|
||
```bash | ||
cp config.yaml.example config.yaml | ||
cp config.example.yaml config.yaml | ||
``` | ||
|
||
3. Run the application. | ||
|
@@ -48,7 +48,7 @@ You can fork this repository and add Secrets Keys: `DOCKER_USERNAME` and `DOCKER | |
├── cmd | ||
│ ├── main.go // The main entry point for the application | ||
│ └── srv // Server controller | ||
├── config.yaml.example // An example configuration file for the project | ||
├── config.example.yaml // An example configuration file for the project | ||
├── docker-compose.yml // Defines services, networks and volumes for docker-compose | ||
├── internal | ||
│ ├── gconfig // Internal package for configuration | ||
|
@@ -77,7 +77,7 @@ You can fork this repository and add Secrets Keys: `DOCKER_USERNAME` and `DOCKER | |
|
||
## Configuration | ||
|
||
The configuration file is in the `config.yaml` file, you can copy the `config.yaml.example` file to `config.yaml` and update the values, the configuration file is as follows: | ||
The configuration file is in the `config.yaml` file, you can copy the `config.example.yaml` file to `config.yaml` and update the values, the configuration file is as follows: | ||
|
||
```yaml | ||
server: | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" | ||
"http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>Label</key> | ||
<string>go-gin</string> | ||
<key>ProgramArguments</key> | ||
<array> | ||
<string>/opt/go-gin/go-gin</string> | ||
<string>-c</string> | ||
<string>/opt/go-gin/config.yaml</string> | ||
</array> | ||
<key>KeepAlive</key> | ||
<true/> | ||
<key>RunAtLoad</key> | ||
<true/> | ||
<key>WorkingDirectory</key> | ||
<string>/opt/go-gin</string> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[Unit] | ||
Description=go-gin service | ||
After=syslog.target | ||
|
||
[Service] | ||
Type=simple | ||
User=nobody | ||
Group=nogroup | ||
Restart=on-failure | ||
RestartSec=30s | ||
WorkingDirectory=/opt/go-gin | ||
ExecStart=/opt/go-gin/go-gin -c go-gin | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
$taskName = "go-gin" | ||
$programPath = Join-Path $PSScriptRoot "go-gin.exe" | ||
$workingDir = $PSScriptRoot | ||
|
||
# check if Administrator | ||
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator") | ||
if (-not $isAdmin) { | ||
Write-Host "Please run this script as Administrator." | ||
exit | ||
} | ||
|
||
if ($args[0] -eq "enable") { | ||
# first check if the task exists | ||
$task = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue | ||
if ($task -ne $null) { | ||
Write-Host "Task $taskName already exists." | ||
$status = Get-ScheduledTask -TaskName $taskName | Select-Object State | ||
if ($status.State -eq "Running") { | ||
Write-Host "Task $taskName is already running." | ||
} else { | ||
Start-ScheduledTask -TaskName $taskName | ||
Write-Host "Task $taskName started." | ||
} | ||
} else { | ||
Write-Host "Creating task $taskName..." | ||
$action = New-ScheduledTaskAction -Execute $programPath -WorkingDirectory $workingDir | ||
$trigger = New-ScheduledTaskTrigger -AtStartup | ||
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable -DontStopOnIdleEnd | ||
$principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount | ||
Register-ScheduledTask -TaskName $taskName -Action $action -Trigger $trigger -Settings $settings -Principal $principal | ||
Start-ScheduledTask -TaskName $taskName | ||
Write-Host "Task $taskName created." | ||
} | ||
} elseif ($args[0] -eq "disable") { | ||
# first check if the task exists | ||
$task = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue | ||
if ($task -eq $null) { | ||
Write-Host "Task $taskName does not exist." | ||
} else { | ||
Write-Host "Deleting task $taskName..." | ||
Stop-ScheduledTask -TaskName $taskName | ||
Unregister-ScheduledTask -TaskName $taskName -Confirm:$false | ||
Write-Host "Task $taskName deleted." | ||
} | ||
} elseif ($args[0] -eq "start") { | ||
# first check if the task exists | ||
$task = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue | ||
if ($task -eq $null) { | ||
Write-Host "Task $taskName does not exist. Please enable it first." | ||
} else { | ||
Write-Host "Starting task $taskName..." | ||
Start-ScheduledTask -TaskName $taskName | ||
Write-Host "Task $taskName started." | ||
} | ||
} elseif ($args[0] -eq "stop") { | ||
# first check if the task exists | ||
$task = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue | ||
if ($task -eq $null) { | ||
Write-Host "Task $taskName does not exist. Please enable it first." | ||
} else { | ||
Write-Host "Stopping task $taskName..." | ||
Stop-ScheduledTask -TaskName $taskName | ||
Write-Host "Task $taskName stopped." | ||
} | ||
} elseif ($args[0] -eq "restart") { | ||
# first check if the task exists | ||
$task = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue | ||
if ($task -eq $null) { | ||
Write-Host "Task $taskName does not exist. Please enable it first." | ||
} else { | ||
Write-Host "Restarting task $taskName..." | ||
Restart-ScheduledTask -TaskName $taskName | ||
Write-Host "Task $taskName restarted." | ||
} | ||
} elseif ($args[0] -eq "status") { | ||
# first check if the task exists | ||
$task = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue | ||
if ($task -eq $null) { | ||
Write-Host "Task $taskName does not exist. Please enable it first." | ||
} else { | ||
$status = Get-ScheduledTask -TaskName $taskName | Select-Object State | ||
if ($status.State -eq "Running") { | ||
Write-Host "Task $taskName is running." | ||
} else { | ||
Write-Host "Task $taskName is not running." | ||
} | ||
} | ||
} else { | ||
Write-Host "Please specify 'enable' or 'disable'." | ||
} |
Oops, something went wrong.