The Wayback Machine - https://web.archive.org/web/20211028083046/https://github.com/Homebrew/homebrew-core/issues/79367
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service: switch formula from def plist to service do blocks #79367

Open
137 of 182 tasks
SMillerDev opened this issue Jun 15, 2021 · 7 comments
Open
137 of 182 tasks

Service: switch formula from def plist to service do blocks #79367

SMillerDev opened this issue Jun 15, 2021 · 7 comments

Comments

@SMillerDev
Copy link
Member

@SMillerDev SMillerDev commented Jun 15, 2021

To allow Linux users to use brew services and to make formula less OS dependent we should migrate the formulae to use the OS agnostic service do block.


  • asimov
  • automysqlbackup
  • bitlbee
  • burp
  • carrot2
  • [email protected]
  • [email protected]
  • coredns
  • davmail
  • dbus
  • ddclient
  • ejabberd
  • elasticsearch
  • elasticsearch@6
  • h2
  • h2o
  • haproxy
  • hbase
  • heartbeat
  • i2pd
  • icecream
  • influxdb
  • influxdb@1
  • ipfs
  • ircd-hybrid
  • ircd-irc2
  • isc-dhcp
  • isync
  • jack
  • jenkins-lts
  • jenkins
  • jobber
  • kafka
  • kapacitor
  • kcptun
  • kettle
  • kibana
  • kibana@6
  • knot-resolver
  • knot
  • launch_socket_server
  • launchdns
  • libvirt
  • lighttpd
  • lldpd
  • logrotate
  • logstash
  • loki
  • mailhog
  • manticoresearch
  • mariadb
  • [email protected]
  • [email protected]
  • [email protected]
  • [email protected]
  • meilisearch
  • memcached
  • metabase
  • metricbeat
  • minidlna
  • minio
  • monero
  • mongo-orchestration
  • monit
  • mosquitto
  • moto
  • mpd
  • mpdas
  • mpdscribble
  • mysql
  • [email protected]
  • [email protected]
  • nagios
  • nats-server
  • nats-streaming-server
  • nebula
  • neo4j
  • netdata
  • nexus
  • nginx
  • node_exporter
  • nomad
  • nrpe
  • nsq
  • nut
  • nzbget
  • oauth2_proxy
  • offlineimap
  • opentsdb
  • openvpn
  • orientdb
  • packetbeat
  • payara
  • pdns
  • pdnsd
  • percona-server
  • perkeep
  • pgbouncer
  • [email protected]
  • [email protected]
  • [email protected]
  • piknik
  • pilosa
  • polipo
  • postgresql
  • postgresql@10
  • postgresql@11
  • postgresql@12
  • [email protected]
  • [email protected]
  • [email protected]
  • prestodb
  • prestosql
  • privoxy
  • proftpd
  • prometheus
  • pueue
  • pulseaudio
  • pure-ftpd
  • questdb
  • rabbitmq
  • [email protected]
  • [email protected]
  • redshift
  • rethinkdb
  • riemann
  • rsyslog
  • rtags
  • runit
  • scm-manager
  • sdns
  • selenium-server-standalone
  • ser2net
  • server-go
  • shadowsocks-libev
  • shairport-sync
  • shibboleth-sp
  • solr
  • [email protected]
  • sonarqube-lts
  • sonarqube
  • sonic
  • spoof-mac
  • spotifyd
  • squid
  • ssdb
  • sshguard
  • stubby
  • stunnel
  • supervisor
  • syncthing
  • telegraf
  • tile38
  • tinyproxy
  • tomcat
  • tomcat@7
  • tomcat@8
  • tomcat@9
  • tor
  • traefik
  • traefik@1
  • transmission-cli
  • twoping
  • udpxy
  • uftp
  • unbound
  • uptimed
  • uwsgi
  • v2ray
  • varnish
  • vault
  • vlmcsd
  • vnstat
  • vsftpd
  • webdis
  • wildfly-as
  • wownero
  • yubikey-agent
  • znapzend
  • znc
  • zookeeper
  • zrepl
@MikeMcQuaid
Copy link
Member

@MikeMcQuaid MikeMcQuaid commented Jun 15, 2021

