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

Add illumos support #111

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
OS := $(shell uname -o)
ifeq ($(OS),illumos)
# for debug add -g -O0 to line below
CFLAGS+=-pthread -O2 -Wall -Wextra -Wpedantic -Wstrict-overflow -fno-strict-aliasing -std=gnu11 -g -O0
prefix=/usr/local/bin
CFLAGS+=-pthread -O2 -Wall -Wextra -Wpedantic -Wstrict-overflow -fno-strict-aliasing -std=gnu11 -lsocket -lnsl
prefix=/opt/local/bin

all:
${CC} main.c fiche.c $(CFLAGS) -o fiche

install: fiche
install -m 0755 fiche $(prefix)
svccfg import fiche.xml
else
# for debug add -g -O0 to line below
CFLAGS+=-pthread -O2 -Wall -Wextra -Wpedantic -Wstrict-overflow -fno-strict-aliasing -std=gnu11 -g -O0
prefix=/usr/local/bin

all:
${CC} main.c fiche.c $(CFLAGS) -o fiche

install: fiche
install -m 0755 fiche $(prefix)
endif

clean:
rm -f fiche
Expand Down
99 changes: 97 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ To use fiche you have to have netcat installed. You probably already have it - t

# Server-side usage

## Installation

## Installation

__Linux__

1. Clone:

```
Expand All @@ -130,7 +132,30 @@ To use fiche you have to have netcat installed. You probably already have it - t
```
sudo make install
```

__illumos__

The install target also imports the smf manifest, so it must be configured before running the install target.

1. Clone:

```
git clone https://github.com/solusipse/fiche.git
```

2. Build:

```
make
```

3. Install:

```
pfexec make install
```

__FreeBSD__
### Using Ports on FreeBSD

To install the port: `cd /usr/ports/net/fiche/ && make install clean`. To add the package: `pkg install fiche`.
Expand Down Expand Up @@ -296,6 +321,8 @@ __WARNING:__ not implemented yet

### Running as a service

__Linux__

There's a simple systemd example:
```
[Unit]
Expand All @@ -310,6 +337,74 @@ WantedBy=multi-user.target

__WARNING:__ In service mode you have to set output directory with `-o` parameter.

__illumos__

To run fiche as a service an example [smf](https://wiki.smartos.org/basic-smf-commands/) manifest is provided (fiche.xml).
This manifest assumes that the user fiche exists and has a home directory to use
as a output directory (`-o` parameter).
Also exec_method must be changed to match the required flags for your use case.

```xml
<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<!--
Created by Manifold
--><service_bundle type="manifest" name="fiche">

<service name="network/fiche" type="service" version="1">

<create_default_instance enabled="false"/>

<single_instance/>

<dependency name="network" grouping="require_all" restart_on="error" type="service">
<service_fmri value="svc:/milestone/network:default"/>
</dependency>

<dependency name="filesystem" grouping="require_all" restart_on="error" type="service">
<service_fmri value="svc:/system/filesystem/local"/>
</dependency>


<method_context>
<method_credential user="fiche" />
</method_context>

<exec_method type="method" name="start" exec="/opt/local/bin/fiche -S -o /home/fiche/code -d example.com -l /var/log/fiche.log -s 6 " timeout_seconds="60"/>

<exec_method type="method" name="stop" exec=":kill" timeout_seconds="60"/>

<property_group name="startd" type="framework">
<propval name="duration" type="astring" value="child"/>


<propval name="ignore_error" type="astring" value="core,signal"/>
</property_group>

<property_group name="application" type="application">

</property_group>


<stability value="Evolving"/>

<template>
<common_name>
<loctext xml:lang="C">
fiche
</loctext>
</common_name>
</template>

</service>

</service_bundle>
```

Relevant information for smf is available on the following links:
- https://www.joyent.com/blog/documentation-for-smf
- https://docs.joyent.com/public-cloud/instances/infrastructure/images/smartos/managing-smartos/using-smf

-------------------------------------------------------------------------------

### Example nginx config
Expand Down
39 changes: 36 additions & 3 deletions fiche.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,11 @@ static void log_entry(const Fiche_Settings *s, const char *ip,
* @brief Returns string containing current date
* @warning Output has to be freed!
*/
#ifdef __sun
static void get_date(char *buf, size_t len);
#else
static void get_date(char *buf);

#endif

/**
* @brief Time seed
Expand Down Expand Up @@ -228,7 +231,11 @@ int fiche_run(Fiche_Settings settings) {
// Display welcome message
{
char date[64];
#ifdef __sun
get_date(date, sizeof(date));
#else
get_date(date);
#endif
print_status("Starting fiche on %s...", date);
}

Expand Down Expand Up @@ -334,14 +341,37 @@ static void log_entry(const Fiche_Settings *s, const char *ip,
}

char date[64];
#ifdef __sun
get_date(date, sizeof(date));
#else
get_date(date);
#endif

// Write entry to file
fprintf(f, "%s -- %s -- %s (%s)\n", slug, date, ip, hostname);
fclose(f);
}

#ifdef __sun
static void get_date(char *buf, size_t len) {
struct tm curtime;
time_t ltime;

ltime=time(&ltime);
localtime_r(&ltime, &curtime);

// Save data to provided buffer
if (asctime_r(&curtime, buf,strnlen(buf,len) == 0)) {
// Couldn't get date, setting first byte of the
// buffer to zero so it won't be displayed
buf[0] = 0;
return;
}

// Remove newline char
buf[strlen(buf)-1] = 0;
}
#else
static void get_date(char *buf) {
struct tm curtime;
time_t ltime;
Expand All @@ -360,8 +390,7 @@ static void get_date(char *buf) {
// Remove newline char
buf[strlen(buf)-1] = 0;
}


#endif
static int set_domain_name(Fiche_Settings *settings) {

char *prefix = "";
Expand Down Expand Up @@ -554,7 +583,11 @@ static void *handle_connection(void *args) {
// Print status on this connection
{
char date[64];
#ifdef __sun
get_date(date, sizeof(date));
#else
get_date(date);
#endif
print_status("%s", date);

print_status("Incoming connection from: %s (%s).", ip, hostname);
Expand Down
54 changes: 54 additions & 0 deletions fiche.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<!--
Created by Manifold
--><service_bundle type="manifest" name="fiche">

<service name="network/fiche" type="service" version="1">

<create_default_instance enabled="false"/>

<single_instance/>

<dependency name="network" grouping="require_all" restart_on="error" type="service">
<service_fmri value="svc:/milestone/network:default"/>
</dependency>

<dependency name="filesystem" grouping="require_all" restart_on="error" type="service">
<service_fmri value="svc:/system/filesystem/local"/>
</dependency>


<method_context>
<method_credential user="fiche" />
</method_context>

<exec_method type="method" name="start" exec="/opt/local/bin/fiche -S -o /home/fiche/code -d example.com -l /var/log/fiche.log -s 6 " timeout_seconds="60"/>

<exec_method type="method" name="stop" exec=":kill" timeout_seconds="60"/>

<property_group name="startd" type="framework">
<propval name="duration" type="astring" value="child"/>


<propval name="ignore_error" type="astring" value="core,signal"/>
</property_group>

<property_group name="application" type="application">

</property_group>


<stability value="Evolving"/>

<template>
<common_name>
<loctext xml:lang="C">
fiche
</loctext>
</common_name>
</template>

</service>

</service_bundle>