-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move service creation to Prefix::App
- Loading branch information
Showing
9 changed files
with
140 additions
and
135 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
module Service::InitSystem | ||
getter name : String, | ||
file : String, | ||
boot_file : String | ||
|
||
def type : String | ||
self.class.type | ||
end | ||
|
||
def boot? : Bool | ||
File.exists? @boot_file | ||
end | ||
|
||
def exists? : Bool | ||
File.symlink?(@file) || File.exists?(@file) | ||
end | ||
|
||
def writable? : Bool | ||
File.writable? @file | ||
end | ||
|
||
def boot(value : Bool) : Bool | ||
case value | ||
when boot? # nothing to do | ||
when true then File.symlink @file, @boot_file | ||
when false then File.delete boot_file | ||
end | ||
value | ||
end | ||
|
||
def real_file : String | ||
File.real_path file | ||
end | ||
|
||
private def delete_internal | ||
stop if run? | ||
boot false if boot? | ||
File.delete @file if exists? | ||
end | ||
|
||
def check_availability | ||
if exists? | ||
raise "system service already exist: " + name | ||
elsif !File.writable? File.dirname(@file) | ||
Log.warn "service creation unavailable, root permissions required", name | ||
else | ||
Log.info "service available for creation", name | ||
end | ||
end | ||
|
||
def check_delete | ||
if !writable? | ||
raise "root execution needed for system service deletion: " + name | ||
elsif !exists? | ||
raise "service doesn't exist: " + name | ||
end | ||
end | ||
end |
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 was deleted.
Oops, something went wrong.
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