@SMillerDev before we do this: do you have a replacement for the plist_options DSL? I think it should probably go away or get replaced with a more platform-agnostic version.

@SMillerDev
Copy link
Member Author

@SMillerDev SMillerDev commented Jun 15, 2021

I don't have one for :startup though it could probably just be a service function boot_service true or something.

The :manual option is auto-generated from the command in the service block.

@MikeMcQuaid
Copy link
Member

@MikeMcQuaid MikeMcQuaid commented Jun 15, 2021

I don't have one for :startup though it could probably just be a service function boot_service true or something.

Yeh, could be an argument to service do, I think. It kinda only applies on macOS because I think it's always gonna be a boot service on Linux, no? Could have a plist_type :system/:user or macos_startup :boot/:login or something else.

The :manual option is auto-generated from the command in the service block.

Gotcha. So it's essentially already also removable in favour of the service block?

@SMillerDev
Copy link
Member Author

@SMillerDev SMillerDev commented Jun 15, 2021

Yeh, could be an argument to service do, I think. It kinda only applies on macOS because I think it's always gonna be a boot service on Linux, no? Could have a plist_type :system/:user or macos_startup :boot/:login or something else.

Nope, for systemD it works the same as for launchd.

Gotcha. So it's essentially already also removable in favour of the service block?

Yeah, but I figured I'd combine the work.

@MikeMcQuaid
Copy link
Member

@MikeMcQuaid MikeMcQuaid commented Jun 15, 2021

Yeh, could be an argument to service do, I think. It kinda only applies on macOS because I think it's always gonna be a boot service on Linux, no? Could have a plist_type :system/:user or macos_startup :boot/:login or something else.

Nope, for systemD it works the same as for launchd.

Ah, cool. Yeh, a boot/login differentiation argument makes sense to me.

Yeah, but I figured I'd combine the work.

👍🏻

@github-actions
Copy link

@github-actions github-actions bot commented Jul 7, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@branchvincent
Copy link
Member

@branchvincent branchvincent commented Jul 29, 2021

in case it's helpful to others, I wrote a script to do most of the work here:

migrate_plist.py
import json
import plistlib
import re
import textwrap
from pathlib import Path

PLIST_RE = re.compile(r"def plist\s+<<\~EOS\s+(?P<plist>.*)\s+EOS\s+end", re.DOTALL)
PLIST_OPTIONS_RE = re.compile(r"plist_options .*")


def plist_to_service(plist: str) -> str:
    data = plistlib.loads(plist.encode())
    if "StartInterval" in data or "StartCalendarInterval" in data:
        print("ERROR: run_type not yet supported")
        exit(1)
    service = {
        "run": data.get("Program") or data.get("ProgramArguments"),
        "keep_alive": data.get("KeepAlive"),
        "working_dir": data.get("WorkingDirectory"),
        "root_dir": data.get("RootDirectory"),
        "input_path": data.get("StandardInPath"),
        "log_path": data.get("StandardOutputPath"),
        "error_log_path": data.get("StandardErrorPath"),
        "environment_variables": data.get("EnvironmentVariables"),
    }
    block = "service do\n"
    for k, v in service.items():
        if v is not None:
            block += f"  {k} {json.dumps(v)}\n"
    block += "end"
    return block


if __name__ == "__main__":
    from argparse import ArgumentParser

    parser = ArgumentParser(description="Migrate plist file to a service")
    parser.add_argument("file", type=Path, help="plist file to migrate")
    parser.add_argument(
        "-i", "--in-place", action="store_true", help="rewrite in-place"
    )

    args = parser.parse_args()
    contents = args.file.read_text()
    if not (match := PLIST_RE.search(contents)):
        print(f"ERROR: Failed to find a plist in {args.file}")
        exit(1)

    service = plist_to_service(match.group("plist"))
    if args.in_place:
        service = textwrap.indent(service, " " * 2).lstrip()
        contents = PLIST_RE.sub(service, contents, count=1)
        contents = PLIST_OPTIONS_RE.sub("", contents, count=1)
        args.file.write_text(contents)
    else:
        print(service)

to use it:

python3 migrate_plist.py --in-place Formula/example.rb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants