Skip to content

MihaelIsaev/SwiftSystemd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

MIT License Swift 5.8 Swift.Stream


Support this lib by giving a ⭐️

A simple plugin for any executable Swift package that provides the ability to manage it via systemd.

How to install

To install systemd as a SwiftPM plugin, first add the following line to your Package.swift file:

.package(url: "https://github.com/MihaelIsaev/SwiftSystemd.git", from:"1.0.0")

Usage

The purpose of systemd is to run your app as a daemon and monitor it.

The first step is to generate the appropriate config file and save it.

πŸ› οΈ Install

swift run systemd install

It will prompt you with a few questions to generate and save the correct config file.

Or you could use parameters to predefine values

Parameter Description
-c,--config Type of configuration: release or debug
-t,--target Executable target name
-u,--user User under which the service will run
swift run systemd install -c release -t App -u mike 

It generates the following config file

[Unit]
Description="AppName"
After=network.target

[Service]
User={user}
EnvironmentFile=/path/to/AppName/.env
WorkingDirectory=/path/to/AppName
TimeoutStopSec=2

Restart=always

ExecStart=/path/to/AppName/.build/{config}/{target}

[Install]
WantedBy=multi-user.target

πŸ’‘ Please feel free to contribute your own config variations

🧹 Uninstall

swift run systemd uninstall

Deletes the systemd configuration file and stops the service if it is active.

🍰 Start

swift run systemd start

Starts your app using systemctl start

πŸ”„ Restart

swift run systemd restart

Restarts your app using systemctl restart

πŸ›‘ Stop

swift run systemd stop

Stops your app if it is running via systemd, using systemctl stop.

🟒 Enable

swift run systemd enable

Enables the existing service configuration via systemctl enable.

πŸ”΄ Disable

swift run systemd disable

Disables the existing service configuration via systemctl disable.

πŸ”« Kill

swift run systemd kill

Sends kill signal to the running service via systemctl kill.

πŸ‘€ Status

swift run systemd status

Shows status of your app via systemctl status.

βš™οΈ Daemon Reload

swift run systemd daemon-reload

Reloads all systemd services via systemctl daemon-reload.

πŸ“‹ Logs

swift run systemd logs

Displays live logs of your app via journalctl.

swift run systemd logs --limit 100

Displays the last 100 lines from your app's log via journalctl

Contributing

Please feel free to contribute!

About

🍰 Let systemd run your app while you enjoy your cake!

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages