KillingSpark / rustysd

A service manager that is able to run "traditional" systemd services, written in rust
MIT License
495 stars 15 forks source link

".service" should be optional to start a service? #32

Closed pwFoo closed 4 years ago

pwFoo commented 4 years ago

I added a rust package manager to my fun linux os and have problems to reload (add) and start a new unitfile.

New unitfile is addes sucessful

Write cmd: {"jsonrpc":"2.0","method":"reload"}
[2020-03-08][20:33:32][rustysd::control::control][TRACE] Execute command: LoadAllNew
[2020-03-08][20:33:32][rustysd::units::loading][TRACE] ID 12: "./unitfiles/default.target"
[2020-03-08][20:33:32][rustysd::units::loading][TRACE] ID 13: "./unitfiles/docker.service"
[2020-03-08][20:33:32][rustysd::units::loading][TRACE] ID 14: "./unitfiles/init.target"
[2020-03-08][20:33:32][rustysd::units::loading][TRACE] ID 15: "./unitfiles/mdevd.service"
[2020-03-08][20:33:32][rustysd::units::loading][TRACE] ID 16: "./unitfiles/network.target"
[2020-03-08][20:33:32][rustysd::units::loading][TRACE] ID 17: "./unitfiles/onboot.target"
[2020-03-08][20:33:32][rustysd::units::loading][TRACE] ID 18: "./unitfiles/rngd.service"
[2020-03-08][20:33:32][rustysd::units::loading][TRACE] ID 19: "./unitfiles/services.target"
[2020-03-08][20:33:32][rustysd::units::loading][TRACE] ID 20: "./unitfiles/sshd.service"
[2020-03-08][20:33:32][rustysd::units::loading][TRACE] ID 21: "./unitfiles/udhcpc.service"
[2020-03-08][20:33:32][rustysd::units::dependency_resolving][TRACE] Id 12 references ids: [19]
[2020-03-08][20:33:32][rustysd::units::dependency_resolving][TRACE] Id 19 references ids: [12, 13, 15, 16, 18, 20, 21]
[2020-03-08][20:33:32][rustysd::units::dependency_resolving][TRACE] Id 13 references ids: [19]
Wait for response
[2020-03-08][20:33:32][rustysd::units::dependency_resolving][TRACE] Id 15 references ids: [19]
[2020-03-08][20:33:32][rustysd::units::dependency_resolving][TRACE] Id 16 references ids: [17, 19]
[2020-03-08][20:33:32][rustysd::units::dependency_resolving][TRACE] Id 17 references ids: [14, 16]
[2020-03-08][20:33:32][rustysd::units::dependency_resolving][TRACE] Id 14 references ids: [17]
[2020-03-08][20:33:32][rustysd::units::dependency_resolving][TRACE] Id 18 references ids: [19]
[2020-03-08][20:33:32][rustysd::units::dependency_resolving][TRACE] Id 20 references ids: [19]
[2020-03-08][20:33:32][rustysd::units::dependency_resolving][TRACE] Id 21 references ids: [19]
[2020-03-08][20:33:32][rustysd::units::loading][TRACE] Finished pruning units
[2020-03-08][20:33:32][rustysd::units::insert_new][TRACE] Check all names exist
[2020-03-08][20:33:32][rustysd::units::insert_new][TRACE] Add new unit: docker.service
Got response
{
  "jsonrpc": "2.0",
  "result": [
    {
      "Added": [
        "docker.service"
      ],
      "Ignored": [
        "sshd.service",
        "udhcpc.service",
        "rngd.service",
        "network.target",
        "onboot.target",
        "mdevd.service",
        "services.target",
        "default.target",
        "init.target"
      ]
    }
  ]
}

(Re-)start without .service fails

/ # rsdctl /notifications/control.socket restart docker
Write cmd: {"jsonrpc":"2.0","method":"restart","params":"docker"}
[2020-03-08][20:38:22][rustysd::control::control][TRACE] Execute command: Restart("docker")
[2020-03-08][20:38:22][rustysd::control::control][TRACE] Find unit for name: docker
Wait for response
Got response
{
  "error": {
    "code": -32000,
    "message": "No unit found with name: docker"
  },
  "jsonrpc": "2.0"
}

Works fine with ".service" added

/ # rsdctl /notifications/control.socket restart docker.service
Write cmd: {"jsonrpc":"2.0","method":"restart","params":"docker.service"}
[2020-03-08][20:36:30][rustysd::control::control][TRACE] Execute command: Restart("docker.service")
[2020-03-08][20:36:30][rustysd::control::control][TRACE] Find unit for name: docker.service
[2020-03-08][20:36:30][rustysd::units::activate][TRACE] Activate id: 13
[2020-03-08][20:36:30][rustysd::units::activate][TRACE] Lock unit: 13
[2020-03-08][20:36:30][rustysd::units::activate][TRACE] Locked unit: 13
[2020-03-08][20:36:30][rustysd::units::activate][TRACE] Lock status for: docker.service
[2020-03-08][20:36:30][rustysd::units::activate][TRACE] Locked status for: docker.service
[2020-03-08][20:36:30][rustysd::services::services][TRACE] Start service docker.service
[2020-03-08][20:36:30][rustysd::services::fork_parent][TRACE] [FORK_PARENT] Service: docker.service forked with pid: 1215
[2020-03-08][20:36:30][rustysd::services::fork_parent][TRACE] [FORK_PARENT] service docker.service doesnt notify
Wait for response
Got response
{
  "jsonrpc": "2.0",
  "result": []
}
KillingSpark commented 4 years ago

I don't really like this, because of the ambiguity it introduces. Socket units are named the same as their service units, so it's not clear which one the user wanted to start.

I would consider starting a unit if only one unit has that name as a prefix, and else return an error with the names of the matching units. Is that acceptable to you?

pwFoo commented 4 years ago

Would be ok. User needs maybe a hint why it fails / not found 👍

KillingSpark commented 4 years ago

With 5f96b0b599f67f0d1bc7621d8a2ee80925c3fb8a this should work. As long as there is only one unit matching the name you give to restart and friends it should work as expected.

Moreover, you only need to enter a identifying prefix of the name. Assume you have the services sshd and sssd, you can run rsdctl restart ssh and sshd.service will be selected :)

pwFoo commented 4 years ago

Works fine!