{"id":13457940,"url":"https://github.com/xljiulang/ServiceSelf","last_synced_at":"2025-03-24T14:32:30.447Z","repository":{"id":152592136,"uuid":"626552526","full_name":"xljiulang/ServiceSelf","owner":"xljiulang","description":"为.NET 泛型主机的应用程序提供自安装为服务进程的能力","archived":false,"fork":false,"pushed_at":"2024-06-30T13:00:38.000Z","size":109,"stargazers_count":119,"open_issues_count":3,"forks_count":25,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-22T12:43:56.690Z","etag":null,"topics":["linux-service","service","service-control","systemd","systemd-service","windows-service"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xljiulang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-11T17:40:35.000Z","updated_at":"2025-02-12T01:52:21.000Z","dependencies_parsed_at":"2024-10-22T15:19:33.381Z","dependency_job_id":null,"html_url":"https://github.com/xljiulang/ServiceSelf","commit_stats":{"total_commits":65,"total_committers":1,"mean_commits":65.0,"dds":0.0,"last_synced_commit":"89439bf0bac2a309778f58afc02f4f86afff1868"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xljiulang%2FServiceSelf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xljiulang%2FServiceSelf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xljiulang%2FServiceSelf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xljiulang%2FServiceSelf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xljiulang","download_url":"https://codeload.github.com/xljiulang/ServiceSelf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245144966,"owners_count":20568056,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["linux-service","service","service-control","systemd","systemd-service","windows-service"],"created_at":"2024-07-31T09:00:40.220Z","updated_at":"2025-03-24T14:32:30.418Z","avatar_url":"https://github.com/xljiulang.png","language":"C#","funding_links":[],"categories":["C\\#"],"sub_categories":[],"readme":"# ServiceSelf\n为[.NET 泛型主机](https://learn.microsoft.com/zh-cn/dotnet/core/extensions/generic-host)的应用程序提供自安装为服务进程的能力，支持windows和linux平台。\n\n\u003e 功能\n\n* 自我服务安装\n* 自我服务卸载\n* 自我服务日志监听\n\n### 1 nuget\nhttps://www.nuget.org/packages/ServiceSelf/\n\n### 2 使用示例\n```csharp\nstatic void Main(string[] args)\n{\n    // 创建Host之前调用Service.UseServiceSelf(args)\n    if (Service.UseServiceSelf(args))\n    {\n        var builder = WebApplication.CreateBuilder(args);\n\n        // 为Host配置UseServiceSelf()\n        builder.Host.UseServiceSelf();\n\n        var app = builder.Build();\n        app.MapGet(\"/\", context =\u003e context.Response.WriteAsync(\"ServiceSelf\"));\n        app.Run();\n    }\n}\n```\n\n```csharp\nstatic void Main(string[] args)\n{\n    var serviceName = \"app\";\n    var serviceOptions = new ServiceOptions\n    {\n        Arguments = new[] { new Argument(\"key\", \"value\") },\n        Description = \"这是演示示例应用\",\n    };\n    serviceOptions.Linux.Service.Restart = \"always\";\n    serviceOptions.Linux.Service.RestartSec = \"10\";\n    serviceOptions.Windows.DisplayName = \"演示示例\";\n    serviceOptions.Windows.FailureActionType = WindowsServiceActionType.Restart;\n\n    if (Service.UseServiceSelf(args, serviceName, serviceOptions))\n    {\n        var host = Host.CreateDefaultBuilder(args)\n            // 为Host配置UseServiceSelf()\n            .UseServiceSelf()\n            .ConfigureServices(service =\u003e\n            {\n                service.AddHostedService\u003cAppHostedService\u003e();\n            })\n            .Build();\n\n        host.Run();\n    }\n}\n```\n\n### 3 服务控制\n当yourapp集成ServiceSelf之后，在管理员或root下使用如下命令控制yourapp服务\n\n\u003e windows平台\n\n```bat\nyourapp.exe start // 安装并启动服务\n```\n\n```bat\nyourapp.exe stop // 停止并删除服务\n```\n\n```bat\nyourapp.exe logs // 控制台输出服务的日志\nyourapp.exe logs filter=\"key words\" // 控制台输出服务的日志\n```\n\n\u003e linux平台\n\n```bash\nsudo ./yourapp start // 安装并启动服务\n```\n\n```bash\nsudo ./yourapp stop // 停止并删除服务\n```\n\n```bash\nsudo ./yourapp logs // 控制台输出服务的日志\nsudo ./yourapp logs filter=\"key words\" // 控制台输出服务的日志\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxljiulang%2FServiceSelf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxljiulang%2FServiceSelf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxljiulang%2FServiceSelf/lists"}